Skip to content

Commit

Permalink
fix: access token validation
Browse files Browse the repository at this point in the history
  • Loading branch information
colinnielsen committed Sep 26, 2023
1 parent 71c03a5 commit bd6e05d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
openLoginWindow,
requestForIdToken,
saveIdToken,
validateAccessToken,
validateJWT,
} from '../utils/auth';
import { upsertUser } from '../utils/user';

Expand Down Expand Up @@ -59,7 +59,7 @@ export const handler = async ({ force }: HandlerInput) => {
const idToken = await requestForIdToken(codeVerifier, authorizationCode);

// validate the attached access token is valid
await validateAccessToken(idToken.access_token);
await validateJWT(idToken.access_token);

// save the id token to the local filesystem
saveIdToken(idToken);
Expand Down
8 changes: 4 additions & 4 deletions src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ const fetchJWKSFromAuth0Domain = async () => {
return key;
};

export const validateAccessToken = async <T extends AccessToken>(
export const validateJWT = async <T extends AccessToken>(
accessToken: string,
audience: string,
audience = AUTH0_AUDIENCE,
): Promise<T> => {
// fetch the public key from the auth0 domain
const rs256PubKey = await fetchJWKSFromAuth0Domain().catch(err => {
Expand Down Expand Up @@ -283,8 +283,8 @@ export const checkAuthentication = async (): Promise<AuthenticationStatus> => {
const tokenCache: CachedIDToken = JSON.parse(tokenCache_raw.toString());

const [accessToken, parsedIdToken] = await Promise.all([
validateAccessToken(tokenCache.access_token, AUTH0_AUDIENCE),
validateAccessToken<IdTokenWithProfileScope>(tokenCache.id_token, AUTH0_CLI_CLIENT_ID),
validateJWT(tokenCache.access_token),
validateJWT<IdTokenWithProfileScope>(tokenCache.id_token, AUTH0_CLI_CLIENT_ID),
]);

return {
Expand Down

0 comments on commit bd6e05d

Please sign in to comment.