Skip to content

Commit e941ca5

Browse files
authored
Merge branch 'master' into master
2 parents 319de62 + 9dfde46 commit e941ca5

16 files changed

+77
-19
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ python:
44
- "2.7"
55
- "3.4"
66
- "3.5"
7+
- "3.6"
78
- "pypy"
89

910
script:

CHANGES.rst

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ Changelog
33

44
Here you can see the full list of changes between each Flask-OAuthlib release.
55

6+
Version 0.9.5
7+
-------------
8+
9+
Released on May 16, 2018
10+
11+
- Fix error handlers
12+
- Update supported OAuthlib
13+
- Add support for string type token
14+
615
Version 0.9.4
716
-------------
817

README.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ Flask-OAuthlib
1717
:target: https://coveralls.io/r/lepture/flask-oauthlib
1818
:alt: Coverage Status
1919

20-
Notification
21-
------------
20+
Notice
21+
------
2222

23-
I'm working on https://github.com/lepture/authlib which will
24-
be the replacement of this project.
23+
**If you are a company, you should use https://github.com/lepture/authlib instead**.
2524

2625
=====
2726

docs/_templates/sidebarintro.html

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<h3>Notice</h3>
2+
<p>Flask-OAuthlib is not maintained well. Please use <strong><a href="https://authlib.org/">Authlib</a></strong> instead.</p>
3+
14
<h3>Feedback</h3>
25
<p>Feedback is greatly appreciated. If you have any questions, comments, random praise, or anymous threats, <a href="mailto:[email protected]">shoot me an email</a>.</p>
36

docs/client.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Client
22
======
33

4+
.. note::
5+
6+
Please read https://docs.authlib.org/en/latest/client/frameworks.html
7+
48
The client part keeps the same API as `Flask-OAuth`_. The only changes are
59
the imports::
610

docs/index.rst

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ oauthlib_.
1414
The client part of Flask-OAuthlib shares the same API as Flask-OAuth,
1515
which is pretty and simple.
1616

17+
.. warning::
18+
19+
Please use https://github.com/lepture/authlib instead.
20+
1721

1822
Features
1923
--------

docs/oauth1.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
OAuth1 Server
22
=============
33

4+
.. note::
5+
6+
Please read https://docs.authlib.org/en/latest/flask/oauth1.html
7+
48
This part of documentation covers the tutorial of setting up an OAuth1
59
provider. An OAuth1 server concerns how to grant the authorization and
610
how to protect the resource. Register an **OAuth** provider::

docs/oauth2.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
OAuth2 Server
44
=============
55

6+
.. note::
7+
8+
Please read https://docs.authlib.org/en/latest/flask/oauth2.html
9+
610
An OAuth2 server concerns how to grant the authorization and how to protect
711
the resource. Register an **OAuth** provider::
812

@@ -495,5 +499,5 @@ Example for OAuth 2
495499
An example server (and client) can be found in the tests folder: https://github.com/lepture/flask-oauthlib/tree/master/tests/oauth2
496500

497501
Other helpful resources include:
498-
- Another example of an OAuth 2 server: https://github.com/lepture/example-oauth2-server
502+
- Another example of an OAuth 2 server: https://github.com/authlib/example-oauth2-server
499503
- An article on how to create an OAuth server: http://lepture.com/en/2013/create-oauth-server.

flask_oauthlib/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
remote OAuth enabled applications, and also helps you creating your own
88
OAuth servers.
99
10-
:copyright: (c) 2013 - 2017 by Hsiaoming Yang.
10+
:copyright: (c) 2013 by Hsiaoming Yang.
1111
:license: BSD, see LICENSE for more details.
1212
"""
1313

14-
__version__ = "0.9.4"
14+
__version__ = "0.9.5"
1515
__author__ = "Hsiaoming Yang <[email protected]>"
1616
__homepage__ = 'https://github.com/lepture/flask-oauthlib'
1717
__license__ = 'BSD'

flask_oauthlib/provider/oauth2.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ def user():
6969
return jsonify(request.oauth.user)
7070
"""
7171

72-
def __init__(self, app=None):
72+
def __init__(self, app=None, validator_class=None):
7373
self._before_request_funcs = []
7474
self._after_request_funcs = []
7575
self._exception_handler = None
7676
self._invalid_response = None
77+
self._validator_class = validator_class
7778
if app:
7879
self.init_app(app)
7980

@@ -163,7 +164,10 @@ def validate_client_id(self, client_id):
163164
if hasattr(self, '_usergetter'):
164165
usergetter = self._usergetter
165166

166-
validator = OAuth2RequestValidator(
167+
validator_class = self._validator_class
168+
if validator_class is None:
169+
validator_class = OAuth2RequestValidator
170+
validator = validator_class(
167171
clientgetter=self._clientgetter,
168172
tokengetter=self._tokengetter,
169173
grantgetter=self._grantgetter,
@@ -430,7 +434,12 @@ def decorated(*args, **kwargs):
430434
return self._on_exception(e, e.in_uri(self.error_uri))
431435
except oauth2.OAuth2Error as e:
432436
log.debug('OAuth2Error: %r', e, exc_info=True)
437+
# on auth error, we should preserve state if it's present according to RFC 6749
438+
state = request.values.get('state')
439+
if state and not e.state:
440+
e.state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri
433441
return self._on_exception(e, e.in_uri(redirect_uri))
442+
434443
except Exception as e:
435444
log.exception(e)
436445
return self._on_exception(e, add_params_to_uri(
@@ -449,6 +458,10 @@ def decorated(*args, **kwargs):
449458
return self._on_exception(e, e.in_uri(self.error_uri))
450459
except oauth2.OAuth2Error as e:
451460
log.debug('OAuth2Error: %r', e, exc_info=True)
461+
# on auth error, we should preserve state if it's present according to RFC 6749
462+
state = request.values.get('state')
463+
if state and not e.state:
464+
e.state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri
452465
return self._on_exception(e, e.in_uri(redirect_uri))
453466

454467
if not isinstance(rv, bool):
@@ -457,8 +470,9 @@ def decorated(*args, **kwargs):
457470

458471
if not rv:
459472
# denied by user
460-
e = oauth2.AccessDeniedError()
473+
e = oauth2.AccessDeniedError(state=request.values.get('state'))
461474
return self._on_exception(e, e.in_uri(redirect_uri))
475+
462476
return self.confirm_authorization_request()
463477
return decorated
464478

@@ -488,6 +502,11 @@ def confirm_authorization_request(self):
488502
return self._on_exception(e, e.in_uri(self.error_uri))
489503
except oauth2.OAuth2Error as e:
490504
log.debug('OAuth2Error: %r', e, exc_info=True)
505+
506+
# on auth error, we should preserve state if it's present according to RFC 6749
507+
state = request.values.get('state')
508+
if state and not e.state:
509+
e.state = state # set e.state so e.in_uri() can add the state query parameter to redirect uri
491510
return self._on_exception(e, e.in_uri(redirect_uri or self.error_uri))
492511
except Exception as e:
493512
log.exception(e)

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Flask==0.11.1
1+
Flask==0.12.2
22
mock==2.0.0
3-
oauthlib==1.1.2
4-
requests-oauthlib==0.6.2
3+
oauthlib==2.0.6
4+
requests-oauthlib==0.8.0
55
Flask-SQLAlchemy==2.1

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def fread(filename):
4343
license='BSD',
4444
install_requires=[
4545
'Flask',
46-
'oauthlib>=1.1.2',
46+
'oauthlib>=1.1.2,!=2.0.3,!=2.0.4,!=2.0.5,<3.0.0',
4747
'requests-oauthlib>=0.6.2',
4848
],
4949
tests_require=['nose', 'Flask-SQLAlchemy', 'mock'],

tests/_base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def setUp(self):
3232
'OAUTH1_PROVIDER_ENFORCE_SSL': False,
3333
'OAUTH1_PROVIDER_KEY_LENGTH': (3, 30),
3434
'OAUTH1_PROVIDER_REALMS': ['email', 'address'],
35-
'SQLALCHEMY_DATABASE_URI': 'sqlite:///%s' % self.db_file
35+
'SQLALCHEMY_DATABASE_URI': 'sqlite:///%s' % self.db_file,
36+
'SQLALCHEMY_TRACK_MODIFICATIONS': False
3637
}
3738
app.config.update(config)
3839

tests/oauth2/test_oauth2.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,21 @@ def test_oauth_authorize_valid_url(self):
8181
assert 'code=' in rv.location
8282
assert 'state' not in rv.location
8383

84-
# test state
84+
# test state on access denied
85+
# According to RFC 6749, state should be preserved on error response if it's present in the client request.
86+
# Reference: https://tools.ietf.org/html/rfc6749#section-4.1.2
87+
rv = self.client.post(authorize_url + '&state=foo', data=dict(
88+
confirm='no'
89+
))
90+
assert 'error=access_denied' in rv.location
91+
assert 'state=foo' in rv.location
92+
93+
# test state on success
8594
rv = self.client.post(authorize_url + '&state=foo', data=dict(
8695
confirm='yes'
8796
))
8897
assert 'code=' in rv.location
89-
assert 'state' in rv.location
98+
assert 'state=foo' in rv.location
9099

91100
def test_http_head_oauth_authorize_valid_url(self):
92101
rv = self.client.head(authorize_url)

tests/test_oauth2/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def create_app(self):
313313
app.debug = True
314314
app.secret_key = 'testing'
315315
app.config.update({
316-
'SQLALCHEMY_DATABASE_URI': 'sqlite://'
316+
'SQLALCHEMY_DATABASE_URI': 'sqlite://',
317+
'SQLALCHEMY_TRACK_MODIFICATIONS': False
317318
})
318319
return app

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27,py33,py34,py35,pypy
2+
envlist = py27,py33,py34,py35,py36,pypy
33

44
[testenv]
55
deps =

0 commit comments

Comments
 (0)