Skip to content

Commit

Permalink
make sid and sub optional again
Browse files Browse the repository at this point in the history
  • Loading branch information
magnearun committed Jan 17, 2025
1 parent 9587a64 commit 25363b4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
29 changes: 16 additions & 13 deletions libs/api/domains/license-service/src/lib/licenseService.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,20 +484,23 @@ export class LicenseService {
const licenseType = this.mapLicenseType(genericUserLicenseType)
const client = await this.getClient<typeof licenseType>(licenseType)

const barcodeSessionKey = this.getBarcodeSessionKey(licenseType, user.sub)
const activeBarcodeSession = await this.barcodeService.getSessionCache(barcodeSessionKey)

if (activeBarcodeSession && activeBarcodeSession !== user.sid) {
// If the user has an active session for the license type, we should not create a new barcode
this.logger.info(
`User has an active session for license: ${licenseType}`,
)
const barcodeSessionKey = user.sub ? this.getBarcodeSessionKey(licenseType, user.sub) : undefined
if (barcodeSessionKey) {
const activeBarcodeSession = await this.barcodeService.getSessionCache(barcodeSessionKey)

if (activeBarcodeSession && activeBarcodeSession !== user.sid) {
// If the user has an active session for the license type, we should not create a new barcode
this.logger.info(
`User has an active session for license: ${licenseType}`,
)

throw new ProblemError({
type: ProblemType.BAD_SUBJECT,
title: `User has an active session for license type: ${licenseType}`,
})
throw new ProblemError({
type: ProblemType.BAD_SUBJECT,
title: `User has an active session for license type: ${licenseType}`,
})
}
}

if (
genericUserLicense.license.pkpassStatus !==
GenericUserLicensePkPassStatus.Available
Expand Down Expand Up @@ -538,7 +541,7 @@ export class LicenseService {
licenseType,
extraData,
}),
this.barcodeService.setSessionCache(barcodeSessionKey, user.sid),
barcodeSessionKey && user.sid && this.barcodeService.setSessionCache(barcodeSessionKey, user.sid),
])

return tokenPayload
Expand Down
4 changes: 2 additions & 2 deletions libs/auth-nest-tools/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from '@island.is/shared/types'

export interface Auth {
sub: string
sid: string
sub?: string
sid?: string
nationalId?: string
scope: string[]
authorization: string
Expand Down
4 changes: 2 additions & 2 deletions libs/auth-nest-tools/src/lib/jwt.payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export interface JwtAct {
}

export interface JwtPayload {
sub: string
sid: string
sub?: string
sid?: string
nationalId?: string
scope: string | string[]
client_id: string
Expand Down
10 changes: 0 additions & 10 deletions libs/auth-nest-tools/src/lib/jwt.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ describe('JwtStrategy#validate', () => {
nationalId: '1234567890',
scope: ['test-scope-1'],
client_id: 'test-client',
sub: 'sub',
sid: 'sid',
delegationType: [AuthDelegationType.Custom],
actor: {
nationalId: '1234565555',
Expand Down Expand Up @@ -124,8 +122,6 @@ describe('JwtStrategy#validate', () => {
nationalId: '1234567890',
scope: ['test-scope-1'],
client_id: 'test-client',
sid: 'sid',
sub: 'sub',
}
const request = {
headers: {
Expand Down Expand Up @@ -155,8 +151,6 @@ describe('JwtStrategy#validate', () => {
nationalId: '1234564321',
scope: ['test-scope-2'],
},
sid: 'sid',
sub: 'sub',
}

// Act
Expand All @@ -178,16 +172,12 @@ describe('JwtStrategy#validate', () => {
scope: ['test-scope-1'],
client_id: 'test-client',
client_nationalId: '1234565555',
sid: 'sid',
sub: 'sub',
}

const personPayload: JwtPayload = {
scope: ['test-scope-1'],
client_id: 'test-client',
nationalId: '1234567890',
sub: 'sub',
sid: 'sid',
}

// Act
Expand Down
2 changes: 0 additions & 2 deletions libs/auth-nest-tools/src/lib/mock-auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export class MockAuthGuard implements CanActivate {
this.auth = {
nationalId: '0101302989',
authorization: '',
sid: '',
sub: '',
client: 'mock',
scope: [],
...auth,
Expand Down

0 comments on commit 25363b4

Please sign in to comment.