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
1
example/.gitignore
vendored
1
example/.gitignore
vendored
|
@ -4,6 +4,7 @@ html/*
|
|||
public/*
|
||||
!public/footer.html
|
||||
!public/robots.txt
|
||||
!public/examples
|
||||
media/*
|
||||
icons/*
|
||||
langs/*
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// @ts-nocheck
|
||||
// APP_API_KEY=... deno run --allow-net --allow-import --allow-env -r app_sdk_test.js
|
||||
const deno = Deno;
|
||||
const sdk = (await import("http://localhost:4118/js/app_sdk.js")).default(
|
||||
"http://localhost:4118",
|
||||
deno.env.get("APP_API_KEY"),
|
||||
);
|
||||
const sdk = (await import("http://localhost:4118/js/app_sdk.js")).default({
|
||||
host: "http://localhost:4118",
|
||||
api_key: deno.env.get("APP_API_KEY"),
|
||||
});
|
||||
|
||||
// check data used
|
||||
console.log("data used:", (await sdk.app()).data_used);
|
||||
|
|
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