Skip to content

Commit 937a7fe

Browse files
committed
Prompt parameter customizable and default to None
1 parent 4834221 commit 937a7fe

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

docs/abc.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ It is an abstract base class. You cannot use it directly.
1111

1212
.. autoclass:: identity.pallet.PalletAuth
1313
:members:
14+
:inherited-members:
15+
16+
.. automethod:: __init__
1417

identity/django.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(
3838
self,
3939
*args,
4040
post_logout_view: Optional[callable] = None,
41+
prompt: Optional[str] = None,
4142
**kwargs,
4243
):
4344
"""Initialize the Auth class for a Django web application.
@@ -57,7 +58,13 @@ def __init__(
5758
)
5859
5960
where ``my_post_logout_view`` is a Django view function.
61+
62+
:param str prompt:
63+
Optional. The prompt parameter to be used during login.
64+
Valid values are defined in
65+
`OpenID Connect Core spec <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_
6066
"""
67+
self._prompt = prompt
6168
super(Auth, self).__init__(*args, **kwargs)
6269
route, redirect_view = _parse_redirect_uri(self._redirect_uri)
6370
self.urlpattern = path(route, include([
@@ -90,7 +97,7 @@ def login(
9097
log_in_result = self._build_auth(request.session).log_in(
9198
scopes=scopes, # Have user consent to scopes (if any) during log-in
9299
redirect_uri=self._redirect_uri, # Optional. If present, this absolute URL must match your app's redirect_uri registered in Azure Portal
93-
prompt="select_account", # Optional. More values defined in https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
100+
prompt=self._prompt, # Optional. More values defined in https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
94101
next_link=next_link,
95102
)
96103
if "error" in log_in_result:
@@ -209,4 +216,3 @@ def wrapper(request, *args, **kwargs):
209216
scopes=scopes,
210217
)
211218
return wrapper
212-

identity/flask.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def build_app():
6969
If provided, it shall be the view (which is a function)
7070
that will be redirected to, after the user has logged out.
7171
72-
It also passes extra parameters to :class:`identity.web.WebFrameworkAuth`.
72+
It also passes extra parameters to :class:`identity.pallet.PalletAuth`.
7373
"""
7474
self._request = request # Not available during class definition
7575
self._session = session # Not available during class definition
@@ -100,7 +100,7 @@ def login(
100100
log_in_result: dict = self._auth.log_in(
101101
scopes=scopes, # Have user consent to scopes (if any) during log-in
102102
redirect_uri=self._redirect_uri,
103-
prompt="select_account", # Optional. More values defined in https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
103+
prompt=self._prompt, # self._prompt was defined in parent class
104104
next_link=next_link,
105105
)
106106
if "error" in log_in_result:
@@ -166,4 +166,3 @@ def call_an_api(*, context):
166166
...
167167
"""
168168
return super(Auth, self).login_required(function, scopes=scopes)
169-

identity/pallet.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,28 @@
1111
logger = logging.getLogger(__name__)
1212

1313

14-
class PalletAuth(WebFrameworkAuth): # A common base class for Flask and Quart
14+
class PalletAuth(WebFrameworkAuth):
15+
"""A common base class for Flask and Quart web authentication.
16+
17+
Provides shared functionality for login handling, session management, and routing
18+
used by both Flask and Quart framework implementations.
19+
"""
1520
_endpoint_prefix = "identity" # A convention to match the template's folder name
1621
_auth: Optional[Auth] = None # None means not initialized yet
1722

18-
def __init__(self, app, *args, **kwargs):
23+
def __init__(self, app, *args, prompt: Optional[str] = None, **kwargs):
24+
"""Initialize the Auth class for a Pallet-based web application.
25+
26+
:param app:
27+
The Flask or Quart application instance, or ``None``.
28+
If None, you must call init_app() later. This pattern can be useful
29+
when your project does not use a global app object, such as when using
30+
the application factory pattern.
31+
:param str prompt:
32+
Optional. The prompt parameter to be used during login.
33+
Valid values are defined in
34+
`OpenID Connect Core spec <https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_
35+
"""
1936
if not (
2037
self._Blueprint and self._Session and self._redirect
2138
and getattr(self, "_session", None) is not None
@@ -24,6 +41,7 @@ def __init__(self, app, *args, **kwargs):
2441
raise RuntimeError(
2542
"Subclass must provide "
2643
"_Blueprint, _Session, _redirect, _session, and _request.")
44+
self._prompt = prompt
2745
super(PalletAuth, self).__init__(*args, **kwargs)
2846
self._bp = bp = self._Blueprint(
2947
self._endpoint_prefix,
@@ -106,4 +124,3 @@ def wrapper(*args, **kwargs):
106124
# Save an http 302 by calling self.login(request) instead of redirect(self.login)
107125
return self.login(next_link=self._request.url, scopes=scopes)
108126
return wrapper
109-

identity/quart.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def build_app():
6969
If provided, it shall be the view (which is a function)
7070
that will be redirected to, after the user has logged out.
7171
72-
It also passes extra parameters to :class:`identity.web.WebFrameworkAuth`.
72+
It also passes extra parameters to :class:`identity.pallet.PalletAuth`.
7373
"""
7474
self._request = request # Not available during class definition
7575
self._session = session # Not available during class definition
@@ -98,7 +98,7 @@ async def login(
9898
log_in_result = self._auth.log_in(
9999
scopes=scopes, # Have user consent to scopes (if any) during log-in
100100
redirect_uri=self._redirect_uri,
101-
prompt="select_account", # Optional. More values defined in https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
101+
prompt=self._prompt, # self._prompt was defined in parent class
102102
next_link=next_link,
103103
)
104104
if "error" in log_in_result:
@@ -165,4 +165,3 @@ async def call_api(*, context):
165165
166166
"""
167167
return super(Auth, self).login_required(function, scopes=scopes)
168-

0 commit comments

Comments
 (0)