Skip to content

Commit 36e841d

Browse files
committed
Add support to more paramenters of OpenID Connect
1 parent e5b698e commit 36e841d

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

social_core/backends/open_id_connect.py

+51-10
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ class OpenIdConnectAuth(BaseOAuth2):
6565
JWKS_URI = ""
6666
TOKEN_ENDPOINT_AUTH_METHOD = ""
6767
# Optional parameters for Authentication Request
68-
PROMPT = ""
68+
DISPLAY = None
69+
PROMPT = None
70+
MAX_AGE = None
71+
UI_LOCALES = None
72+
ID_TOKEN_HINT = None
73+
LOGIN_HINT = None
74+
ACR_VALUES = None
6975

7076
def __init__(self, *args, **kwargs):
7177
self.id_token = None
@@ -134,17 +140,52 @@ def auth_params(self, state=None):
134140
params = super().auth_params(state)
135141
params["nonce"] = self.get_and_store_nonce(self.authorization_url(), state)
136142

137-
prompt = self.setting(
138-
"PROMPT", default=self.PROMPT
139-
)
140-
is_prompt_valid = True
141-
for prompt_token in prompt.split():
142-
if prompt_token not in ("none", "login", "consent", "select_account"):
143-
is_prompt_valid = False
144-
break
145-
if is_prompt_valid:
143+
display = self.setting("DISPLAY", default=self.DISPLAY)
144+
if display is not None:
145+
if not display:
146+
raise ValueError("OpenID Connect display value cannot be empty string.")
147+
148+
if display not in ("page", "popup", "touch", "wap"):
149+
raise ValueError(f"Invalid OpenID Connect display value: {display}")
150+
151+
params["display"] = display
152+
153+
prompt = self.setting("PROMPT", default=self.PROMPT)
154+
if prompt is not None:
155+
if not prompt:
156+
raise ValueError("OpenID Connect prompt value cannot be empty string.")
157+
158+
for prompt_token in prompt.split():
159+
if prompt_token not in ("none", "login", "consent", "select_account"):
160+
raise ValueError(
161+
f"Invalid OpenID Connect prompt value: {prompt_token}"
162+
)
163+
146164
params["prompt"] = prompt
147165

166+
max_age = self.setting("MAX_AGE", default=self.MAX_AGE)
167+
if max_age is not None:
168+
if max_age < 0:
169+
raise ValueError("OpenID Connect max_age cannot be negative.")
170+
171+
params["max_age"] = max_age
172+
173+
ui_locales = self.setting("UI_LOCALES", default=self.UI_LOCALES)
174+
if ui_locales is not None:
175+
raise ValueError("OpenID Connect ui_locales is not implemented.")
176+
177+
id_token_hint = self.setting("ID_TOKEN_HINT", default=self.ID_TOKEN_HINT)
178+
if id_token_hint is not None:
179+
raise ValueError("OpenID Connect id_token_hint is not implemented.")
180+
181+
login_hint = self.setting("LOGIN_HINT", default=self.LOGIN_HINT)
182+
if login_hint is not None:
183+
raise ValueError("OpenID Connect login_hint is not implemented.")
184+
185+
acr_values = self.setting("ACR_VALUES", default=self.ACR_VALUES)
186+
if acr_values is not None:
187+
raise ValueError("OpenID Connect acr_values is not implemented.")
188+
148189
return params
149190

150191
def get_and_store_nonce(self, url, state):

0 commit comments

Comments
 (0)