Skip to content

Commit b2f5148

Browse files
committed
fix: improve oidc strategy
1 parent 310303e commit b2f5148

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/api/strategies/oidc.strategy.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
import { create_base_client } from "../base_client";
21
import { 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+
})
711
const 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

1624
export 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
};

src/commands/link/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const link: CommandModule<object, Options> = {
6464
const apps = await api.list();
6565

6666
if (apps.length === 0) {
67-
log.error("No apps found in your account. Create one first at https://faable.cloud");
67+
log.error("No apps found in your account. Create one first at https://faable.com");
6868
return;
6969
}
7070

0 commit comments

Comments
 (0)