gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / oauthlib / oauth2 / rfc6749 / endpoints / pre_configured.py @ 564
History | View | Annotate | Download (10.9 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
"""
|
3 |
oauthlib.oauth2.rfc6749
|
4 |
~~~~~~~~~~~~~~~~~~~~~~~
|
5 |
|
6 |
This module is an implementation of various logic needed
|
7 |
for consuming and providing OAuth 2.0 RFC6749.
|
8 |
"""
|
9 |
from __future__ import absolute_import, unicode_literals |
10 |
|
11 |
from ..tokens import BearerToken |
12 |
from ..grant_types import AuthorizationCodeGrant |
13 |
from ..grant_types import ImplicitGrant |
14 |
from ..grant_types import ResourceOwnerPasswordCredentialsGrant |
15 |
from ..grant_types import ClientCredentialsGrant |
16 |
from ..grant_types import RefreshTokenGrant |
17 |
|
18 |
from .authorization import AuthorizationEndpoint |
19 |
from .token import TokenEndpoint |
20 |
from .resource import ResourceEndpoint |
21 |
from .revocation import RevocationEndpoint |
22 |
|
23 |
|
24 |
class Server(AuthorizationEndpoint, TokenEndpoint, ResourceEndpoint, |
25 |
RevocationEndpoint): |
26 |
|
27 |
"""An all-in-one endpoint featuring all four major grant types."""
|
28 |
|
29 |
def __init__(self, request_validator, token_expires_in=None, |
30 |
token_generator=None, refresh_token_generator=None, |
31 |
*args, **kwargs): |
32 |
"""Construct a new all-grants-in-one server.
|
33 |
|
34 |
:param request_validator: An implementation of
|
35 |
oauthlib.oauth2.RequestValidator.
|
36 |
:param token_expires_in: An int or a function to generate a token
|
37 |
expiration offset (in seconds) given a
|
38 |
oauthlib.common.Request object.
|
39 |
:param token_generator: A function to generate a token from a request.
|
40 |
:param refresh_token_generator: A function to generate a token from a
|
41 |
request for the refresh token.
|
42 |
:param kwargs: Extra parameters to pass to authorization-,
|
43 |
token-, resource-, and revocation-endpoint constructors.
|
44 |
"""
|
45 |
auth_grant = AuthorizationCodeGrant(request_validator) |
46 |
implicit_grant = ImplicitGrant(request_validator) |
47 |
password_grant = ResourceOwnerPasswordCredentialsGrant( |
48 |
request_validator) |
49 |
credentials_grant = ClientCredentialsGrant(request_validator) |
50 |
refresh_grant = RefreshTokenGrant(request_validator) |
51 |
bearer = BearerToken(request_validator, token_generator, |
52 |
token_expires_in, refresh_token_generator) |
53 |
AuthorizationEndpoint.__init__(self, default_response_type='code', |
54 |
response_types={ |
55 |
'code': auth_grant,
|
56 |
'token': implicit_grant,
|
57 |
}, |
58 |
default_token_type=bearer) |
59 |
TokenEndpoint.__init__(self, default_grant_type='authorization_code', |
60 |
grant_types={ |
61 |
'authorization_code': auth_grant,
|
62 |
'password': password_grant,
|
63 |
'client_credentials': credentials_grant,
|
64 |
'refresh_token': refresh_grant,
|
65 |
}, |
66 |
default_token_type=bearer) |
67 |
ResourceEndpoint.__init__(self, default_token='Bearer', |
68 |
token_types={'Bearer': bearer})
|
69 |
RevocationEndpoint.__init__(self, request_validator)
|
70 |
|
71 |
|
72 |
class WebApplicationServer(AuthorizationEndpoint, TokenEndpoint, ResourceEndpoint, |
73 |
RevocationEndpoint): |
74 |
|
75 |
"""An all-in-one endpoint featuring Authorization code grant and Bearer tokens."""
|
76 |
|
77 |
def __init__(self, request_validator, token_generator=None, |
78 |
token_expires_in=None, refresh_token_generator=None, **kwargs): |
79 |
"""Construct a new web application server.
|
80 |
|
81 |
:param request_validator: An implementation of
|
82 |
oauthlib.oauth2.RequestValidator.
|
83 |
:param token_expires_in: An int or a function to generate a token
|
84 |
expiration offset (in seconds) given a
|
85 |
oauthlib.common.Request object.
|
86 |
:param token_generator: A function to generate a token from a request.
|
87 |
:param refresh_token_generator: A function to generate a token from a
|
88 |
request for the refresh token.
|
89 |
:param kwargs: Extra parameters to pass to authorization-,
|
90 |
token-, resource-, and revocation-endpoint constructors.
|
91 |
"""
|
92 |
auth_grant = AuthorizationCodeGrant(request_validator) |
93 |
refresh_grant = RefreshTokenGrant(request_validator) |
94 |
bearer = BearerToken(request_validator, token_generator, |
95 |
token_expires_in, refresh_token_generator) |
96 |
AuthorizationEndpoint.__init__(self, default_response_type='code', |
97 |
response_types={'code': auth_grant},
|
98 |
default_token_type=bearer) |
99 |
TokenEndpoint.__init__(self, default_grant_type='authorization_code', |
100 |
grant_types={ |
101 |
'authorization_code': auth_grant,
|
102 |
'refresh_token': refresh_grant,
|
103 |
}, |
104 |
default_token_type=bearer) |
105 |
ResourceEndpoint.__init__(self, default_token='Bearer', |
106 |
token_types={'Bearer': bearer})
|
107 |
RevocationEndpoint.__init__(self, request_validator)
|
108 |
|
109 |
|
110 |
class MobileApplicationServer(AuthorizationEndpoint, ResourceEndpoint, |
111 |
RevocationEndpoint): |
112 |
|
113 |
"""An all-in-one endpoint featuring Implicit code grant and Bearer tokens."""
|
114 |
|
115 |
def __init__(self, request_validator, token_generator=None, |
116 |
token_expires_in=None, refresh_token_generator=None, **kwargs): |
117 |
"""Construct a new implicit grant server.
|
118 |
|
119 |
:param request_validator: An implementation of
|
120 |
oauthlib.oauth2.RequestValidator.
|
121 |
:param token_expires_in: An int or a function to generate a token
|
122 |
expiration offset (in seconds) given a
|
123 |
oauthlib.common.Request object.
|
124 |
:param token_generator: A function to generate a token from a request.
|
125 |
:param refresh_token_generator: A function to generate a token from a
|
126 |
request for the refresh token.
|
127 |
:param kwargs: Extra parameters to pass to authorization-,
|
128 |
token-, resource-, and revocation-endpoint constructors.
|
129 |
"""
|
130 |
implicit_grant = ImplicitGrant(request_validator) |
131 |
bearer = BearerToken(request_validator, token_generator, |
132 |
token_expires_in, refresh_token_generator) |
133 |
AuthorizationEndpoint.__init__(self, default_response_type='token', |
134 |
response_types={ |
135 |
'token': implicit_grant},
|
136 |
default_token_type=bearer) |
137 |
ResourceEndpoint.__init__(self, default_token='Bearer', |
138 |
token_types={'Bearer': bearer})
|
139 |
RevocationEndpoint.__init__(self, request_validator,
|
140 |
supported_token_types=['access_token'])
|
141 |
|
142 |
|
143 |
class LegacyApplicationServer(TokenEndpoint, ResourceEndpoint, |
144 |
RevocationEndpoint): |
145 |
|
146 |
"""An all-in-one endpoint featuring Resource Owner Password Credentials grant and Bearer tokens."""
|
147 |
|
148 |
def __init__(self, request_validator, token_generator=None, |
149 |
token_expires_in=None, refresh_token_generator=None, **kwargs): |
150 |
"""Construct a resource owner password credentials grant server.
|
151 |
|
152 |
:param request_validator: An implementation of
|
153 |
oauthlib.oauth2.RequestValidator.
|
154 |
:param token_expires_in: An int or a function to generate a token
|
155 |
expiration offset (in seconds) given a
|
156 |
oauthlib.common.Request object.
|
157 |
:param token_generator: A function to generate a token from a request.
|
158 |
:param refresh_token_generator: A function to generate a token from a
|
159 |
request for the refresh token.
|
160 |
:param kwargs: Extra parameters to pass to authorization-,
|
161 |
token-, resource-, and revocation-endpoint constructors.
|
162 |
"""
|
163 |
password_grant = ResourceOwnerPasswordCredentialsGrant( |
164 |
request_validator) |
165 |
refresh_grant = RefreshTokenGrant(request_validator) |
166 |
bearer = BearerToken(request_validator, token_generator, |
167 |
token_expires_in, refresh_token_generator) |
168 |
TokenEndpoint.__init__(self, default_grant_type='password', |
169 |
grant_types={ |
170 |
'password': password_grant,
|
171 |
'refresh_token': refresh_grant,
|
172 |
}, |
173 |
default_token_type=bearer) |
174 |
ResourceEndpoint.__init__(self, default_token='Bearer', |
175 |
token_types={'Bearer': bearer})
|
176 |
RevocationEndpoint.__init__(self, request_validator)
|
177 |
|
178 |
|
179 |
class BackendApplicationServer(TokenEndpoint, ResourceEndpoint, |
180 |
RevocationEndpoint): |
181 |
|
182 |
"""An all-in-one endpoint featuring Client Credentials grant and Bearer tokens."""
|
183 |
|
184 |
def __init__(self, request_validator, token_generator=None, |
185 |
token_expires_in=None, refresh_token_generator=None, **kwargs): |
186 |
"""Construct a client credentials grant server.
|
187 |
|
188 |
:param request_validator: An implementation of
|
189 |
oauthlib.oauth2.RequestValidator.
|
190 |
:param token_expires_in: An int or a function to generate a token
|
191 |
expiration offset (in seconds) given a
|
192 |
oauthlib.common.Request object.
|
193 |
:param token_generator: A function to generate a token from a request.
|
194 |
:param refresh_token_generator: A function to generate a token from a
|
195 |
request for the refresh token.
|
196 |
:param kwargs: Extra parameters to pass to authorization-,
|
197 |
token-, resource-, and revocation-endpoint constructors.
|
198 |
"""
|
199 |
credentials_grant = ClientCredentialsGrant(request_validator) |
200 |
bearer = BearerToken(request_validator, token_generator, |
201 |
token_expires_in, refresh_token_generator) |
202 |
TokenEndpoint.__init__(self, default_grant_type='client_credentials', |
203 |
grant_types={ |
204 |
'client_credentials': credentials_grant},
|
205 |
default_token_type=bearer) |
206 |
ResourceEndpoint.__init__(self, default_token='Bearer', |
207 |
token_types={'Bearer': bearer})
|
208 |
RevocationEndpoint.__init__(self, request_validator,
|
209 |
supported_token_types=['access_token'])
|