Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
fix: exp for response token
Browse files Browse the repository at this point in the history
  • Loading branch information
Mritunjay Kumar authored and Mritunjay Kumar committed Aug 25, 2023
1 parent 8fbd8ca commit 8e6c48f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class DidAuthClientService {
async createDidAuthResponseToken(
didAuthRequestTokenStr: string,
options?: CreateResponseTokenOptions,
exp?: number
): Promise<string> {
const didAuthRequestToken = DidAuthRequestToken.fromString(didAuthRequestTokenStr)
const maxTokenValidityPeriod = options?.maxTokenValidInMs ?? DEFAULT_MAX_TOKEN_VALID_IN_MS
Expand All @@ -25,7 +26,7 @@ export default class DidAuthClientService {
)
}

const jwtObject = await buildResponseJwtObject(didAuthRequestTokenStr)
const jwtObject = await buildResponseJwtObject(didAuthRequestTokenStr, exp)

await this._signer.fillSignature(jwtObject)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ export default class AffinidiDidAuthService {
async createDidAuthResponseToken(
didAuthRequestTokenStr: string,
options?: CreateResponseTokenOptions,
exp?: number
): Promise<string> {
const clientService = new DidAuthClientService(this.createSigner())
return clientService.createDidAuthResponseToken(didAuthRequestTokenStr, options)
return clientService.createDidAuthResponseToken(didAuthRequestTokenStr, options, exp)
}

async createDidAuthResponseTokenThroughCloudWallet(
Expand Down
4 changes: 2 additions & 2 deletions common-libs/did-auth-lib/src/shared/builder.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { JwtService } from '@affinidi/tools-common'
import { parse } from 'did-resolver'

export const buildResponseJwtObject = async (didAuthRequestToken: string) => {
export const buildResponseJwtObject = async (didAuthRequestToken: string, exp?: number) => {
const didAuthRequestTokenDecoded = JwtService.fromJWT(didAuthRequestToken)
const jwtType = 'DidAuthResponse'
const NOW = Date.now()

const jwtObject: any = await JwtService.buildJWTInteractionToken(null, jwtType, didAuthRequestTokenDecoded)
jwtObject.payload.requestToken = didAuthRequestToken
jwtObject.payload.aud = parse(didAuthRequestTokenDecoded.payload.iss).did
jwtObject.payload.exp = undefined
jwtObject.payload.exp = exp
jwtObject.payload.createdAt = NOW
return jwtObject
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DidAuthServerService from '../../../src/DidAuthService/DidAuthServerServi
import Signer from '../../../src/shared/Signer'
import { Affinidi, KeysService, LocalKeyVault } from '@affinidi/common'
import DidAuthClientService from '../../../src/DidAuthService/DidAuthClientService'
import { DEFAULT_REQUEST_TOKEN_VALID_IN_MS } from 'src/shared/constants'

const env = {
environment: <Env>'dev',
Expand Down Expand Up @@ -150,7 +151,11 @@ describe('AffinidiDidAuthService', () => {

const didAuthRequestToken = await verifierDidAuthService.createDidAuthRequestToken(holderDid)

const didAuthResponseToken = await holderDidAuthService.createDidAuthResponseToken(didAuthRequestToken)
const NOW = Date.now()

const exp = NOW + DEFAULT_REQUEST_TOKEN_VALID_IN_MS

const didAuthResponseToken = await holderDidAuthService.createDidAuthResponseToken(didAuthRequestToken, undefined, exp)

const result = await verifierDidAuthService.verifyDidAuthResponseToken(didAuthResponseToken, verifierOptions)

Expand All @@ -174,7 +179,11 @@ describe('AffinidiDidAuthService', () => {

const didAuthRequestToken = await serverService.createDidAuthRequestToken(holderDid)

const didAuthResponseToken = await clientService.createDidAuthResponseToken(didAuthRequestToken)
const NOW = Date.now()

const exp = NOW + DEFAULT_REQUEST_TOKEN_VALID_IN_MS

const didAuthResponseToken = await clientService.createDidAuthResponseToken(didAuthRequestToken, undefined ,exp)

const result = await serverService.verifyDidAuthResponseToken(didAuthResponseToken)

Expand Down

0 comments on commit 8e6c48f

Please sign in to comment.