Skip to content

Commit

Permalink
invalidate authorization code
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmanos committed Sep 26, 2023
1 parent 120208e commit 42a2d69
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/openid4vci/grant_types/AuthorizationCodeGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export async function authorizationCodeGrantTokenEndpoint(body: TokenRequestBody
.createQueryBuilder("state")
.where("state.authorization_code = :code", { code: body.code })
.getOne();

if (!userSession) {
throw `No user session was found for authorization code ${body.code}`
}


return generateAccessToken(userSession);
}
4 changes: 3 additions & 1 deletion src/openid4vci/utils/generateAccessToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const accessTokenExpirationInSeconds = 8000;
export async function generateAccessToken(userSession: AuthorizationServerState): Promise<TokenResponseSchemaType> {

const credentialIssuersIdentifiers: string[] = [];

if (userSession.authorization_details) {
for (const ad of userSession?.authorization_details) {
if (ad.locations) {
Expand All @@ -25,6 +25,8 @@ export async function generateAccessToken(userSession: AuthorizationServerState)
userSession.c_nonce = crypto.randomBytes(60).toString('base64url');
userSession.c_nonce_expires_in = accessTokenExpirationInSeconds;



// store user session in access token
console.log("User session on AT generation: ", userSession);
console.log("Serialized user session", AuthorizationServerState.serialize(userSession))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class OpenidForCredentialIssuingAuthorizationServerService implements Ope
let state = await this.authorizationServerStateRepository.createQueryBuilder("state")
.where("state.authorization_code = :code", { code: body.code })
.getOne();

if (!state)
throw new Error("Could not get session");
// if (!userSession.categorizedRawCredentials) {
Expand All @@ -179,6 +180,10 @@ export class OpenidForCredentialIssuingAuthorizationServerService implements Ope
// throw new Error("Could not get categorized raw credential");

response = await authorizationCodeGrantTokenEndpoint(body, req.headers.authorization);
if (state.authorization_code) {
state.authorization_code = "";
await this.authorizationServerStateRepository.save(state);
}
}
catch (err) {
console.error("Error = ", err)
Expand Down

0 comments on commit 42a2d69

Please sign in to comment.