Skip to content

Device flow: Pass verification_uri_complete to endpoint + pass Server kwargs to DeviceCodeGrant to allow validators to be setup with more flexibility #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion oauthlib/oauth2/rfc6749/endpoints/pre_configured.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
self.password_grant = ResourceOwnerPasswordCredentialsGrant(request_validator)
self.credentials_grant = ClientCredentialsGrant(request_validator)
self.refresh_grant = RefreshTokenGrant(request_validator)
self.device_code_grant = DeviceCodeGrant(request_validator)
self.device_code_grant = DeviceCodeGrant(request_validator, **kwargs)

self.bearer = BearerToken(
request_validator, token_generator, token_expires_in, refresh_token_generator
Expand Down
6 changes: 3 additions & 3 deletions oauthlib/oauth2/rfc8628/clients/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def prepare_request_uri(self, uri, scope=None, **kwargs):
if scope:
params.append(('scope', list_to_scope(scope)))

for k in kwargs:
if kwargs[k]:
params.append((str(k), kwargs[k]))
for k,v in kwargs.items():
if v:
params.append((str(k), v))

return add_params_to_uri(uri, params)

Expand Down
5 changes: 4 additions & 1 deletion oauthlib/oauth2/rfc8628/endpoints/pre_configured.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from oauthlib.oauth2.rfc8628.endpoints.device_authorization import (
DeviceAuthorizationEndpoint,
)
from typing import Callable

from typing import Callable, Optional
from oauthlib.openid.connect.core.request_validator import RequestValidator


Expand All @@ -13,6 +14,7 @@ def __init__(
request_validator: RequestValidator,
verification_uri: str,
interval: int = 5,
verification_uri_complete: Optional[str] = None, # noqa: FA100
user_code_generator: Callable[[None], str] = None,
**kwargs,
):
Expand All @@ -30,4 +32,5 @@ def __init__(
interval=interval,
verification_uri=verification_uri,
user_code_generator=user_code_generator,
verification_uri_complete=verification_uri_complete,
)
2 changes: 1 addition & 1 deletion oauthlib/oauth2/rfc8628/grant_types/device_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Callable

from oauthlib import common # noqa: TCH001
from oauthlib import common # noqa: TC001

from oauthlib.oauth2.rfc6749 import errors as rfc6749_errors
from oauthlib.oauth2.rfc6749.grant_types.base import GrantTypeBase
Expand Down
2 changes: 1 addition & 1 deletion oauthlib/openid/connect/core/endpoints/pre_configured.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(
self.openid_connect_auth = AuthorizationCodeGrant(request_validator)
self.openid_connect_implicit = ImplicitGrant(request_validator)
self.openid_connect_hybrid = HybridGrant(request_validator)
self.device_code_grant = DeviceCodeGrant(request_validator)
self.device_code_grant = DeviceCodeGrant(request_validator, **kwargs)

self.bearer = BearerToken(
request_validator, token_generator, token_expires_in, refresh_token_generator
Expand Down
6 changes: 6 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ max-complexity = 24 # default is 10
"oauthlib/oauth2/rfc6749/endpoints/base.py" = ["BLE001"]
"oauthlib/openid/connect/core/grant_types/base.py" = ["BLE001"]
"tests/*" = ["PT009", "PT027", "S101"]
"oauthlib/oauth1/rfc5849/endpoints/resource.py" = ["A005"]
"oauthlib/oauth2/rfc6749/endpoints/resource.py" = ["A005"]
"oauthlib/oauth2/rfc6749/endpoints/token.py" = ["A005"]
"oauthlib/oauth2/rfc6749/parameters.py" = ["PLC0206"]
"oauthlib/oauth2/rfc6749/tokens.py" = ["RUF023"]
"oauthlib/openid/connect/core/tokens.py" = ["RUF023"]

# [tool.ruff.pylint]
[pylint]
Expand Down
26 changes: 26 additions & 0 deletions tests/oauth2/rfc8628/endpoints/test_device_application_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
from unittest import TestCase, mock

from oauthlib.common import Request, urlencode
from oauthlib.oauth2.rfc6749 import errors
from oauthlib.oauth2.rfc8628.endpoints.pre_configured import DeviceApplicationServer
from oauthlib.oauth2.rfc8628.request_validator import RequestValidator


def test_server_set_up_device_endpoint_instance_attributes_correctly():
"""
Simple test that just instantiates DeviceApplicationServer
and asserts the important attributes are present
"""
validator = mock.MagicMock(spec=RequestValidator)
validator.get_default_redirect_uri.return_value = None
validator.get_code_challenge.return_value = None

verification_uri = "test.com/device"
verification_uri_complete = "test.com/device?user_code=123"
device = DeviceApplicationServer(validator, verification_uri=verification_uri, verification_uri_complete=verification_uri_complete)
device_vars = vars(device)
assert device_vars["_verification_uri_complete"] == "test.com/device?user_code=123"
assert device_vars["_verification_uri"] == "test.com/device"
assert device_vars["_expires_in"] == 1800
assert device_vars["_interval"] == 5
Loading
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