add: app sdk client auth flow example
This commit is contained in:
parent
0138bf4cd4
commit
9ccbc69405
9 changed files with 95 additions and 27 deletions
39
example/public/examples/auth_flow_example/index.html
Normal file
39
example/public/examples/auth_flow_example/index.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Auth flow example</title>
|
||||
</head>
|
||||
<body>
|
||||
<button
|
||||
onclick="window.location.href = globalThis.sdk.GRANT_URL"
|
||||
id="login_button"
|
||||
>
|
||||
Login
|
||||
</button>
|
||||
|
||||
<p id="greeting"></p>
|
||||
|
||||
<script type="module">
|
||||
const app_id = BigInt(prompt("App ID:"));
|
||||
globalThis.sdk = (await import("/js/app_sdk.js")).from_localstorage(
|
||||
{
|
||||
host: window.location.origin,
|
||||
app_id,
|
||||
},
|
||||
);
|
||||
|
||||
if (sdk.user_id) {
|
||||
const user = await sdk.request({
|
||||
route: "auth/user/me",
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
document.getElementById("login_button").remove();
|
||||
document.getElementById("greeting").innerText =
|
||||
`Hello, ${user.username}!`;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
25
example/public/examples/auth_flow_example/redirect.html
Normal file
25
example/public/examples/auth_flow_example/redirect.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Auth flow example redirect</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Waiting...</p>
|
||||
|
||||
<script type="module">
|
||||
const app_id = BigInt(prompt("App ID:"));
|
||||
globalThis.sdk = (await import("/js/app_sdk.js")).from_localstorage(
|
||||
{
|
||||
host: window.location.origin,
|
||||
app_id,
|
||||
},
|
||||
);
|
||||
|
||||
sdk.localstorage_accept_connection();
|
||||
window.location.href =
|
||||
"/public/examples/auth_flow_example/index.html";
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue