Skip to content

Commit ad30577

Browse files
[IMP]auth_oidc: verify self-signed certificates
If the connection between odoo and an oauth provider uses self-signed certificates, a ssl error is thrown because the self-signed certificated cannot be verified.
1 parent 5afea9a commit ad30577

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

auth_oidc/models/auth_oauth_provider.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,21 @@ 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+
self_signed = fields.Boolean(
50+
string="Self-signed", help="Defines if the used certificate is self-signed."
51+
)
52+
self_signed_verify = fields.Char(
53+
string="Self-signed verify path",
54+
help="Path to the self-signed certificate for the verification process."
55+
"Empty value disables the verification.",
56+
)
4957

5058
@tools.ormcache("self.jwks_uri", "kid")
5159
def _get_keys(self, kid):
52-
r = requests.get(self.jwks_uri, timeout=10)
60+
verify = True
61+
if self.self_signed:
62+
verify = self.self_signed_verify or False
63+
r = requests.get(self.jwks_uri, timeout=10, verify=verify)
5364
r.raise_for_status()
5465
response = r.json()
5566
# the keys returned here should follow

auth_oidc/models/res_users.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def _auth_oauth_get_tokens_auth_code_flow(self, oauth_provider, params):
2727
auth = None
2828
if oauth_provider.client_secret:
2929
auth = (oauth_provider.client_id, oauth_provider.client_secret)
30+
verify = True
31+
if oauth_provider.self_signed:
32+
verify = oauth_provider.self_signed_verify or False
3033
response = requests.post(
3134
oauth_provider.token_endpoint,
3235
data=dict(
@@ -38,6 +41,7 @@ def _auth_oauth_get_tokens_auth_code_flow(self, oauth_provider, params):
3841
),
3942
auth=auth,
4043
timeout=10,
44+
verify=verify,
4145
)
4246
response.raise_for_status()
4347
response_json = response.json()

auth_oidc/views/auth_oauth_provider.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<field name="token_endpoint" />
2020
<field name="jwks_uri" />
2121
</field>
22+
<field name="data_endpoint" position="after">
23+
<field name="self_signed" />
24+
<field name="self_signed_verify" invisible="not self_signed" />
25+
</field>
2226
</field>
2327
</record>
2428
</odoo>

0 commit comments

Comments
 (0)