Skip to content

Commit 51ddcf6

Browse files
committed
Apply 99 line length ruff format
1 parent 06d8487 commit 51ddcf6

File tree

7 files changed

+132
-40
lines changed

7 files changed

+132
-40
lines changed

oauthlib/oauth2/__init__.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,62 @@
55
This module is a wrapper for the most recent implementation of OAuth 2.0 Client
66
and Server classes.
77
"""
8+
89
from .rfc6749.clients import (
9-
BackendApplicationClient, Client, LegacyApplicationClient,
10-
MobileApplicationClient, ServiceApplicationClient, WebApplicationClient,
10+
BackendApplicationClient,
11+
Client,
12+
LegacyApplicationClient,
13+
MobileApplicationClient,
14+
ServiceApplicationClient,
15+
WebApplicationClient,
1116
)
1217
from .rfc6749.endpoints import (
13-
AuthorizationEndpoint, BackendApplicationServer, IntrospectEndpoint,
14-
LegacyApplicationServer, MetadataEndpoint, MobileApplicationServer,
15-
ResourceEndpoint, RevocationEndpoint, Server, TokenEndpoint,
18+
AuthorizationEndpoint,
19+
BackendApplicationServer,
20+
IntrospectEndpoint,
21+
LegacyApplicationServer,
22+
MetadataEndpoint,
23+
MobileApplicationServer,
24+
ResourceEndpoint,
25+
RevocationEndpoint,
26+
Server,
27+
TokenEndpoint,
1628
WebApplicationServer,
1729
)
1830
from .rfc6749.errors import (
19-
AccessDeniedError, FatalClientError, InsecureTransportError,
20-
InvalidClientError, InvalidClientIdError, InvalidGrantError,
21-
InvalidRedirectURIError, InvalidRequestError, InvalidRequestFatalError,
22-
InvalidScopeError, MismatchingRedirectURIError, MismatchingStateError,
23-
MissingClientIdError, MissingCodeError, MissingRedirectURIError,
24-
MissingResponseTypeError, MissingTokenError, MissingTokenTypeError,
25-
OAuth2Error, ServerError, TemporarilyUnavailableError, TokenExpiredError,
26-
UnauthorizedClientError, UnsupportedGrantTypeError,
27-
UnsupportedResponseTypeError, UnsupportedTokenTypeError,
31+
AccessDeniedError,
32+
FatalClientError,
33+
InsecureTransportError,
34+
InvalidClientError,
35+
InvalidClientIdError,
36+
InvalidGrantError,
37+
InvalidRedirectURIError,
38+
InvalidRequestError,
39+
InvalidRequestFatalError,
40+
InvalidScopeError,
41+
MismatchingRedirectURIError,
42+
MismatchingStateError,
43+
MissingClientIdError,
44+
MissingCodeError,
45+
MissingRedirectURIError,
46+
MissingResponseTypeError,
47+
MissingTokenError,
48+
MissingTokenTypeError,
49+
OAuth2Error,
50+
ServerError,
51+
TemporarilyUnavailableError,
52+
TokenExpiredError,
53+
UnauthorizedClientError,
54+
UnsupportedGrantTypeError,
55+
UnsupportedResponseTypeError,
56+
UnsupportedTokenTypeError,
2857
)
2958
from .rfc6749.grant_types import (
30-
AuthorizationCodeGrant, ClientCredentialsGrant, ImplicitGrant,
31-
RefreshTokenGrant, ResourceOwnerPasswordCredentialsGrant,
59+
AuthorizationCodeGrant,
60+
ClientCredentialsGrant,
61+
ImplicitGrant,
62+
RefreshTokenGrant,
63+
ResourceOwnerPasswordCredentialsGrant,
3264
)
3365
from .rfc6749.request_validator import RequestValidator
3466
from .rfc6749.tokens import BearerToken, OAuth2Token

oauthlib/oauth2/rfc8628/endpoints/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
This module is an implementation of various logic needed
66
for consuming and providing OAuth 2.0 Device Authorization RFC8628.
77
"""
8+
89
from .device_authorization import DeviceAuthorizationEndpoint
910
from .pre_configured import DeviceApplicationServer

oauthlib/oauth2/rfc8628/endpoints/device_authorization.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ class DeviceAuthorizationEndpoint(BaseEndpoint):
3434
themselves.
3535
"""
3636

37-
def __init__(self, request_validator, verification_uri, expires_in=1800, interval=None, verification_uri_complete=None, user_code_generator: Callable[[None], str] = None):
37+
def __init__(
38+
self,
39+
request_validator,
40+
verification_uri,
41+
expires_in=1800,
42+
interval=None,
43+
verification_uri_complete=None,
44+
user_code_generator: Callable[[None], str] = None,
45+
):
3846
"""
3947
:param request_validator: An instance of RequestValidator.
4048
:type request_validator: oauthlib.oauth2.rfc6749.RequestValidator.
@@ -99,9 +107,13 @@ def validate_device_authorization_request(self, request):
99107
try:
100108
duplicate_params = request.duplicate_params
101109
except ValueError:
102-
raise errors.InvalidRequestFatalError(description="Unable to parse query string", request=request)
110+
raise errors.InvalidRequestFatalError(
111+
description="Unable to parse query string", request=request
112+
)
103113
if param in duplicate_params:
104-
raise errors.InvalidRequestFatalError(description="Duplicate %s parameter." % param, request=request)
114+
raise errors.InvalidRequestFatalError(
115+
description="Duplicate %s parameter." % param, request=request
116+
)
105117

106118
# the "application/x-www-form-urlencoded" format, per Appendix B of [RFC6749]
107119
# https://www.rfc-editor.org/rfc/rfc6749#appendix-B
@@ -129,7 +141,9 @@ def validate_device_authorization_request(self, request):
129141
self._raise_on_invalid_client(request)
130142

131143
@catch_errors_and_unavailability
132-
def create_device_authorization_response(self, uri, http_method="POST", body=None, headers=None):
144+
def create_device_authorization_response(
145+
self, uri, http_method="POST", body=None, headers=None
146+
):
133147
"""create_device_authorization_response - generates a unique device
134148
verification code and an end-user code that are valid for a limited
135149
time and includes them in the HTTP response body using the

oauthlib/oauth2/rfc8628/endpoints/pre_configured.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@
77
class DeviceApplicationServer(DeviceAuthorizationEndpoint):
88
"""An all-in-one endpoint featuring Authorization code grant and Bearer tokens."""
99

10-
def __init__(self, request_validator, verification_uri, user_code_generator: Callable[[None], str] = None, **kwargs):
10+
def __init__(
11+
self,
12+
request_validator,
13+
verification_uri,
14+
user_code_generator: Callable[[None], str] = None,
15+
**kwargs,
16+
):
1117
"""Construct a new web application server.
1218
1319
:param request_validator: An implementation of
1420
oauthlib.oauth2.rfc8626.RequestValidator.
1521
:param verification_uri: the verification_uri to be send back.
1622
:param user_code_generator: a callable that allows the user code to be configured.
1723
"""
18-
DeviceAuthorizationEndpoint.__init__(self, request_validator, verification_uri=verification_uri, user_code_generator=user_code_generator)
24+
DeviceAuthorizationEndpoint.__init__(
25+
self,
26+
request_validator,
27+
verification_uri=verification_uri,
28+
user_code_generator=user_code_generator,
29+
)

oauthlib/openid/connect/core/endpoints/pre_configured.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,25 @@
3737
from .userinfo import UserInfoEndpoint
3838

3939

40-
class Server(AuthorizationEndpoint, IntrospectEndpoint, TokenEndpoint, ResourceEndpoint, RevocationEndpoint, UserInfoEndpoint):
40+
class Server(
41+
AuthorizationEndpoint,
42+
IntrospectEndpoint,
43+
TokenEndpoint,
44+
ResourceEndpoint,
45+
RevocationEndpoint,
46+
UserInfoEndpoint,
47+
):
4148
"""An all-in-one endpoint featuring all four major grant types."""
4249

43-
def __init__(self, request_validator, token_expires_in=None, token_generator=None, refresh_token_generator=None, *args, **kwargs):
50+
def __init__(
51+
self,
52+
request_validator,
53+
token_expires_in=None,
54+
token_generator=None,
55+
refresh_token_generator=None,
56+
*args,
57+
**kwargs,
58+
):
4459
"""Construct a new all-grants-in-one server.
4560
4661
:param request_validator: An implementation of
@@ -63,12 +78,20 @@ def __init__(self, request_validator, token_expires_in=None, token_generator=Non
6378
self.openid_connect_implicit = ImplicitGrant(request_validator)
6479
self.openid_connect_hybrid = HybridGrant(request_validator)
6580

66-
self.bearer = BearerToken(request_validator, token_generator, token_expires_in, refresh_token_generator)
81+
self.bearer = BearerToken(
82+
request_validator, token_generator, token_expires_in, refresh_token_generator
83+
)
6784

68-
self.jwt = JWTToken(request_validator, token_generator, token_expires_in, refresh_token_generator)
85+
self.jwt = JWTToken(
86+
request_validator, token_generator, token_expires_in, refresh_token_generator
87+
)
6988

70-
self.auth_grant_choice = AuthorizationCodeGrantDispatcher(default_grant=self.auth_grant, oidc_grant=self.openid_connect_auth)
71-
self.implicit_grant_choice = ImplicitTokenGrantDispatcher(default_grant=self.implicit_grant, oidc_grant=self.openid_connect_implicit)
89+
self.auth_grant_choice = AuthorizationCodeGrantDispatcher(
90+
default_grant=self.auth_grant, oidc_grant=self.openid_connect_auth
91+
)
92+
self.implicit_grant_choice = ImplicitTokenGrantDispatcher(
93+
default_grant=self.implicit_grant, oidc_grant=self.openid_connect_implicit
94+
)
7295

7396
# See http://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#Combinations for valid combinations
7497
# internally our AuthorizationEndpoint will ensure they can appear in any order for any valid combination
@@ -88,7 +111,9 @@ def __init__(self, request_validator, token_expires_in=None, token_generator=Non
88111
default_token_type=self.bearer,
89112
)
90113

91-
self.token_grant_choice = AuthorizationTokenGrantDispatcher(request_validator, default_grant=self.auth_grant, oidc_grant=self.openid_connect_auth)
114+
self.token_grant_choice = AuthorizationTokenGrantDispatcher(
115+
request_validator, default_grant=self.auth_grant, oidc_grant=self.openid_connect_auth
116+
)
92117

93118
TokenEndpoint.__init__(
94119
self,
@@ -101,7 +126,9 @@ def __init__(self, request_validator, token_expires_in=None, token_generator=Non
101126
},
102127
default_token_type=self.bearer,
103128
)
104-
ResourceEndpoint.__init__(self, default_token="Bearer", token_types={"Bearer": self.bearer, "JWT": self.jwt})
129+
ResourceEndpoint.__init__(
130+
self, default_token="Bearer", token_types={"Bearer": self.bearer, "JWT": self.jwt}
131+
)
105132
RevocationEndpoint.__init__(self, request_validator)
106133
IntrospectEndpoint.__init__(self, request_validator)
107134
UserInfoEndpoint.__init__(self, request_validator)

tests/oauth2/rfc8628/endpoints/test_error_responses.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def set_client(self, request):
1313
request.client.client_id = "mocked"
1414
return True
1515

16-
def build_request(
17-
self, uri="https://example.com/device_authorize", client_id="foo"
18-
):
16+
def build_request(self, uri="https://example.com/device_authorize", client_id="foo"):
1917
body = ""
2018
if client_id:
2119
body = f"client_id={client_id}"
@@ -46,9 +44,7 @@ def setUp(self):
4644
self.validator = mock.MagicMock(spec=RequestValidator)
4745
self.validator.get_default_redirect_uri.return_value = None
4846
self.validator.get_code_challenge.return_value = None
49-
self.device = DeviceApplicationServer(
50-
self.validator, "https://example.com/verify"
51-
)
47+
self.device = DeviceApplicationServer(self.validator, "https://example.com/verify")
5248

5349
def test_missing_client_id(self):
5450
# Device code grant

tests/oauth2/rfc8628/test_server.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88

99

1010
class DeviceAuthorizationEndpointTest(TestCase):
11-
def _configure_endpoint(self, interval=None, verification_uri_complete=None, user_code_generator=None):
11+
def _configure_endpoint(
12+
self, interval=None, verification_uri_complete=None, user_code_generator=None
13+
):
1214
self.endpoint = DeviceAuthorizationEndpoint(
13-
request_validator=mock.MagicMock(spec=RequestValidator), verification_uri=self.verification_uri, interval=interval, verification_uri_complete=verification_uri_complete, user_code_generator=user_code_generator
15+
request_validator=mock.MagicMock(spec=RequestValidator),
16+
verification_uri=self.verification_uri,
17+
interval=interval,
18+
verification_uri_complete=verification_uri_complete,
19+
user_code_generator=user_code_generator,
1420
)
1521

1622
def setUp(self):
@@ -28,7 +34,9 @@ def response_payload(self):
2834
@mock.patch("oauthlib.oauth2.rfc8628.endpoints.device_authorization.generate_token")
2935
def test_device_authorization_grant(self, generate_token):
3036
generate_token.side_effect = ["abc", "def"]
31-
_, body, status_code = self.endpoint.create_device_authorization_response(*self.response_payload())
37+
_, body, status_code = self.endpoint.create_device_authorization_response(
38+
*self.response_payload()
39+
)
3240
expected_payload = {
3341
"verification_uri": "http://i.b/l/verify",
3442
"user_code": "abc",
@@ -93,7 +101,10 @@ def user_code():
93101
"""
94102
return "123456"
95103

96-
self._configure_endpoint(verification_uri_complete=lambda u: f"http://i.l/v?user_code={u}", user_code_generator=user_code)
104+
self._configure_endpoint(
105+
verification_uri_complete=lambda u: f"http://i.l/v?user_code={u}",
106+
user_code_generator=user_code,
107+
)
97108

98109
_, body, _ = self.endpoint.create_device_authorization_response(*self.response_payload())
99110
self.assertEqual(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy