Skip to content

Commit

Permalink
Get biscuit from JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-linaro committed Nov 13, 2024
1 parent 839036b commit c32f2e9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ function getPublicKeys() {
});
}

async function getBiscuitFromJWT(accessToken: string) {
const res = await fetch(`${AUTH_API_URL}/session`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
const resJson = await res.json();
if (!res.ok || !resJson) {
console.log(resJson);
throw new Error("failed to fetch biscuit from session");
}
return resJson.biscuit.token;
}

async function afterToken(accessToken: string) {
// fetch biscuit public keys
const res = await getPublicKeys();
Expand Down Expand Up @@ -107,11 +121,12 @@ export default defineConfig({
// this is only run after sign in
if (account) {
try {
let biscuit = await getBiscuitFromJWT(account.access_token!);
const { profile, public_keys } = await afterToken(
account.access_token!
biscuit
);
return {
access_token: account.access_token,
access_token: biscuit,
// refresh_token: account.refresh_token,
expires_at: account.expires_at,
public_keys,
Expand Down

0 comments on commit c32f2e9

Please sign in to comment.