Skip to content
This repository was archived by the owner on Jun 29, 2019. It is now read-only.

Commit 06d15bc

Browse files
committed
Updated docs and examples
1 parent 6cddb2c commit 06d15bc

File tree

16 files changed

+86
-86
lines changed

16 files changed

+86
-86
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
## 0.5.0 (unreleased)
1+
## 0.5.0
22

33
Features:
44

55
- Added Client Credentials Grant
6+
- Renamed `oauth2.AuthorizationController` to `oauth2.Provider`
7+
- Added mongodb store
68

79
## 0.4.0
810

README.rst

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
python-oauth2
2-
###############
2+
#############
33

44
python-oauth2 is a framework that aims at making it easy to provide authentication
55
via `OAuth 2.0 <http://tools.ietf.org/html/rfc6749>`_ within an application stack.
@@ -12,11 +12,7 @@ Status
1212
.. image:: https://travis-ci.org/wndhydrnt/python-oauth2.png?branch=master
1313
:target: https://travis-ci.org/wndhydrnt/python-oauth2
1414

15-
python-oauth2 is currently not ready for use in production environments.
16-
While the basic implementations work already pretty well, some types of
17-
authorization Grants
18-
`defined in the RFC <http://tools.ietf.org/html/rfc6749#section-1.3>`_ are
19-
still missing.
15+
python-oauth2 has reached its beta phase. All main parts of the `OAuth 2.0 RFC <http://tools.ietf.org/html/rfc6749>`_ such as the various types of Grants, Refresh Token and Scopes have been implemented. However, bugs might occur or implementation details might be wrong.
2016

2117
Installation
2218
************
@@ -30,12 +26,11 @@ Usage
3026
*****
3127

3228
Example Authorization server::
33-
3429
from wsgiref.simple_server import make_server
3530
import oauth2
3631
import oauth2.grant
3732
import oauth2.error
38-
import oauth2.store
33+
import oauth2.store.memory
3934
import oauth2.tokengenerator
4035
import oauth2.web
4136

@@ -61,17 +56,17 @@ Example Authorization server::
6156
return response
6257

6358
# Create an in-memory storage to store your client apps.
64-
client_store = oauth2.store.LocalClientStore()
59+
client_store = oauth2.store.memory.ClientStore()
6560
# Add a client
6661
client_store.add_client(client_id="abc", client_secret="xyz",
6762
redirect_uris=["http://localhost/callback"])
6863

6964
# Create an in-memory storage to store issued tokens.
7065
# LocalTokenStore can store access and auth tokens
71-
token_store = oauth2.store.LocalTokenStore()
66+
token_store = oauth2.store.memory.TokenStore()
7267

7368
# Create the controller.
74-
auth_controller = oauth2.AuthorizationController(
69+
auth_controller = oauth2.Provider(
7570
access_token_store=token_store,
7671
auth_code_store=token_store,
7772
client_store=client_store,
@@ -82,7 +77,7 @@ Example Authorization server::
8277
# Add Grants you want to support
8378
auth_controller.add_grant(oauth2.grant.AuthorizationCodeGrant())
8479
auth_controller.add_grant(oauth2.grant.ImplicitGrant())
85-
80+
8681
# Add refresh token capability and set expiration time of access tokens
8782
# to 30 days
8883
auth_controller.add_grant(oauth2.grant.RefreshToken(expires_in=2592000))

docs/oauth2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
``oauth2`` --- Controller classes
2-
========================================
1+
``oauth2`` --- Provider class
2+
=============================
33

44
.. autoclass:: oauth2.Provider
55

docs/store/memcache.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
.. automodule:: oauth2.store.memcache
55

6-
.. autoclass:: MemcacheTokenStore
6+
.. autoclass:: TokenStore

docs/store/memory.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
.. automodule:: oauth2.store.memory
55

6-
.. autoclass:: MemoryClientStore
6+
.. autoclass:: ClientStore
77
:members:
88

9-
.. autoclass:: MemoryTokenStore
9+
.. autoclass:: TokenStore
1010
:members:

docs/store/mongodb.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
.. autoclass:: MongodbStore
77

8-
.. autoclass:: MongodbAccessTokenStore
8+
.. autoclass:: AccessTokenStore
99

10-
.. autoclass:: MongodbAuthCodeStore
10+
.. autoclass:: AuthCodeStore
1111

12-
.. autoclass:: MongodbClientStore
12+
.. autoclass:: ClientStore

examples/authorization_code_grant.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
sys.path.insert(0, os.path.abspath(os.path.realpath(__file__) + '/../../'))
1212

13-
from oauth2 import AuthorizationController
14-
from oauth2.store import LocalClientStore, LocalTokenStore
13+
from oauth2 import Provider
14+
from oauth2.error import UserNotAuthenticated
15+
from oauth2.store.memory import ClientStore, TokenStore
1516
from oauth2.tokengenerator import Uuid4
1617
from oauth2.web import SiteAdapter, Wsgi
1718
from oauth2.grant import AuthorizationCodeGrant
@@ -64,11 +65,11 @@ def render_auth_page(self, request, response, environ, scopes):
6465

6566
return response
6667

67-
def authenticate(self, request, environ):
68+
def authenticate(self, request, environ, scopes):
6869
if request.method == "POST":
6970
if request.post_param("confirm") is "1":
70-
return True
71-
return None
71+
return
72+
raise UserNotAuthenticated
7273

7374
def user_has_denied_access(self, request):
7475
if request.method == "POST":
@@ -174,15 +175,15 @@ def run_app_server():
174175

175176
def run_auth_server():
176177
try:
177-
client_store = LocalClientStore()
178+
client_store = ClientStore()
178179
client_store.add_client(client_id="abc", client_secret="xyz",
179180
redirect_uris=["http://localhost:8081/callback"])
180181

181-
token_store = LocalTokenStore()
182+
token_store = TokenStore()
182183

183-
auth_controller = AuthorizationController(
184+
auth_controller = Provider(
184185
access_token_store=token_store,
185-
auth_token_store=token_store,
186+
auth_code_store=token_store,
186187
client_store=client_store,
187188
site_adapter=TestSiteAdapter(),
188189
token_generator=Uuid4())

examples/implicit_grant.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
sys.path.insert(0, os.path.abspath(os.path.realpath(__file__) + '/../../'))
99

10-
from oauth2 import AuthorizationController
10+
from oauth2 import Provider
11+
from oauth2.error import UserNotAuthenticated
1112
from oauth2.web import Wsgi, SiteAdapter
1213
from oauth2.tokengenerator import Uuid4
1314
from oauth2.grant import ImplicitGrant
14-
from oauth2.store import LocalClientStore, LocalTokenStore
15+
from oauth2.store.memory import ClientStore, TokenStore
1516

1617
class TestSiteAdapter(SiteAdapter):
1718
CONFIRMATION_TEMPLATE = """
@@ -39,11 +40,11 @@ def render_auth_page(self, request, response, environ, scopes):
3940

4041
return response
4142

42-
def authenticate(self, request, environ):
43+
def authenticate(self, request, environ, scopes):
4344
if request.method == "POST":
4445
if request.post_param("confirm") is "1":
45-
return True
46-
return False
46+
return
47+
raise UserNotAuthenticated
4748

4849
def user_has_denied_access(self, request):
4950
if request.method == "POST":
@@ -110,15 +111,15 @@ def application(env, start_response):
110111

111112
def run_auth_server():
112113
try:
113-
client_store = LocalClientStore()
114+
client_store = ClientStore()
114115
client_store.add_client(client_id="abc", client_secret="xyz",
115116
redirect_uris=["http://localhost:8081/"])
116117

117-
token_store = LocalTokenStore()
118+
token_store = TokenStore()
118119

119-
auth_server = AuthorizationController(
120+
auth_server = Provider(
120121
access_token_store=token_store,
121-
auth_token_store=token_store,
122+
auth_code_store=token_store,
122123
client_store=client_store,
123124
site_adapter=TestSiteAdapter(),
124125
token_generator=Uuid4())

oauth2/__init__.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
Usage
1111
=====
1212
13-
Example Authorization server::
13+
Example::
1414
1515
from wsgiref.simple_server import make_server
1616
import oauth2
1717
import oauth2.grant
1818
import oauth2.error
19-
import oauth2.store
19+
import oauth2.store.memory
2020
import oauth2.tokengenerator
2121
import oauth2.web
22-
22+
2323
# Create a SiteAdapter to interact with the user.
2424
# This can be used to display confirmation dialogs and the like.
2525
class ExampleSiteAdapter(oauth2.web.SiteAdapter):
2626
def authenticate(self, request, environ, scopes):
2727
if request.post_param("confirm") == "1":
2828
return {}
29-
29+
3030
raise oauth2.error.UserNotAuthenticated
31-
31+
3232
def render_auth_page(self, request, response, environ, scopes):
3333
response.body = '''
3434
<html>
@@ -40,17 +40,17 @@ def render_auth_page(self, request, response, environ, scopes):
4040
</body>
4141
</html>'''
4242
return response
43-
43+
4444
# Create an in-memory storage to store your client apps.
45-
client_store = oauth2.store.LocalClientStore()
45+
client_store = oauth2.store.memory.ClientStore()
4646
# Add a client
4747
client_store.add_client(client_id="abc", client_secret="xyz",
4848
redirect_uris=["http://localhost/callback"])
49-
49+
5050
# Create an in-memory storage to store issued tokens.
5151
# LocalTokenStore can store access and auth tokens
52-
token_store = oauth2.store.LocalTokenStore()
53-
52+
token_store = oauth2.store.memory.TokenStore()
53+
5454
# Create the controller.
5555
auth_controller = oauth2.Provider(
5656
access_token_store=token_store,
@@ -59,18 +59,18 @@ def render_auth_page(self, request, response, environ, scopes):
5959
site_adapter=ExampleSiteAdapter(),
6060
token_generator=oauth2.tokengenerator.Uuid4()
6161
)
62-
62+
6363
# Add Grants you want to support
6464
auth_controller.add_grant(oauth2.grant.AuthorizationCodeGrant())
6565
auth_controller.add_grant(oauth2.grant.ImplicitGrant())
6666
6767
# Add refresh token capability and set expiration time of access tokens
6868
# to 30 days
6969
auth_controller.add_grant(oauth2.grant.RefreshToken(expires_in=2592000))
70-
70+
7171
# Wrap the controller with the Wsgi adapter
7272
app = oauth2.web.Wsgi(server=auth_controller)
73-
73+
7474
if __name__ == "__main__":
7575
httpd = make_server('', 8080, app)
7676
httpd.serve_forever()
@@ -102,7 +102,7 @@ class Provider(object):
102102
def __init__(self, access_token_store, auth_code_store, client_store,
103103
site_adapter, token_generator, response_class=Response):
104104
"""
105-
Endpoint of requests to the OAuth 2.0 server.
105+
Endpoint of requests to the OAuth 2.0 provider.
106106
107107
:param access_token_store: An object that implements methods defiend by
108108
:class:`oauth2.store.AccessTokenStore`.
@@ -129,7 +129,7 @@ def __init__(self, access_token_store, auth_code_store, client_store,
129129

130130
def add_grant(self, grant):
131131
"""
132-
Adds a Grant that the server should support.
132+
Adds a Grant that the provider should support.
133133
"""
134134
if hasattr(grant, "expires_in"):
135135
self.token_generator.expires_in = grant.expires_in
@@ -167,6 +167,7 @@ def dispatch(self, request, environ):
167167
response.body = json.dumps(json_body)
168168
return response
169169

170+
@property
170171
def scope_separator(self, separator):
171172
"""
172173
Sets the separator of values in scope query parameter.

oauth2/store/memcache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from oauth2.error import AccessTokenNotFound, AuthCodeNotFound
55
from oauth2.store import AccessTokenStore, AuthCodeStore
66

7-
class MemcacheTokenStore(AccessTokenStore, AuthCodeStore):
7+
class TokenStore(AccessTokenStore, AuthCodeStore):
88
"""
99
Uses memcache to store access tokens and auth tokens.
1010
@@ -19,11 +19,11 @@ class MemcacheTokenStore(AccessTokenStore, AuthCodeStore):
1919
# Somewhere in your application
2020
mc = memcache.Client(servers=['127.0.0.1:11211'], debug=0)
2121
# ...
22-
token_store = MemcacheTokenStore(mc=mc)
22+
token_store = TokenStore(mc=mc)
2323
2424
Initialization using ``python-memcached``::
2525
26-
token_store = MemcacheTokenStore(servers=['127.0.0.1:11211'], debug=0)
26+
token_store = TokenStore(servers=['127.0.0.1:11211'], debug=0)
2727
2828
"""
2929
def __init__(self, mc=None, prefix="oauth2", *args, **kwargs):

0 commit comments

Comments
 (0)