Skip to content

Commit cb5f36f

Browse files
authored
Merge pull request #360 from AzureAD/prompt-create
A demo on how to use prompt=create
2 parents b07bed6 + 864f9ec commit cb5f36f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

msal/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
ConfidentialClientApplication,
3232
PublicClientApplication,
3333
)
34+
from .oauth2cli.oidc import Prompt
3435
from .token_cache import TokenCache, SerializableTokenCache
3536

msal/oauth2cli/oidc.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ def _nonce_hash(nonce):
8383
return hashlib.sha256(nonce.encode("ascii")).hexdigest()
8484

8585

86+
class Prompt(object):
87+
"""This class defines the constant strings for prompt parameter.
88+
89+
The values are based on
90+
https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
91+
"""
92+
NONE = "none"
93+
LOGIN = "login"
94+
CONSENT = "consent"
95+
SELECT_ACCOUNT = "select_account"
96+
CREATE = "create" # Defined in https://openid.net/specs/openid-connect-prompt-create-1_0.html#PromptParameter
97+
98+
8699
class Client(oauth2.Client):
87100
"""OpenID Connect is a layer on top of the OAuth2.
88101
@@ -217,6 +230,8 @@ def obtain_token_by_browser(
217230
`OIDC <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_.
218231
:param string prompt: Defined in
219232
`OIDC <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_.
233+
You can find the valid string values defined in :class:`oidc.Prompt`.
234+
220235
:param int max_age: Defined in
221236
`OIDC <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_.
222237
:param string ui_locales: Defined in
@@ -232,7 +247,7 @@ def obtain_token_by_browser(
232247
for descriptions on other parameters and return value.
233248
"""
234249
filtered_params = {k:v for k, v in dict(
235-
prompt=prompt,
250+
prompt=" ".join(prompt) if isinstance(prompt, (list, tuple)) else prompt,
236251
display=display,
237252
max_age=max_age,
238253
ui_locales=ui_locales,

sample/interactive_sample.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
# after already extracting the username from an earlier sign-in
6363
# by using the preferred_username claim from returned id_token_claims.
6464

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

6870
if "access_token" in result:

0 commit comments

Comments
 (0)