-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: presentation during issuance server side
Signed-off-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
b468f27
commit 6cf1477
Showing
12 changed files
with
213 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/oauth2/src/authorization-challenge/create-authorization-challenge-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { type StringWithAutoCompletion, parseWithErrorHandling } from '@animo-id/oauth2-utils' | ||
import type { Oauth2ErrorCodes } from '../common/v-oauth2-error' | ||
import { | ||
type AuthorizationChallengeErrorResponse, | ||
type AuthorizationChallengeResponse, | ||
vAuthorizationChallengeErrorResponse, | ||
vAuthorizationChallengeResponse, | ||
} from './v-authorization-challenge' | ||
|
||
export interface CreateAuthorizationChallengeResponseOptions { | ||
/** | ||
* The authorization code | ||
*/ | ||
authorizationCode: string | ||
|
||
/** | ||
* Additional payload to include in the authorization challenge response. | ||
*/ | ||
additionalPayload?: Record<string, unknown> | ||
} | ||
|
||
/** | ||
* Create an authorization challenge response | ||
* | ||
* @throws {ValidationError} if an error occured during verification of the {@link AuthorizationChallengeResponse} | ||
*/ | ||
export function createAuthorizationChallengeResponse(options: CreateAuthorizationChallengeResponseOptions) { | ||
const authorizationChallengeResponse = parseWithErrorHandling(vAuthorizationChallengeResponse, { | ||
...options.additionalPayload, | ||
authorization_code: options.authorizationCode, | ||
} satisfies AuthorizationChallengeResponse) | ||
|
||
return { authorizationChallengeResponse } | ||
} | ||
|
||
export interface CreateAuthorizationChallengeErrorResponseOptions { | ||
/** | ||
* Auth session identifier for the authorization challenge. The client MUST include this | ||
* in subsequent requests to the authorization challenge endpoint. | ||
*/ | ||
authSession?: string | ||
|
||
/** | ||
* The presentation during issuance error. | ||
* | ||
* Error codes specific to authorization challenge are: | ||
* - @see Oauth2ErrorCodes.RedirectToWeb | ||
* - @see Oauth2ErrorCodes.InvalidSession | ||
* - @see Oauth2ErrorCodes.InsufficientAuthorization | ||
* | ||
* If you want to require presentation of a | ||
*/ | ||
error: Oauth2ErrorCodes | StringWithAutoCompletion | ||
|
||
/** | ||
* Optional error description | ||
*/ | ||
errorDescription?: string | ||
|
||
/** | ||
* OpenID4VP authorization request url that must be completed before authorization | ||
* can be granted | ||
* | ||
* Should be combined with `error` @see Oauth2ErrorCodes.InsufficientAuthorization | ||
*/ | ||
presentation?: string | ||
|
||
/** | ||
* Optional PAR request uri, allowing the authorization challenge request to be treated | ||
* as a succesfull pushed authorization request. | ||
* | ||
* Should be combined with `error` @see Oauth2ErrorCodes.RedirectToWeb | ||
*/ | ||
requestUri?: string | ||
|
||
/** | ||
* Duration is seconds after which the `requestUri` parameter will expire. Should only be included | ||
* if the `requestUri` is also included, and has no meaning otherwise | ||
*/ | ||
expiresIn?: number | ||
|
||
/** | ||
* Additional payload to include in the authorization challenge error response. | ||
*/ | ||
additionalPayload?: Record<string, unknown> | ||
} | ||
|
||
/** | ||
* Create an authorization challenge error response | ||
* | ||
* @throws {ValidationError} if an error occured during validation of the {@link AuthorizationChallengeErrorResponse} | ||
*/ | ||
export function createAuthorizationChallengeErrorResponse(options: CreateAuthorizationChallengeErrorResponseOptions) { | ||
const authorizationChallengeErrorResponse = parseWithErrorHandling(vAuthorizationChallengeErrorResponse, { | ||
...options.additionalPayload, | ||
|
||
// General FiPA | ||
error: options.error, | ||
error_description: options.errorDescription, | ||
auth_session: options.authSession, | ||
|
||
// Presentation during issuance | ||
presentation: options.presentation, | ||
|
||
// PAR | ||
request_uri: options.requestUri, | ||
expires_in: options.expiresIn, | ||
} satisfies AuthorizationChallengeErrorResponse) | ||
|
||
return authorizationChallengeErrorResponse | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/oauth2/src/authorization-challenge/parse-authorization-challenge-request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { parseWithErrorHandling } from '@animo-id/oauth2-utils' | ||
import { vAuthorizationChallengeRequest } from './v-authorization-challenge' | ||
|
||
export interface ParseAuthorizationChallengeRequestOptions { | ||
authorizationChallengeRequest: unknown | ||
} | ||
|
||
/** | ||
* Parse an authorization challenge request. | ||
* | ||
* @throws {ValidationError} if a successful response was received but an error occured during verification of the {@link AuthorizationChallengeResponse} | ||
*/ | ||
export async function parseAuthorizationChallengeRequest(options: ParseAuthorizationChallengeRequestOptions) { | ||
const authorizationChallengeRequest = parseWithErrorHandling( | ||
vAuthorizationChallengeRequest, | ||
options.authorizationChallengeRequest | ||
) | ||
|
||
return { authorizationChallengeRequest } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {} | ||
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>> | ||
export type StringWithAutoCompletion = string & {} |