Skip to content
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

Make pw realm params optional #484

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions auth0/authentication/get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def login(
self,
username,
password,
scope,
realm,
audience,
scope=None,
realm=None,
audience=None,
grant_type="http://auth0.com/oauth/grant-type/password-realm",
):
"""Calls /oauth/token endpoint with password-realm grant type
Expand All @@ -134,18 +134,18 @@ def login(
this information.

Args:
audience (str): The unique identifier of the target API you want to access.

username (str): Resource owner's identifier

password (str): resource owner's Secret

scope(str): String value of the different scopes the client is asking for.
scope(str, optional): String value of the different scopes the client is asking for.
Multiple scopes are separated with whitespace.

realm (str): String value of the realm the user belongs.
realm (str, optional): String value of the realm the user belongs.
Set this if you want to add realm support at this grant.

audience (str, optional): The unique identifier of the target API you want to access.

grant_type (str, optional): Denotes the flow you're using. For password realm
use http://auth0.com/oauth/grant-type/password-realm

Expand Down
26 changes: 26 additions & 0 deletions auth0/test/authentication/test_get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ def test_login(self, mock_post):
},
)

@mock.patch("auth0.rest.RestClient.post")
def test_login_simple(self, mock_post):
g = GetToken("my.domain.com", "cid", client_secret="clsec")

g.login(
username="usrnm",
password="pswd",
)

args, kwargs = mock_post.call_args

self.assertEqual(args[0], "https://my.domain.com/oauth/token")
self.assertEqual(
kwargs["data"],
{
"client_id": "cid",
"client_secret": "clsec",
"username": "usrnm",
"password": "pswd",
"realm": None,
"scope": None,
"audience": None,
"grant_type": "http://auth0.com/oauth/grant-type/password-realm",
},
)

@mock.patch("auth0.rest.RestClient.post")
def test_refresh_token(self, mock_post):
g = GetToken("my.domain.com", "cid", client_secret="clsec")
Expand Down