5
5
This module is an implementation of various endpoints needed
6
6
for providing OpenID Connect servers.
7
7
"""
8
+
8
9
from oauthlib .oauth2 .rfc6749 .endpoints import (
9
- AuthorizationEndpoint , IntrospectEndpoint , ResourceEndpoint ,
10
- RevocationEndpoint , TokenEndpoint ,
10
+ AuthorizationEndpoint ,
11
+ IntrospectEndpoint ,
12
+ ResourceEndpoint ,
13
+ RevocationEndpoint ,
14
+ TokenEndpoint ,
11
15
)
12
16
from oauthlib .oauth2 .rfc6749 .grant_types import (
13
17
AuthorizationCodeGrant as OAuth2AuthorizationCodeGrant ,
14
- ClientCredentialsGrant , ImplicitGrant as OAuth2ImplicitGrant ,
18
+ ClientCredentialsGrant ,
19
+ ImplicitGrant as OAuth2ImplicitGrant ,
15
20
ResourceOwnerPasswordCredentialsGrant ,
16
21
)
17
22
from oauthlib .oauth2 .rfc6749 .tokens import BearerToken
18
23
from oauthlib .oauth2 .rfc8628 .endpoints import DeviceAuthorizationEndpoint
19
24
20
25
from ..grant_types import (
21
- AuthorizationCodeGrant , HybridGrant , ImplicitGrant , RefreshTokenGrant ,
26
+ AuthorizationCodeGrant ,
27
+ HybridGrant ,
28
+ ImplicitGrant ,
29
+ RefreshTokenGrant ,
22
30
)
23
31
from ..grant_types .dispatchers import (
24
- AuthorizationCodeGrantDispatcher , AuthorizationTokenGrantDispatcher ,
32
+ AuthorizationCodeGrantDispatcher ,
33
+ AuthorizationTokenGrantDispatcher ,
25
34
ImplicitTokenGrantDispatcher ,
26
35
)
27
36
from ..tokens import JWTToken
28
37
from .userinfo import UserInfoEndpoint
29
38
30
39
31
- class Server (AuthorizationEndpoint , IntrospectEndpoint , TokenEndpoint ,
32
- ResourceEndpoint , RevocationEndpoint , UserInfoEndpoint ):
33
-
40
+ class Server (AuthorizationEndpoint , IntrospectEndpoint , TokenEndpoint , ResourceEndpoint , RevocationEndpoint , UserInfoEndpoint ):
34
41
"""An all-in-one endpoint featuring all four major grant types."""
35
42
36
- def __init__ (self , request_validator , token_expires_in = None ,
37
- token_generator = None , refresh_token_generator = None ,
38
- * args , ** kwargs ):
43
+ def __init__ (self , request_validator , token_expires_in = None , token_generator = None , refresh_token_generator = None , * args , ** kwargs ):
39
44
"""Construct a new all-grants-in-one server.
40
45
41
46
:param request_validator: An implementation of
@@ -51,50 +56,52 @@ def __init__(self, request_validator, token_expires_in=None,
51
56
"""
52
57
self .auth_grant = OAuth2AuthorizationCodeGrant (request_validator )
53
58
self .implicit_grant = OAuth2ImplicitGrant (request_validator )
54
- self .password_grant = ResourceOwnerPasswordCredentialsGrant (
55
- request_validator )
59
+ self .password_grant = ResourceOwnerPasswordCredentialsGrant (request_validator )
56
60
self .credentials_grant = ClientCredentialsGrant (request_validator )
57
61
self .refresh_grant = RefreshTokenGrant (request_validator )
58
62
self .openid_connect_auth = AuthorizationCodeGrant (request_validator )
59
63
self .openid_connect_implicit = ImplicitGrant (request_validator )
60
64
self .openid_connect_hybrid = HybridGrant (request_validator )
61
65
62
- self .bearer = BearerToken (request_validator , token_generator ,
63
- token_expires_in , refresh_token_generator )
66
+ self .bearer = BearerToken (request_validator , token_generator , token_expires_in , refresh_token_generator )
64
67
65
- self .jwt = JWTToken (request_validator , token_generator ,
66
- token_expires_in , refresh_token_generator )
68
+ self .jwt = JWTToken (request_validator , token_generator , token_expires_in , refresh_token_generator )
67
69
68
70
self .auth_grant_choice = AuthorizationCodeGrantDispatcher (default_grant = self .auth_grant , oidc_grant = self .openid_connect_auth )
69
71
self .implicit_grant_choice = ImplicitTokenGrantDispatcher (default_grant = self .implicit_grant , oidc_grant = self .openid_connect_implicit )
70
72
71
73
# See http://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#Combinations for valid combinations
72
74
# internally our AuthorizationEndpoint will ensure they can appear in any order for any valid combination
73
- AuthorizationEndpoint .__init__ (self , default_response_type = 'code' ,
74
- response_types = {
75
- 'code' : self .auth_grant_choice ,
76
- 'token' : self .implicit_grant_choice ,
77
- 'id_token' : self .openid_connect_implicit ,
78
- 'id_token token' : self .openid_connect_implicit ,
79
- 'code token' : self .openid_connect_hybrid ,
80
- 'code id_token' : self .openid_connect_hybrid ,
81
- 'code id_token token' : self .openid_connect_hybrid ,
82
- 'none' : self .auth_grant
83
- },
84
- default_token_type = self .bearer )
75
+ AuthorizationEndpoint .__init__ (
76
+ self ,
77
+ default_response_type = "code" ,
78
+ response_types = {
79
+ "code" : self .auth_grant_choice ,
80
+ "token" : self .implicit_grant_choice ,
81
+ "id_token" : self .openid_connect_implicit ,
82
+ "id_token token" : self .openid_connect_implicit ,
83
+ "code token" : self .openid_connect_hybrid ,
84
+ "code id_token" : self .openid_connect_hybrid ,
85
+ "code id_token token" : self .openid_connect_hybrid ,
86
+ "none" : self .auth_grant ,
87
+ },
88
+ default_token_type = self .bearer ,
89
+ )
85
90
86
91
self .token_grant_choice = AuthorizationTokenGrantDispatcher (request_validator , default_grant = self .auth_grant , oidc_grant = self .openid_connect_auth )
87
92
88
- TokenEndpoint .__init__ (self , default_grant_type = 'authorization_code' ,
89
- grant_types = {
90
- 'authorization_code' : self .token_grant_choice ,
91
- 'password' : self .password_grant ,
92
- 'client_credentials' : self .credentials_grant ,
93
- 'refresh_token' : self .refresh_grant ,
94
- },
95
- default_token_type = self .bearer )
96
- ResourceEndpoint .__init__ (self , default_token = 'Bearer' ,
97
- token_types = {'Bearer' : self .bearer , 'JWT' : self .jwt })
93
+ TokenEndpoint .__init__ (
94
+ self ,
95
+ default_grant_type = "authorization_code" ,
96
+ grant_types = {
97
+ "authorization_code" : self .token_grant_choice ,
98
+ "password" : self .password_grant ,
99
+ "client_credentials" : self .credentials_grant ,
100
+ "refresh_token" : self .refresh_grant ,
101
+ },
102
+ default_token_type = self .bearer ,
103
+ )
104
+ ResourceEndpoint .__init__ (self , default_token = "Bearer" , token_types = {"Bearer" : self .bearer , "JWT" : self .jwt })
98
105
RevocationEndpoint .__init__ (self , request_validator )
99
106
IntrospectEndpoint .__init__ (self , request_validator )
100
107
UserInfoEndpoint .__init__ (self , request_validator )
0 commit comments