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
|
@ -176,11 +176,7 @@ export default function tetratto({
|
|||
window.localStorage.setItem("atto:grant.user_id", uid);
|
||||
}
|
||||
|
||||
async function refresh_token(verifier) {
|
||||
if (!user_token) {
|
||||
throw Error("No user token provided.");
|
||||
}
|
||||
|
||||
async function refresh_token() {
|
||||
return api_promise(
|
||||
json_parse(
|
||||
await (
|
||||
|
@ -190,10 +186,10 @@ export default function tetratto({
|
|||
method,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Cookie": `__Secure-atto-token=${user_token}`,
|
||||
"X-Cookie": `Atto-Grant=${user_token}`,
|
||||
},
|
||||
body: json_stringify({
|
||||
verifier,
|
||||
verifier: user_verifier,
|
||||
}),
|
||||
},
|
||||
)
|
||||
|
@ -203,10 +199,10 @@ export default function tetratto({
|
|||
}
|
||||
|
||||
async function request({
|
||||
api_path,
|
||||
route,
|
||||
method = "POST",
|
||||
content_type = "application/json",
|
||||
body = "{}",
|
||||
body = {},
|
||||
}) {
|
||||
if (!user_token) {
|
||||
throw Error("No user token provided.");
|
||||
|
@ -215,16 +211,19 @@ export default function tetratto({
|
|||
return api_promise(
|
||||
json_parse(
|
||||
await (
|
||||
await fetch(`${host}/api/v1/${api_path}`, {
|
||||
await fetch(`${host}/api/v1/${route}`, {
|
||||
method,
|
||||
headers: {
|
||||
"Content-Type": content_type,
|
||||
"X-Cookie": `__Secure-atto-token=${user_token}`,
|
||||
"Content-Type":
|
||||
method === "GET" ? null : content_type,
|
||||
"X-Cookie": `Atto-Grant=${user_token}`,
|
||||
},
|
||||
body:
|
||||
content_type === "application/json"
|
||||
? json_stringify(body)
|
||||
: body,
|
||||
method === "GET"
|
||||
? null
|
||||
: content_type === "application/json"
|
||||
? json_stringify(body)
|
||||
: body,
|
||||
})
|
||||
).text(),
|
||||
),
|
||||
|
@ -233,6 +232,11 @@ export default function tetratto({
|
|||
|
||||
// ...
|
||||
return {
|
||||
user_id,
|
||||
user_token,
|
||||
user_verifier,
|
||||
app_id,
|
||||
api_key,
|
||||
// app data
|
||||
app,
|
||||
query,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue