GithubHelp home page GithubHelp logo

flask-rauth's Introduction

Flask-Rauth

Adds OAuth 1.0/a, 2.0, and Ofly consumer support for Flask, using the rauth library.

Flask-Rauth is a fork of Armin Ronacher's Flask-OAuth.

Documentation

Current documentation is available at the following URL:

http://flask-rauth.readthedocs.org/en/latest/

Documentation hosting is provided by Read the Docs.

Examples

Some people learn better by example, that's why I've provided the following examples for your edification:

https://github.com/joelverhagen/flask-rauth/tree/master/example

flask-rauth's People

Contributors

dag avatar gmodena avatar joelverhagen avatar jqxl0205 avatar lolsborn avatar mattupstate avatar mitsuhiko avatar passy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flask-rauth's Issues

Getting key and secret from app.config doesn't work because self.app isn't set yet

When using the current PyPI release of flask-rauth, I get the following exception:

14:07:15 web.1  | Traceback (most recent call last):
14:07:15 web.1  |   File "app.py", line 1, in <module>
14:07:15 web.1  |     from qwake import run
14:07:15 web.1  |   File "/Users/lvh/Code/qwake/qwake/__init__.py", line 57, in <module>
14:07:15 web.1  |     access_token_url='https://connect.stripe.com/oauth/token',
14:07:15 web.1  |   File "/Users/lvh/Code/qwake/venv/lib/python2.7/site-packages/flask_rauth.py", line 266, in __init__
14:07:15 web.1  |     OAuth2Service.__init__(self, consumer_key=consumer_key, consumer_secret=consumer_secret, **kwargs)
14:07:15 web.1  |   File "/Users/lvh/Code/qwake/venv/lib/python2.7/site-packages/rauth/service.py", line 318, in __init__
14:07:15 web.1  |     if None in (self.consumer_key, self.consumer_secret):
14:07:15 web.1  |   File "/Users/lvh/Code/qwake/venv/lib/python2.7/site-packages/flask_rauth.py", line 210, in consumer_key
14:07:15 web.1  |     elif self.app is not None and self._consumer_key_config() in self.app.config:
14:07:15 web.1  | AttributeError: 'RauthOAuth2' object has no attribute 'app'
14:07:15 web.1  | exited with code 1

The required keys are in app.config, but this is never read, because self.app is set in RauthServiceMixin.__init__:

https://github.com/joelverhagen/flask-rauth/blob/master/flask_rauth.py#L155

Which is called after OAuth2Service.__init__:

https://github.com/joelverhagen/flask-rauth/blob/master/flask_rauth.py#L270

So I get the exception raised here:

https://github.com/joelverhagen/flask-rauth/blob/master/flask_rauth.py#L213

....

I worked around this issue by specifying these values when creating the object instead of putting them in the config, but the documentation suggests that isn't recommended. Anyway, I think the current_app using line isn't actually ever used, since the only case where it'd be used is when self.app isn't set yet...

rauth.service.Response ImportError due to rauth api change

Installed flask-rauth with pip. Seems to have installed:
Flask_Rauth-0.3.2-py2.7.egg
rauth-0.5.1-py2.7.egg

However the rauth api changed as of litl/rauth@bad9531 so that Response has been removed from service.py

File "/sw/myprog/prog.py", line 4, in
from flask_rauth import RauthOAuth2
File "/sw/myprog/env/local/lib/python2.7/site-packages/flask_rauth.py", line 17, in
from rauth.service import OAuth2Service, OAuth1Service, OflyService, Response, parse_utf8_qsl
ImportError: cannot import name Response

RuntimeError/AttributeError configuring OAuth2 service from current app

When I run this script:

#!/usr/bin/env python

from flask import Flask
from flask.ext.rauth import RauthOAuth2

app = Flask(__name__)
app.config.update(GITHUB_CONSUMER_KEY='foo', GITHUB_CONSUMER_SECRET='bar')

github = RauthOAuth2(
    name='github',
    base_url='https://api.github.com/',
    authorize_url='https://github.com/login/oauth/authorize',
    access_token_url='https://github.com/login/oauth/access_token',
)

if __name__ == '__main__':
    app.run()

I get this error:

Traceback (most recent call last):
  File "rautherr.py", line 13, in <module>
    access_token_url='https://github.com/login/oauth/access_token',
  File ".env/lib/python2.7/site-packages/flask_rauth.py", line 267, in __init__
    OAuth2Service.__init__(self, consumer_key=consumer_key, consumer_secret=consumer_secret, **kwargs)
  File ".env/lib/python2.7/site-packages/rauth/service.py", line 318, in __init__
    if None in (self.consumer_key, self.consumer_secret):
  File ".env/lib/python2.7/site-packages/flask_rauth.py", line 215, in consumer_key
    return current_app.config.get(self._consumer_key_config(), None)
  File ".env/lib/python2.7/site-packages/werkzeug/local.py", line 336, in __getattr__
    return getattr(self._get_current_object(), name)
  File ".env/lib/python2.7/site-packages/werkzeug/local.py", line 295, in _get_current_object
    return self.__local()
  File ".env/lib/python2.7/site-packages/flask/globals.py", line 26, in _find_app
    raise RuntimeError('working outside of application context')
RuntimeError: working outside of application context

I expected it to at least instantiate so I could call github.init_app(app) after that, as in the Twitter example. I tried to fix it by wrapping the instantiation in a with app.app_context():, but that only changes the error to:

Traceback (most recent call last):
  File "rautherr.py", line 14, in <module>
    access_token_url='https://github.com/login/oauth/access_token',
  File ".env/lib/python2.7/site-packages/flask_rauth.py", line 267, in __init__
    OAuth2Service.__init__(self, consumer_key=consumer_key, consumer_secret=consumer_secret, **kwargs)
  File ".env/lib/python2.7/site-packages/rauth/service.py", line 318, in __init__
    if None in (self.consumer_key, self.consumer_secret):
  File ".env/lib/python2.7/site-packages/flask_rauth.py", line 215, in consumer_key
    return current_app.config.get(self._consumer_key_config(), None)
  File ".env/lib/python2.7/site-packages/flask_rauth.py", line 242, in _consumer_key_config
    return '%s_CONSUMER_KEY' % (self.name.upper(),)
AttributeError: 'RauthOAuth2' object has no attribute 'name'

As with issue #1, this seems related to the order in which the objects are configured in rauth 0.4.17. When initializing the RauthOAuth2 instance, OAuth2Service.__init__() inadvertently calls back into the RauthServiceMixin.consumer_key property. With no explicitly set app, it assumes it can look up the flask.current_app and causes the RuntimeError.

In the latter case, even if the app is set, the consumer_key access happens before OAuth2Service.__init__() calls the superimplementation to set the name attribute, and RauthServiceMixin._consumer_key_config() raises the AttributeError.

Downgrading to rauth 0.4.16 causes the error not to occur. I only see it with rauth 0.4.17 and Flask-Rauth 0.3.2. As rauth 0.4.17's change is related to using client_id instead of consumer_key etc, this also seems to affect only OAuth2 services (specifically, flask-rauth's Twitter example still works).

_cached_content is being overwritten as a function

access_token = resp.content.get('access_token')

AttributeError: 'function' object has no attribute 'get'

Commented out the content() override in RauthResponse and everything works. I am using python 2.7 and OAuth2. Took me a while to wire up pycharm and confirm. Just as I step into the if, it changes from a member variable to an instance function...not sure why though.

For now I will forgoe the caching...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.