Skip to content

Commit 809c82b

Browse files
[MIG] auth_jwt_demo: Migration to 19.0
1 parent 5393018 commit 809c82b

4 files changed

Lines changed: 91 additions & 83 deletions

File tree

auth_jwt_demo/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Auth JWT Test",
66
"summary": """
77
Test/demo module for auth_jwt.""",
8-
"version": "18.0.1.0.0",
8+
"version": "19.0.1.0.0",
99
"license": "LGPL-3",
1010
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1111
"maintainers": ["sbidoul"],

auth_jwt_demo/tests/spa/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ <h2>SPA OIDC Authentication Sample</h2>
1313
<button id="btn-whoami">Who am I? (api call)</button>
1414
<button id="btn-whoami-public-or-jwt">Who am I (public or auth)? (api call)</button>
1515
<script type="module">
16-
import {onload, login, logout, whoami, whoami_public_or_jwt} from "./js/app.js";
16+
import {
17+
onload,
18+
login,
19+
logout,
20+
whoami,
21+
whoami_public_or_jwt,
22+
} from "./js/app.esm.js";
1723

1824
window.onload = onload;
1925
document.getElementById("btn-login").onclick = login;
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Oidc} from "./oidc-client.js";
1+
import {Oidc} from "./oidc-client.esm.js";
22

33
let client = null;
44

@@ -29,6 +29,27 @@ class InMemoryWebStorageStateStore {
2929
}
3030
}
3131

32+
async function updateUI() {
33+
const user = await client.getUser();
34+
const isAuthenticated = Boolean(user);
35+
36+
document.getElementById("btn-login").disabled = isAuthenticated;
37+
document.getElementById("btn-logout").disabled = !isAuthenticated;
38+
document.getElementById("txt-email").textContent = isAuthenticated
39+
? user.profile.email || user.profile.sub
40+
: "(please log in)";
41+
}
42+
43+
async function refresh() {
44+
console.log("refresh token");
45+
client.startSilentRenew();
46+
}
47+
48+
async function logout() {
49+
client.removeUser();
50+
updateUI();
51+
}
52+
3253
async function onload() {
3354
const settings_response = await fetch("/auth_settings.json");
3455
const settings = await settings_response.json();
@@ -43,39 +64,19 @@ async function onload() {
4364
if (query.includes("code=") && query.includes("state=")) {
4465
// Process the redirect callback from the identity provider
4566
const user = await client.signinCallback();
46-
console.log(user); // Don't do this IRL!
67+
// Don't do this IRL!
68+
console.log(user);
4769
// Use replaceState to redirect the user away and remove the querystring parameters
4870
window.history.replaceState({}, document.title, "/");
4971
}
5072

5173
updateUI();
5274
}
5375

54-
async function updateUI() {
55-
const user = await client.getUser();
56-
const isAuthenticated = Boolean(user);
57-
58-
document.getElementById("btn-login").disabled = isAuthenticated;
59-
document.getElementById("btn-logout").disabled = !isAuthenticated;
60-
document.getElementById("txt-email").textContent = isAuthenticated
61-
? user.profile.email || user.profile.sub
62-
: "(please log in)";
63-
}
64-
6576
async function login() {
6677
client.signinRedirect();
6778
}
6879

69-
async function logout() {
70-
client.removeUser();
71-
updateUI();
72-
}
73-
74-
async function refresh() {
75-
console.log("refresh token");
76-
client.startSilentRenew();
77-
}
78-
7980
async function _whoami(endpoint) {
8081
const user = await client.getUser();
8182
try {

0 commit comments

Comments
 (0)