Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/endpoints/pre_configured.py: 31%
55 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:22 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:22 +0000
1"""
2oauthlib.oauth2.rfc6749.endpoints.pre_configured
3~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5This module is an implementation of various endpoints needed
6for providing OAuth 2.0 RFC6749 servers.
7"""
8from ..grant_types import (
9 AuthorizationCodeGrant, ClientCredentialsGrant, ImplicitGrant,
10 RefreshTokenGrant, ResourceOwnerPasswordCredentialsGrant,
11)
12from ..tokens import BearerToken
13from .authorization import AuthorizationEndpoint
14from .introspect import IntrospectEndpoint
15from .resource import ResourceEndpoint
16from .revocation import RevocationEndpoint
17from .token import TokenEndpoint
20class Server(AuthorizationEndpoint, IntrospectEndpoint, TokenEndpoint,
21 ResourceEndpoint, RevocationEndpoint):
23 """An all-in-one endpoint featuring all four major grant types."""
25 def __init__(self, request_validator, token_expires_in=None,
26 token_generator=None, refresh_token_generator=None,
27 *args, **kwargs):
28 """Construct a new all-grants-in-one server.
30 :param request_validator: An implementation of
31 oauthlib.oauth2.RequestValidator.
32 :param token_expires_in: An int or a function to generate a token
33 expiration offset (in seconds) given a
34 oauthlib.common.Request object.
35 :param token_generator: A function to generate a token from a request.
36 :param refresh_token_generator: A function to generate a token from a
37 request for the refresh token.
38 :param kwargs: Extra parameters to pass to authorization-,
39 token-, resource-, and revocation-endpoint constructors.
40 """
41 self.auth_grant = AuthorizationCodeGrant(request_validator)
42 self.implicit_grant = ImplicitGrant(request_validator)
43 self.password_grant = ResourceOwnerPasswordCredentialsGrant(
44 request_validator)
45 self.credentials_grant = ClientCredentialsGrant(request_validator)
46 self.refresh_grant = RefreshTokenGrant(request_validator)
48 self.bearer = BearerToken(request_validator, token_generator,
49 token_expires_in, refresh_token_generator)
51 AuthorizationEndpoint.__init__(self, default_response_type='code',
52 response_types={
53 'code': self.auth_grant,
54 'token': self.implicit_grant,
55 'none': self.auth_grant
56 },
57 default_token_type=self.bearer)
59 TokenEndpoint.__init__(self, default_grant_type='authorization_code',
60 grant_types={
61 'authorization_code': self.auth_grant,
62 'password': self.password_grant,
63 'client_credentials': self.credentials_grant,
64 'refresh_token': self.refresh_grant,
65 },
66 default_token_type=self.bearer)
67 ResourceEndpoint.__init__(self, default_token='Bearer',
68 token_types={'Bearer': self.bearer})
69 RevocationEndpoint.__init__(self, request_validator)
70 IntrospectEndpoint.__init__(self, request_validator)
73class WebApplicationServer(AuthorizationEndpoint, IntrospectEndpoint, TokenEndpoint,
74 ResourceEndpoint, RevocationEndpoint):
76 """An all-in-one endpoint featuring Authorization code grant and Bearer tokens."""
78 def __init__(self, request_validator, token_generator=None,
79 token_expires_in=None, refresh_token_generator=None, **kwargs):
80 """Construct a new web application server.
82 :param request_validator: An implementation of
83 oauthlib.oauth2.RequestValidator.
84 :param token_expires_in: An int or a function to generate a token
85 expiration offset (in seconds) given a
86 oauthlib.common.Request object.
87 :param token_generator: A function to generate a token from a request.
88 :param refresh_token_generator: A function to generate a token from a
89 request for the refresh token.
90 :param kwargs: Extra parameters to pass to authorization-,
91 token-, resource-, and revocation-endpoint constructors.
92 """
93 self.auth_grant = AuthorizationCodeGrant(request_validator)
94 self.refresh_grant = RefreshTokenGrant(request_validator)
95 self.bearer = BearerToken(request_validator, token_generator,
96 token_expires_in, refresh_token_generator)
97 AuthorizationEndpoint.__init__(self, default_response_type='code',
98 response_types={'code': self.auth_grant},
99 default_token_type=self.bearer)
100 TokenEndpoint.__init__(self, default_grant_type='authorization_code',
101 grant_types={
102 'authorization_code': self.auth_grant,
103 'refresh_token': self.refresh_grant,
104 },
105 default_token_type=self.bearer)
106 ResourceEndpoint.__init__(self, default_token='Bearer',
107 token_types={'Bearer': self.bearer})
108 RevocationEndpoint.__init__(self, request_validator)
109 IntrospectEndpoint.__init__(self, request_validator)
112class MobileApplicationServer(AuthorizationEndpoint, IntrospectEndpoint,
113 ResourceEndpoint, RevocationEndpoint):
115 """An all-in-one endpoint featuring Implicit code grant and Bearer tokens."""
117 def __init__(self, request_validator, token_generator=None,
118 token_expires_in=None, refresh_token_generator=None, **kwargs):
119 """Construct a new implicit grant server.
121 :param request_validator: An implementation of
122 oauthlib.oauth2.RequestValidator.
123 :param token_expires_in: An int or a function to generate a token
124 expiration offset (in seconds) given a
125 oauthlib.common.Request object.
126 :param token_generator: A function to generate a token from a request.
127 :param refresh_token_generator: A function to generate a token from a
128 request for the refresh token.
129 :param kwargs: Extra parameters to pass to authorization-,
130 token-, resource-, and revocation-endpoint constructors.
131 """
132 self.implicit_grant = ImplicitGrant(request_validator)
133 self.bearer = BearerToken(request_validator, token_generator,
134 token_expires_in, refresh_token_generator)
135 AuthorizationEndpoint.__init__(self, default_response_type='token',
136 response_types={
137 'token': self.implicit_grant},
138 default_token_type=self.bearer)
139 ResourceEndpoint.__init__(self, default_token='Bearer',
140 token_types={'Bearer': self.bearer})
141 RevocationEndpoint.__init__(self, request_validator,
142 supported_token_types=['access_token'])
143 IntrospectEndpoint.__init__(self, request_validator,
144 supported_token_types=['access_token'])
147class LegacyApplicationServer(TokenEndpoint, IntrospectEndpoint,
148 ResourceEndpoint, RevocationEndpoint):
150 """An all-in-one endpoint featuring Resource Owner Password Credentials grant and Bearer tokens."""
152 def __init__(self, request_validator, token_generator=None,
153 token_expires_in=None, refresh_token_generator=None, **kwargs):
154 """Construct a resource owner password credentials grant server.
156 :param request_validator: An implementation of
157 oauthlib.oauth2.RequestValidator.
158 :param token_expires_in: An int or a function to generate a token
159 expiration offset (in seconds) given a
160 oauthlib.common.Request object.
161 :param token_generator: A function to generate a token from a request.
162 :param refresh_token_generator: A function to generate a token from a
163 request for the refresh token.
164 :param kwargs: Extra parameters to pass to authorization-,
165 token-, resource-, and revocation-endpoint constructors.
166 """
167 self.password_grant = ResourceOwnerPasswordCredentialsGrant(
168 request_validator)
169 self.refresh_grant = RefreshTokenGrant(request_validator)
170 self.bearer = BearerToken(request_validator, token_generator,
171 token_expires_in, refresh_token_generator)
172 TokenEndpoint.__init__(self, default_grant_type='password',
173 grant_types={
174 'password': self.password_grant,
175 'refresh_token': self.refresh_grant,
176 },
177 default_token_type=self.bearer)
178 ResourceEndpoint.__init__(self, default_token='Bearer',
179 token_types={'Bearer': self.bearer})
180 RevocationEndpoint.__init__(self, request_validator)
181 IntrospectEndpoint.__init__(self, request_validator)
184class BackendApplicationServer(TokenEndpoint, IntrospectEndpoint,
185 ResourceEndpoint, RevocationEndpoint):
187 """An all-in-one endpoint featuring Client Credentials grant and Bearer tokens."""
189 def __init__(self, request_validator, token_generator=None,
190 token_expires_in=None, refresh_token_generator=None, **kwargs):
191 """Construct a client credentials grant server.
193 :param request_validator: An implementation of
194 oauthlib.oauth2.RequestValidator.
195 :param token_expires_in: An int or a function to generate a token
196 expiration offset (in seconds) given a
197 oauthlib.common.Request object.
198 :param token_generator: A function to generate a token from a request.
199 :param refresh_token_generator: A function to generate a token from a
200 request for the refresh token.
201 :param kwargs: Extra parameters to pass to authorization-,
202 token-, resource-, and revocation-endpoint constructors.
203 """
204 self.credentials_grant = ClientCredentialsGrant(request_validator)
205 self.bearer = BearerToken(request_validator, token_generator,
206 token_expires_in, refresh_token_generator)
207 TokenEndpoint.__init__(self, default_grant_type='client_credentials',
208 grant_types={
209 'client_credentials': self.credentials_grant},
210 default_token_type=self.bearer)
211 ResourceEndpoint.__init__(self, default_token='Bearer',
212 token_types={'Bearer': self.bearer})
213 RevocationEndpoint.__init__(self, request_validator,
214 supported_token_types=['access_token'])
215 IntrospectEndpoint.__init__(self, request_validator,
216 supported_token_types=['access_token'])