-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jul/oidc-pre-verification' into 'master'
feat(oidc): add preverified oidc verification method See merge request TankerHQ/sdk-js!1012
- Loading branch information
Showing
11 changed files
with
162 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { oidcSettings } from './config'; | ||
|
||
import { utils } from '@tanker/crypto'; | ||
|
||
export async function getGoogleIdToken(refreshToken: string): Promise<string> { | ||
const formData = JSON.stringify({ | ||
client_id: oidcSettings.googleAuth.clientId, | ||
client_secret: oidcSettings.googleAuth.clientSecret, | ||
grant_type: 'refresh_token', | ||
refresh_token: refreshToken, | ||
}); | ||
|
||
const url = 'https://www.googleapis.com/oauth2/v4/token'; | ||
|
||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: formData, | ||
}); | ||
|
||
if (!response.ok) { | ||
const description = `${response.status} ${response.statusText}: ${await response.text()}`; | ||
throw new Error(`Failed to get an ID token from ${url}:\n${description}`); | ||
} | ||
|
||
const data = await response.json(); | ||
return data.id_token; | ||
} | ||
|
||
export function extractSubject(jwt: string): string { | ||
const b64body = jwt.split('.')[1]!; | ||
const body = utils.toString(utils.fromSafeBase64(b64body)); | ||
return JSON.parse(body).sub; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.