Skip to content

A demo on how to use prompt=create #360

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
May 14, 2021
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
1 change: 1 addition & 0 deletions msal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
ConfidentialClientApplication,
PublicClientApplication,
)
from .oauth2cli.oidc import Prompt
from .token_cache import TokenCache, SerializableTokenCache

17 changes: 16 additions & 1 deletion msal/oauth2cli/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def _nonce_hash(nonce):
return hashlib.sha256(nonce.encode("ascii")).hexdigest()


class Prompt(object):
"""This class defines the constant strings for prompt parameter.

The values are based on
https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
"""
NONE = "none"
LOGIN = "login"
CONSENT = "consent"
SELECT_ACCOUNT = "select_account"
CREATE = "create" # Defined in https://openid.net/specs/openid-connect-prompt-create-1_0.html#PromptParameter


class Client(oauth2.Client):
"""OpenID Connect is a layer on top of the OAuth2.

Expand Down Expand Up @@ -217,6 +230,8 @@ def obtain_token_by_browser(
`OIDC <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_.
:param string prompt: Defined in
`OIDC <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_.
You can find the valid string values defined in :class:`oidc.Prompt`.

:param int max_age: Defined in
`OIDC <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_.
:param string ui_locales: Defined in
Expand All @@ -232,7 +247,7 @@ def obtain_token_by_browser(
for descriptions on other parameters and return value.
"""
filtered_params = {k:v for k, v in dict(
prompt=prompt,
prompt=" ".join(prompt) if isinstance(prompt, (list, tuple)) else prompt,
display=display,
max_age=max_age,
ui_locales=ui_locales,
Expand Down
4 changes: 3 additions & 1 deletion sample/interactive_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
# after already extracting the username from an earlier sign-in
# by using the preferred_username claim from returned id_token_claims.

#prompt="select_account", # Optional. It forces to show account selector page
#prompt=msal.Prompt.SELECT_ACCOUNT, # Or simply "select_account". Optional. It forces to show account selector page
#prompt=msal.Prompt.CREATE, # Or simply "create". Optional. It brings user to a self-service sign-up flow.
# Prerequisite: https://docs.microsoft.com/en-us/azure/active-directory/external-identities/self-service-sign-up-user-flow
)

if "access_token" in result:
Expand Down