Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(services-bff): Move params from ids par requests body to header #16761

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions apps/services/bff/src/app/modules/ids/ids.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class IdsService {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: this.createPARAuthorizationHeader(),
},
body: new URLSearchParams(body).toString(),
},
Expand Down Expand Up @@ -122,6 +123,22 @@ export class IdsService {
}
}

/**
* Creates a Basic Authorization header for the PAR (Pushed Authorization Requests)
* The client ID and secret are url encoded and concatenated with a colon and then base64 encoded
*
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1
*/
createPARAuthorizationHeader() {
const { ids } = this.config
const basicAuth = `${encodeURIComponent(ids.clientId)}:${encodeURIComponent(
ids.secret,
)}`
const base64Auth = Buffer.from(basicAuth).toString('base64')

return `Basic ${base64Auth}`
}

/**
* Fetches the PAR (Pushed Authorization Requests) from the Ids
*/
Expand All @@ -131,10 +148,10 @@ export class IdsService {
loginHint?: string
prompt?: string
}) {
return this.postRequest<ParResponse>('/connect/par', {
client_secret: this.config.ids.secret,
...this.getLoginSearchParams(args),
})
return this.postRequest<ParResponse>(
'/connect/par',
this.getLoginSearchParams(args),
)
}

/**
Expand All @@ -150,13 +167,9 @@ export class IdsService {
code: string
codeVerifier: string
}) {
const { ids } = this.config

return this.postRequest<TokenResponse>('/connect/token', {
grant_type: 'authorization_code',
code,
client_secret: ids.secret,
client_id: ids.clientId,
redirect_uri: this.config.callbacksRedirectUris.login,
code_verifier: codeVerifier,
})
Expand All @@ -169,13 +182,10 @@ export class IdsService {
*/
public async refreshToken(refreshToken: string) {
const decryptedRefreshToken = this.cryptoService.decrypt(refreshToken)
const { ids } = this.config

return this.postRequest<TokenResponse>('/connect/token', {
grant_type: 'refresh_token',
refresh_token: decryptedRefreshToken,
client_secret: ids.secret,
client_id: ids.clientId,
})
}

Expand All @@ -190,13 +200,10 @@ export class IdsService {
tokenTypeHint: 'access_token' | 'refresh_token',
) {
const decryptedToken = this.cryptoService.decrypt(token)
const { ids } = this.config

return this.postRequest('/connect/revocation', {
token: decryptedToken,
token_type_hint: tokenTypeHint,
client_secret: ids.secret,
client_id: ids.clientId,
})
}
}