Skip to content

Commit

Permalink
feat: encode unauthorized header value
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Nov 7, 2024
1 parent 5731a50 commit 58efac3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/oauth2/src/error/Oauth2ResourceUnauthorizedError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseWwwAuthenticateHeader } from '@animo-id/oauth2-utils'
import { encodeWwwAuthenticateHeader, parseWwwAuthenticateHeader } from '@animo-id/oauth2-utils'
import type { SupportedAuthenticationScheme } from '../access-token/verify-access-token'
import type { Oauth2ErrorCodes } from '../common/v-oauth2-error'
import { Oauth2Error } from './Oauth2Error'
Expand Down Expand Up @@ -56,4 +56,18 @@ export class Oauth2ResourceUnauthorizedError extends Oauth2Error {
)
)
}

public toHeaderValue() {
return encodeWwwAuthenticateHeader(
this.wwwAuthenticateHeaders.map((header) => ({
scheme: header.scheme,
payload: {
error: header.error ?? null,
error_description: header.error_description ?? null,
scope: header.scope ?? null,
...header.additionalPayload,
},
}))
)
}
}
6 changes: 5 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ export { type ValibotFetcher, createValibotFetcher, defaultFetcher } from './val
export { type HttpMethod, vHttpMethod, vHttpsUrl, vInteger } from './validation'
export { mergeDeep } from './object'
export { arrayEqualsIgnoreOrder } from './array'
export { parseWwwAuthenticateHeader, type WwwAuthenticateHeaderChallenge } from './www-authenticate'
export {
parseWwwAuthenticateHeader,
type WwwAuthenticateHeaderChallenge,
encodeWwwAuthenticateHeader,
} from './www-authenticate'
export { ContentType } from './content-type'

0 comments on commit 58efac3

Please sign in to comment.