1- import { create_base_client } from "../base_client" ;
21import { AuthStrategyBuilder } from "./types" ;
2+ import axios from 'axios'
33
4+ type TokenExchange = { access_token :string , token_type :string , expires_in :number }
45
5- type TokenExchange = { token :string , app_id :string }
66
7+ const auth = axios . create ( {
8+ baseURL :"https://faable.auth.staging.faable.link" ,
9+
10+ } )
711const exchangeGithubOidcToken = async ( gh_token :string ) => {
8- const client = create_base_client ( )
9- const res = await client . post < TokenExchange > ( "/auth/github-oidc" , {
10- token :gh_token
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" ,
1120 } )
12- const { token, app_id} = res . data
13- return { token, app_id}
21+ return res . data
1422}
1523
1624export const oidc_strategy : AuthStrategyBuilder < { idToken :string } > = (
@@ -30,15 +38,15 @@ export const oidc_strategy: AuthStrategyBuilder<{idToken:string}> = (
3038 token_ex = ex
3139 }
3240 return {
33- Authorization : `Bearer ${ token_ex . token } ` ,
41+ Authorization : `Bearer ${ token_ex . access_token } ` ,
3442 } ;
3543 } ,
3644 app_id : async ( ) => {
3745 if ( ! token_ex ) {
3846 const ex = await exchangeGithubOidcToken ( idToken )
3947 token_ex = ex
4048 }
41- return token_ex . app_id ;
49+ return token_ex . access_token ;
4250 }
4351 } ;
4452} ;
0 commit comments