Skip to content

Commit 93a97b8

Browse files
committed
Merge PR #706 into 17.0
Signed-off-by sbidoul
2 parents ba7dc4a + cf071ce commit 93a97b8

File tree

10 files changed

+67
-7
lines changed

10 files changed

+67
-7
lines changed

auth_oidc/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ or
9090

9191
|image2|
9292

93+
- Auth Link Params: Add {'prompt':'select_account'} to the auth link to
94+
get the account selection screen |image3|
95+
9396
Setup for Keycloak
9497
------------------
9598

@@ -126,6 +129,7 @@ In Odoo, create a new Oauth Provider with the following parameters:
126129
.. |image| image:: https://raw.githubusercontent.com/OCA/server-auth/17.0/auth_oidc/static/description/oauth-microsoft_azure-api_permissions.png
127130
.. |image1| image:: https://raw.githubusercontent.com/OCA/server-auth/17.0/auth_oidc/static/description/oauth-microsoft_azure-optional_claims.png
128131
.. |image2| image:: https://raw.githubusercontent.com/OCA/server-auth/17.0/auth_oidc/static/description/odoo-azure_ad_multitenant.png
132+
.. |image3| image:: https://raw.githubusercontent.com/OCA/server-auth/17.0/auth_oidc/static/description/oauth-microsoft_azure-select_account.png
129133

130134
Usage
131135
=====

auth_oidc/controllers/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import hashlib
77
import logging
88
import secrets
9+
from ast import literal_eval
910

1011
from werkzeug.urls import url_decode, url_encode
1112

@@ -43,6 +44,12 @@ def list_providers(self):
4344
if "openid" not in provider["scope"].split():
4445
_logger.error("openid connect scope must contain 'openid'")
4546
params["scope"] = provider["scope"]
47+
48+
# append provider specific auth link params
49+
if provider["auth_link_params"]:
50+
params_upd = literal_eval(provider["auth_link_params"])
51+
params.update(params_upd)
52+
4653
# auth link that the user will click
4754
provider["auth_link"] = "{}?{}".format(
4855
provider["auth_endpoint"], url_encode(params)

auth_oidc/data/auth_oauth_data.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
>https://login.microsoftonline.com/organizations/discovery/v2.0/keys</field>
1818
<field name="css_class">fa fa-fw fa-windows</field>
1919
<field name="body">Log in with Microsoft</field>
20+
<field name="auth_link_params">{'prompt':'select_account'}</field>
2021
</record>
2122
<record id="provider_azuread_single" model="auth.oauth.provider">
2223
<field name="name">Azure AD Single Tenant</field>
@@ -35,5 +36,6 @@
3536
>https://login.microsoftonline.com/{tenant_id}/discovery/v2.0/keys</field>
3637
<field name="css_class">fa fa-fw fa-windows</field>
3738
<field name="body">Log in with Microsoft</field>
39+
<field name="auth_link_params">{'prompt':'select_account'}</field>
3840
</record>
3941
</odoo>

auth_oidc/demo/local_keycloak.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,24 @@
1717
name="jwks_uri"
1818
>http://localhost:8080/auth/realms/master/protocol/openid-connect/certs</field>
1919
</record>
20+
<record id="provider_azuread_multi" model="auth.oauth.provider">
21+
<field name="name">Azure AD Multitenant</field>
22+
<field name="flow">id_token_code</field>
23+
<field name="client_id">auth_oidc-test</field>
24+
<field name="enabled">True</field>
25+
<field name="token_map">upn:user_id upn:email</field>
26+
<field
27+
name="auth_endpoint"
28+
>https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize</field>
29+
<field name="scope">profile openid</field>
30+
<field
31+
name="token_endpoint"
32+
>https://login.microsoftonline.com/organizations/oauth2/v2.0/token</field>
33+
<field
34+
name="jwks_uri"
35+
>https://login.microsoftonline.com/organizations/discovery/v2.0/keys</field>
36+
<field name="css_class">fa fa-fw fa-windows</field>
37+
<field name="body">Log in with Microsoft</field>
38+
<field name="auth_link_params">{'prompt':'select_account'}</field>
39+
</record>
2040
</odoo>

auth_oidc/models/auth_oauth_provider.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class AuthOauthProvider(models.Model):
4646
string="Token URL", help="Required for OpenID Connect authorization code flow."
4747
)
4848
jwks_uri = fields.Char(string="JWKS URL", help="Required for OpenID Connect.")
49+
auth_link_params = fields.Char(
50+
help="Additional parameters for the auth link. "
51+
"For example: {'prompt':'select_account'}"
52+
)
4953

5054
@tools.ormcache("self.jwks_uri", "kid")
5155
def _get_keys(self, kid):

auth_oidc/readme/CONFIGURE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ or
3838

3939
![image](../static/description/odoo-azure_ad_multitenant.png)
4040

41+
- Auth Link Params: Add {'prompt':'select_account'} to the auth link to get the account selection screen
42+
![image](../static/description/oauth-microsoft_azure-select_account.png)
43+
44+
4145
## Setup for Keycloak
4246

4347
Example configuration with OpenID Connect authorization code flow.

auth_oidc/static/description/index.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -448,6 +449,10 @@ <h2><a class="toc-backref" href="#toc-entry-3">Setup for Microsoft Azure</a></h2
448449
<li>replace {tenant_id} in urls with your Azure tenant id</li>
449450
</ul>
450451
<p><img alt="image2" src="https://raw.githubusercontent.com/OCA/server-auth/17.0/auth_oidc/static/description/odoo-azure_ad_multitenant.png" /></p>
452+
<ul class="simple">
453+
<li>Auth Link Params: Add {‘prompt’:’select_account’} to the auth link to
454+
get the account selection screen <img alt="image3" src="https://raw.githubusercontent.com/OCA/server-auth/17.0/auth_oidc/static/description/oauth-microsoft_azure-select_account.png" /></li>
455+
</ul>
451456
</div>
452457
<div class="section" id="setup-for-keycloak">
453458
<h2><a class="toc-backref" href="#toc-entry-4">Setup for Keycloak</a></h2>
@@ -582,7 +587,9 @@ <h2><a class="toc-backref" href="#toc-entry-20">Contributors</a></h2>
582587
<div class="section" id="maintainers">
583588
<h2><a class="toc-backref" href="#toc-entry-21">Maintainers</a></h2>
584589
<p>This module is maintained by the OCA.</p>
585-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
590+
<a class="reference external image-reference" href="https://odoo-community.org">
591+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
592+
</a>
586593
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
587594
mission is to support the collaborative development of Odoo features and
588595
promote its widespread use.</p>
21.6 KB
Loading

auth_oidc/tests/test_auth_oidc_auth_code.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def setUp(self):
7171
super().setUp()
7272
# search our test provider and bind the demo user to it
7373
self.provider_rec = self.env["auth.oauth.provider"].search(
74-
[("client_id", "=", "auth_oidc-test")]
74+
[("name", "=", "keycloak:8080 on localhost")]
7575
)
7676
self.assertEqual(len(self.provider_rec), 1)
7777

@@ -83,8 +83,10 @@ def test_auth_link(self):
8383
).write(dict(enabled=False))
8484
with MockRequest(self.env):
8585
providers = OpenIDLogin().list_providers()
86-
self.assertEqual(len(providers), 1)
87-
auth_link = providers[0]["auth_link"]
86+
self.assertEqual(len(providers), 2)
87+
auth_link = list(
88+
filter(lambda p: p["name"] == "keycloak:8080 on localhost", providers)
89+
)[0]["auth_link"]
8890
assert auth_link.startswith(self.provider_rec.auth_endpoint)
8991
params = parse_qs(urlparse(auth_link).query)
9092
self.assertEqual(params["response_type"], ["code"])
@@ -95,6 +97,13 @@ def test_auth_link(self):
9597
self.assertTrue(params["nonce"])
9698
self.assertTrue(params["state"])
9799
self.assertEqual(params["redirect_uri"], [BASE_URL + "/auth_oauth/signin"])
100+
self.assertFalse("prompt" in params)
101+
102+
auth_link_ms = list(
103+
filter(lambda p: p["name"] == "Azure AD Multitenant", providers)
104+
)[0]["auth_link"]
105+
params = parse_qs(urlparse(auth_link_ms).query)
106+
self.assertEqual(params["prompt"], ["select_account"])
98107

99108
def _prepare_login_test_user(self):
100109
user = self.env.ref("base.user_demo")

auth_oidc/views/auth_oauth_provider.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<field name="token_endpoint" />
2020
<field name="jwks_uri" />
2121
</field>
22+
<field name="auth_endpoint" position="after">
23+
<field name="auth_link_params" />
24+
</field>
2225
</field>
2326
</record>
2427
</odoo>

0 commit comments

Comments
 (0)