Skip to content

Commit

Permalink
Expand signature validation with the output of the signature together…
Browse files Browse the repository at this point in the history
… with header and payload #11

Signed-off-by: Sarah Julia Kriesch <sarah.j.kriesch@fau.de>
  • Loading branch information
skriesch committed Jun 28, 2022
1 parent 1b0c9d7 commit 43f72c3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/token/token.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//SDPX-License-Identifier: MIT
//SDPX-FileCopyrightText: 2022 Philip Rebbe <rebbe.philip@fau.de>
//SDPX-FileCopyrightText: 2022 Raghunandan Arava <raghunandan.arava@fau.de>
//SDPX-FileCopyrightText: 2022 Sarah Julia Kriesch <sarah.j.kriesch@fau.de>

import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import * as jose from 'jose';
Expand Down Expand Up @@ -94,13 +95,14 @@ export class TokenService {
return await this.getToken(String(issuer.token_endpoint), grantBody);
}

async decodeToken(tokenString: string): Promise<[string, string]> {
const [header, payload] = this.decodeTokenString(tokenString);
async decodeToken(tokenString: string): Promise<[string, string, string]> {
const [header, payload, signature] = this.decodeTokenString(tokenString);

const formattedHeader = JSON.stringify(header, undefined, 2);
const formattedPayload = JSON.stringify(payload, undefined, 2);
const formattedSignature = JSON.stringify(signature, undefined, 2);

return [formattedHeader, formattedPayload];
return [formattedHeader, formattedPayload, formattedSignature];
}

async validateTokenSignature(
Expand Down Expand Up @@ -150,8 +152,9 @@ export class TokenService {

const header = this.decodeBase64EncodedString(tokenParts[0]);
const body = this.decodeBase64EncodedString(tokenParts[1]);
const signature = this.decodeBase64EncodedString(tokenParts[2]);

return [header, body];
return [header, body, signature];
}

private decodeBase64EncodedString(input: string): string {
Expand Down

0 comments on commit 43f72c3

Please sign in to comment.