Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #28 from lalithkota/17.0-develop
Browse files Browse the repository at this point in the history
Reg ID Auth: Removed confirmation page. And added auth response page
  • Loading branch information
shibu-narayanan authored Aug 14, 2024
2 parents 446c9db + a27f0ee commit 13485d8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ docs/_build/

# OCA rules
!static/lib/

# Pandoc
pandoc*.deb
20 changes: 6 additions & 14 deletions g2p_auth_id_oidc/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@


class RegIdOidcController(http.Controller):
@http.route("/auth_oauth/g2p_registry_id/confirm", type="http", auth="user")
@fragment_to_query_string
def g2p_reg_id_confirm(self, **kw):
return request.render("g2p_auth_id_oidc.g2p_reg_id_confirm", kw)

@http.route("/auth_oauth/g2p_registry_id/authenticate", type="http", auth="user")
@fragment_to_query_string
def g2p_reg_id_authenticate(self, **kw):
Expand All @@ -45,19 +40,16 @@ def g2p_reg_id_authenticate(self, **kw):
# TODO: Support Oauth2 flow also.
raise BadRequest("Oauth2 Provider not supported!")

oauth_provider.oidc_get_tokens(
kw, oidc_redirect_uri=request.httprequest.base_url.replace("authenticate", "confirm")
)
oauth_provider.oidc_get_tokens(kw)
reg_id.authentication_status = "authenticated"
reg_id.last_authentication_time = datetime.now()
reg_id.last_authentication_user_id = request.env.user.id
if kw.get("confirm_update", False):
validation = oauth_provider.oidc_get_validation_dict(kw)
oauth_provider.oidc_signin_generate_user_values(
validation, kw, oauth_partner=reg_id.partner_id, oauth_user=None, create_user=False
)
reg_id.partner_id.write(validation)
validation = oauth_provider.oidc_get_validation_dict(kw)
oauth_provider.oidc_signin_generate_user_values(
validation, kw, oauth_partner=reg_id.partner_id, oauth_user=None, create_user=False
)
response_values["authentication_status"] = True
response_values["validation"] = validation
except Exception:
_logger.exception("Encountered error while authenticating Reg Id.")
response_values["error_exception"] = traceback.format_exc()
Expand Down
2 changes: 1 addition & 1 deletion g2p_auth_id_oidc/models/g2p_reg_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_auth_oauth_provider(self, reg_id_id):
.sudo()
.list_providers(
domain=[("id", "=", reg_id.auth_oauth_provider_id.id)],
oidc_redirect_uri="/auth_oauth/g2p_registry_id/confirm",
oidc_redirect_uri="/auth_oauth/g2p_registry_id/authenticate",
reg_id=reg_id.id,
)[0]
)
Expand Down
43 changes: 9 additions & 34 deletions g2p_auth_id_oidc/views/templates.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="g2p_reg_id_confirm" name="Confirm">
<t t-call="web.layout">
<t t-set="title">Confirm</t>
<t t-set="head">
<script type="text/javascript">
function redirectToAuthenticate(urlParams){
if(!urlParams){
urlParams = new URLSearchParams(location.search);
}
location = `${location.origin}/auth_oauth/g2p_registry_id/authenticate?${urlParams}`
}
function authenticateWithUpdate(){
let urlParams = new URLSearchParams(location.search);
urlParams.set("confirm_update", true);
return redirectToAuthenticate(urlParams);
}
</script>
</t>
<div class="card" id="auth_response">
<h1>Do you want to override registry data with data from ID Provider?</h1>
<p />
<button onclick="authenticateWithUpdate()">Yes</button>
<button onclick="redirectToAuthenticate()">No</button>
</div>
</t>
</template>
<template id="g2p_reg_id_authenticate" name="Authenticate">
<t t-call="web.layout">
<t t-set="title">Authenticate</t>
<t t-if="authentication_status">
<script>window.close()</script>
</t>
<t t-else="">
<div class="card" id="auth_response">
<div class="card" id="auth_response">
<t t-if="authentication_status">
<h2>Authentication Success</h2>
<p>Authentication Response: <t t-out="validation" /></p>
</t>
<t t-else="">
<p>Encountered error while authenticating Reg Id.</p>
<t t-if="debug">
<p><t t-out="error_exception" /></p>
</t>
<button onclick="window.close()">Ok</button>
</div>
</t>
</t>
</div>
<button onclick="window.close()">Ok</button>
</t>
</template>
</odoo>

0 comments on commit 13485d8

Please sign in to comment.