1+ import { create_base_client } from "../base_client" ;
12import { AuthStrategyBuilder } from "./types" ;
2- import axios from 'axios'
33
4- type TokenExchange = { access_token :string , token_type :string , expires_in :number }
54
5+ type TokenExchange = { token :string , app_id :string }
66
7- const auth = axios . create ( {
8- baseURL :"https://faable.auth.staging.faable.link" ,
9-
10- } )
117const exchangeGithubOidcToken = async ( gh_token :string ) => {
12-
13- const res = await auth . post < TokenExchange > ( "/oauth/token" , {
14- grant_type :"urn:ietf:params:oauth:grant-type:token-exchange" ,
15- subject_token_type :"urn:ietf:params:oauth:token-type:jwt" ,
16- subject_token :gh_token ,
17- resource :"https://faable.com" ,
18- audience :"https://faable.com" ,
19- scope :"openid email profile" ,
20- client_id :"a6f1381a-2591-4f18-aaa4-b8922ac91fce"
8+ const client = create_base_client ( )
9+ const res = await client . post < TokenExchange > ( "/auth/github-oidc" , {
10+ token :gh_token
2111 } )
22- return res . data
12+ const { token, app_id} = res . data
13+ return { token, app_id}
2314}
2415
2516export const oidc_strategy : AuthStrategyBuilder < { idToken :string } > = (
@@ -39,15 +30,15 @@ export const oidc_strategy: AuthStrategyBuilder<{idToken:string}> = (
3930 token_ex = ex
4031 }
4132 return {
42- Authorization : `Bearer ${ token_ex . access_token } ` ,
33+ Authorization : `Bearer ${ token_ex . token } ` ,
4334 } ;
4435 } ,
4536 app_id : async ( ) => {
4637 if ( ! token_ex ) {
4738 const ex = await exchangeGithubOidcToken ( idToken )
4839 token_ex = ex
4940 }
50- return token_ex . access_token ;
41+ return token_ex . app_id ;
5142 }
5243 } ;
5344} ;
0 commit comments