-
Notifications
You must be signed in to change notification settings - Fork 174
Adding Support For Back Channel Login #643
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import Any | ||
|
||
from .base import AuthenticationBase | ||
|
||
|
||
class BackChannelLogin(AuthenticationBase): | ||
"""Back-Channel Login endpoint""" | ||
|
||
def back_channel_login( | ||
self, binding_message: str, login_hint: str, scope: str, **kwargs | ||
) -> Any: | ||
"""Send a Back-Channel Login. | ||
|
||
Args: | ||
binding_message (str): Human-readable string displayed on both the device calling /bc-authorize and the user’s | ||
authentication device to ensure the user is approves the correct request. | ||
|
||
login_hint (str): String containing information about the user to contact for authentication. | ||
|
||
scope(str): "openid" is a required scope.Multiple scopes are separated | ||
with whitespace. | ||
|
||
**kwargs: Other fields to send along with the PAR. | ||
|
||
Returns: | ||
auth_req_id, expires_in, interval | ||
""" | ||
return self.authenticated_post( | ||
f"{self.protocol}://{self.domain}/bc-authorize", | ||
data={ | ||
"client_id": self.client_id, | ||
"binding_message": binding_message, | ||
"login_hint": login_hint, | ||
"scope": scope, | ||
**kwargs, | ||
}, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
import unittest | ||
from unittest import mock | ||
|
||
import requests | ||
|
||
from ...exceptions import Auth0Error, RateLimitError | ||
|
||
|
||
from ...authentication.back_channel_login import BackChannelLogin | ||
|
||
class TestBackChannelLogin(unittest.TestCase): | ||
@mock.patch("auth0.rest.RestClient.post") | ||
def test_ciba(self, mock_post): | ||
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec") | ||
|
||
g.back_channel_login( | ||
binding_message="This is a binding message", | ||
login_hint="{ \"format\": \"iss_sub\", \"iss\": \"https://my.domain.auth0.com/\", \"sub\": \"auth0|[USER ID]\" }", | ||
scope="openid", | ||
) | ||
|
||
args, kwargs = mock_post.call_args | ||
|
||
self.assertEqual(args[0], "https://my.domain.com/bc-authorize") | ||
self.assertEqual( | ||
kwargs["data"], | ||
{ | ||
"client_id": "cid", | ||
"client_secret": "clsec", | ||
"binding_message": "This is a binding message", | ||
"login_hint": "{ \"format\": \"iss_sub\", \"iss\": \"https://my.domain.auth0.com/\", \"sub\": \"auth0|[USER ID]\" }", | ||
"scope": "openid", | ||
}, | ||
) | ||
|
||
@mock.patch("auth0.rest.RestClient.post") | ||
def test_should_require_binding_message(self, mock_post): | ||
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec") | ||
|
||
# Expecting an exception to be raised when binding_message is missing | ||
with self.assertRaises(Exception) as context: | ||
g.back_channel_login( | ||
login_hint='{ "format": "iss_sub", "iss": "https://my.domain.auth0.com/", "sub": "auth0|USER_ID" }', | ||
scope="openid", | ||
) | ||
|
||
|
||
# Assert the error message is correct | ||
self.assertIn("missing 1 required positional argument: \'binding_message\'", str(context.exception)) | ||
|
||
@mock.patch("auth0.rest.RestClient.post") | ||
def test_should_require_login_hint(self, mock_post): | ||
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec") | ||
|
||
# Expecting an exception to be raised when login_hint is missing | ||
with self.assertRaises(Exception) as context: | ||
g.back_channel_login( | ||
binding_message="This is a binding message.", | ||
scope="openid", | ||
) | ||
|
||
|
||
# Assert the error message is correct | ||
self.assertIn("missing 1 required positional argument: \'login_hint\'", str(context.exception)) | ||
|
||
@mock.patch("auth0.rest.RestClient.post") | ||
def test_should_require_scope(self, mock_post): | ||
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec") | ||
|
||
# Expecting an exception to be raised when scope is missing | ||
with self.assertRaises(Exception) as context: | ||
g.back_channel_login( | ||
binding_message="This is a binding message.", | ||
login_hint='{ "format": "iss_sub", "iss": "https://my.domain.auth0.com/", "sub": "auth0|USER_ID" }', | ||
) | ||
|
||
|
||
# Assert the error message is correct | ||
self.assertIn("missing 1 required positional argument: \'scope\'", str(context.exception)) | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.