@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-feature.SSISDK.57.uni.client.205 → 0.34.1-feature.SSISDK.58.host.nonce.endpoint.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +133 -186
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -49
- package/dist/index.d.ts +9 -49
- package/dist/index.js +132 -185
- package/dist/index.js.map +1 -1
- package/package.json +18 -21
- package/src/index.ts +1 -1
- package/src/siop-api-functions.ts +20 -31
- package/src/siopv2-rp-api-server.ts +10 -9
- package/src/types/types.ts +3 -60
- package/src/webapp-api-functions.ts +28 -26
- package/src/middleware/validationMiddleware.ts +0 -20
- package/src/universal-oid4vp-api-functions.ts +0 -195
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api",
|
|
3
|
-
"version": "0.34.1-feature.SSISDK.
|
|
3
|
+
"version": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"start:dev": "ts-node __tests__/RestAPI.ts"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@sphereon/did-auth-siop": "0.19.1-feature.
|
|
27
|
-
"@sphereon/ssi-express-support": "0.34.1-feature.SSISDK.
|
|
28
|
-
"@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.
|
|
29
|
-
"@sphereon/ssi-sdk.credential-validation": "0.34.1-feature.SSISDK.
|
|
30
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.34.1-feature.SSISDK.
|
|
31
|
-
"@sphereon/ssi-sdk.pd-manager": "0.34.1-feature.SSISDK.
|
|
32
|
-
"@sphereon/ssi-sdk.presentation-exchange": "0.34.1-feature.SSISDK.
|
|
33
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.
|
|
34
|
-
"@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth": "0.34.1-feature.SSISDK.
|
|
35
|
-
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.
|
|
26
|
+
"@sphereon/did-auth-siop": "0.19.1-feature.SSISDK.58.host.nonce.endpoint.107",
|
|
27
|
+
"@sphereon/ssi-express-support": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
28
|
+
"@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
29
|
+
"@sphereon/ssi-sdk.credential-validation": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
30
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
31
|
+
"@sphereon/ssi-sdk.pd-manager": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
32
|
+
"@sphereon/ssi-sdk.presentation-exchange": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
33
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
34
|
+
"@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
35
|
+
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
36
36
|
"@veramo/core": "4.2.0",
|
|
37
37
|
"@veramo/credential-w3c": "4.2.0",
|
|
38
38
|
"awesome-qr": "^2.1.5-rc.0",
|
|
@@ -44,21 +44,18 @@
|
|
|
44
44
|
"express": "^4.19.2",
|
|
45
45
|
"short-uuid": "^4.2.2",
|
|
46
46
|
"swagger-ui-express": "^5.0.1",
|
|
47
|
-
"uuid": "^9.0.1"
|
|
48
|
-
"zod": "^4.1.5"
|
|
47
|
+
"uuid": "^9.0.1"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@decentralized-identity/ion-sdk": "^0.6.0",
|
|
52
|
-
"@sphereon/did-auth-siop-adapter": "0.19.1-feature.
|
|
51
|
+
"@sphereon/did-auth-siop-adapter": "0.19.1-feature.SSISDK.58.host.nonce.endpoint.107",
|
|
53
52
|
"@sphereon/did-uni-client": "^0.6.3",
|
|
54
53
|
"@sphereon/pex": "5.0.0-unstable.28",
|
|
55
54
|
"@sphereon/pex-models": "^2.3.2",
|
|
56
|
-
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.34.1-feature.SSISDK.
|
|
57
|
-
"@sphereon/ssi-sdk
|
|
58
|
-
"@sphereon/ssi-sdk
|
|
59
|
-
"@sphereon/ssi-sdk.
|
|
60
|
-
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "0.34.1-feature.SSISDK.57.uni.client.205+f1b902e3",
|
|
61
|
-
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.57.uni.client.205+f1b902e3",
|
|
55
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
56
|
+
"@sphereon/ssi-sdk.credential-vcdm": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
57
|
+
"@sphereon/ssi-sdk.credential-vcdm-jsonld-provider": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
58
|
+
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.58.host.nonce.endpoint.145+5bfc0b12",
|
|
62
59
|
"@types/body-parser": "^1.19.5",
|
|
63
60
|
"@types/cookie-parser": "^1.4.7",
|
|
64
61
|
"@types/cors": "^2.8.17",
|
|
@@ -117,5 +114,5 @@
|
|
|
117
114
|
"OpenID Connect",
|
|
118
115
|
"Authenticator"
|
|
119
116
|
],
|
|
120
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "5bfc0b1229134b5d80279a3baf1fc64c9c6e755e"
|
|
121
118
|
}
|
package/src/index.ts
CHANGED
|
@@ -46,32 +46,21 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
46
46
|
console.log(`verifyAuthResponse SIOP endpoint is disabled`)
|
|
47
47
|
return
|
|
48
48
|
}
|
|
49
|
-
const path = opts?.path ?? '/siop/
|
|
49
|
+
const path = opts?.path ?? '/siop/definitions/:definitionId/auth-responses/:correlationId'
|
|
50
50
|
router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
51
51
|
try {
|
|
52
|
-
const { correlationId,
|
|
53
|
-
if (!correlationId) {
|
|
54
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}`)
|
|
52
|
+
const { correlationId, definitionId, tenantId, version } = request.params
|
|
53
|
+
if (!correlationId || !definitionId) {
|
|
54
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
|
|
55
55
|
return sendErrorResponse(response, 404, 'No authorization request could be found')
|
|
56
56
|
}
|
|
57
|
-
console.
|
|
58
|
-
console.
|
|
59
|
-
const definitionItems = await context.agent.pdmGetDefinitions({
|
|
60
|
-
filter: [
|
|
61
|
-
{
|
|
62
|
-
queryId,
|
|
63
|
-
...(tenantId && { tenantId }),
|
|
64
|
-
...(version && { version }),
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: queryId,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
})
|
|
57
|
+
console.log('Authorization Response (siop-sessions')
|
|
58
|
+
console.log(JSON.stringify(request.body, null, 2))
|
|
59
|
+
const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ definitionId, tenantId, version }] })
|
|
71
60
|
if (definitionItems.length === 0) {
|
|
72
|
-
console.log(`Could not get
|
|
61
|
+
console.log(`Could not get definition ${definitionId} from agent. Will return 404`)
|
|
73
62
|
response.statusCode = 404
|
|
74
|
-
response.statusMessage = `No definition ${
|
|
63
|
+
response.statusMessage = `No definition ${definitionId}`
|
|
75
64
|
return response.send()
|
|
76
65
|
}
|
|
77
66
|
|
|
@@ -82,8 +71,8 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
82
71
|
const verifiedResponse = await context.agent.siopVerifyAuthResponse({
|
|
83
72
|
authorizationResponse,
|
|
84
73
|
correlationId,
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
definitionId,
|
|
75
|
+
dcqlQueryPayload: definitionItem.dcqlPayload,
|
|
87
76
|
})
|
|
88
77
|
|
|
89
78
|
// FIXME SSISDK-55 add proper support for checking for DCQL presentations
|
|
@@ -100,7 +89,7 @@ export function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequi
|
|
|
100
89
|
return response.send(JSON.stringify(authorizationChallengeValidationResponse))
|
|
101
90
|
}
|
|
102
91
|
|
|
103
|
-
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId,
|
|
92
|
+
const responseRedirectURI = await context.agent.siopGetRedirectURI({ correlationId, definitionId, state: verifiedResponse.state })
|
|
104
93
|
if (responseRedirectURI) {
|
|
105
94
|
response.setHeader('Content-Type', 'application/json')
|
|
106
95
|
return response.send(JSON.stringify({ redirect_uri: responseRedirectURI }))
|
|
@@ -124,23 +113,23 @@ export function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredC
|
|
|
124
113
|
console.log(`getAuthRequest SIOP endpoint is disabled`)
|
|
125
114
|
return
|
|
126
115
|
}
|
|
127
|
-
const path = opts?.path ?? '/siop/
|
|
116
|
+
const path = opts?.path ?? '/siop/definitions/:definitionId/auth-requests/:correlationId'
|
|
128
117
|
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
129
118
|
try {
|
|
130
119
|
const correlationId = request.params.correlationId
|
|
131
|
-
const
|
|
132
|
-
if (!correlationId || !
|
|
133
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
120
|
+
const definitionId = request.params.definitionId
|
|
121
|
+
if (!correlationId || !definitionId) {
|
|
122
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
|
|
134
123
|
return sendErrorResponse(response, 404, 'No authorization request could be found')
|
|
135
124
|
}
|
|
136
125
|
const requestState = await context.agent.siopGetAuthRequestState({
|
|
137
126
|
correlationId,
|
|
138
|
-
|
|
127
|
+
definitionId,
|
|
139
128
|
errorOnNotFound: false,
|
|
140
129
|
})
|
|
141
130
|
if (!requestState) {
|
|
142
131
|
console.log(
|
|
143
|
-
`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${
|
|
132
|
+
`No authorization request could be found for the given url in the state manager. correlationId: ${correlationId}, definitionId: ${definitionId}`,
|
|
144
133
|
)
|
|
145
134
|
return sendErrorResponse(response, 404, `No authorization request could be found`)
|
|
146
135
|
}
|
|
@@ -159,8 +148,8 @@ export function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredC
|
|
|
159
148
|
} finally {
|
|
160
149
|
await context.agent.siopUpdateAuthRequestState({
|
|
161
150
|
correlationId,
|
|
162
|
-
|
|
163
|
-
state: '
|
|
151
|
+
definitionId,
|
|
152
|
+
state: 'sent',
|
|
164
153
|
error,
|
|
165
154
|
})
|
|
166
155
|
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { agentContext } from '@sphereon/ssi-sdk.core'
|
|
2
2
|
import { copyGlobalAuthToEndpoints, ExpressSupport } from '@sphereon/ssi-express-support'
|
|
3
|
+
import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'
|
|
3
4
|
import { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
4
5
|
import { TAgent } from '@veramo/core'
|
|
5
6
|
import express, { Express, Request, Response, Router } from 'express'
|
|
6
7
|
import { getAuthRequestSIOPv2Endpoint, verifyAuthResponseSIOPv2Endpoint } from './siop-api-functions'
|
|
7
8
|
import { IRequiredPlugins, ISIOPv2RPRestAPIOpts } from './types'
|
|
8
9
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
authStatusWebappEndpoint,
|
|
11
|
+
createAuthRequestWebappEndpoint,
|
|
11
12
|
getDefinitionsEndpoint,
|
|
12
|
-
|
|
13
|
-
} from './
|
|
13
|
+
removeAuthRequestStateWebappEndpoint,
|
|
14
|
+
} from './webapp-api-functions'
|
|
14
15
|
import swaggerUi from 'swagger-ui-express'
|
|
15
16
|
|
|
16
17
|
export class SIOPv2RPApiServer {
|
|
17
18
|
private readonly _express: Express
|
|
18
19
|
private readonly _router: Router
|
|
19
|
-
private readonly _agent: TAgent<ISIOPv2RP>
|
|
20
|
+
private readonly _agent: TAgent<IPresentationExchange & ISIOPv2RP>
|
|
20
21
|
private readonly _opts?: ISIOPv2RPRestAPIOpts
|
|
21
22
|
private readonly _basePath: string
|
|
22
23
|
|
|
@@ -39,9 +40,9 @@ export class SIOPv2RPApiServer {
|
|
|
39
40
|
|
|
40
41
|
// Webapp endpoints
|
|
41
42
|
if (features.includes('rp-status')) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
createAuthRequestWebappEndpoint(this._router, context, opts?.endpointOpts?.webappCreateAuthRequest)
|
|
44
|
+
authStatusWebappEndpoint(this._router, context, opts?.endpointOpts?.webappAuthStatus)
|
|
45
|
+
removeAuthRequestStateWebappEndpoint(this._router, context, opts?.endpointOpts?.webappDeleteAuthRequest)
|
|
45
46
|
getDefinitionsEndpoint(this._router, context, opts?.endpointOpts?.webappGetDefinitions)
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -91,7 +92,7 @@ export class SIOPv2RPApiServer {
|
|
|
91
92
|
return this._router
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
get agent(): TAgent<ISIOPv2RP> {
|
|
95
|
+
get agent(): TAgent<IPresentationExchange & ISIOPv2RP> {
|
|
95
96
|
return this._agent
|
|
96
97
|
}
|
|
97
98
|
|
package/src/types/types.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { CreateAuthorizationRequestPayload, CreateAuthorizationResponsePayload } from '@sphereon/did-auth-siop'
|
|
2
1
|
import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-express-support'
|
|
3
|
-
import {
|
|
4
|
-
import { AuthorizationRequestStateStatus, AuthorizationResponseStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
2
|
+
import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'
|
|
5
3
|
import { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
6
|
-
import { AdditionalClaims } from '@sphereon/ssi-types'
|
|
7
4
|
import { IAgentContext, ICredentialVerifier } from '@veramo/core'
|
|
8
|
-
import {
|
|
5
|
+
import { IPDManager } from '@sphereon/ssi-sdk.pd-manager'
|
|
9
6
|
import { QRCodeOpts } from './QRCode.types'
|
|
10
7
|
|
|
11
8
|
export type SiopFeatures = 'rp-status' | 'siop'
|
|
12
|
-
|
|
13
9
|
export interface ISIOPv2RPRestAPIOpts {
|
|
14
10
|
enableFeatures?: SiopFeatures[]
|
|
15
11
|
endpointOpts?: {
|
|
@@ -32,58 +28,5 @@ export interface ICreateAuthRequestWebappEndpointOpts extends ISingleEndpointOpt
|
|
|
32
28
|
responseRedirectURI?: string
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
export type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP & IPDManager
|
|
31
|
+
export type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP & IPresentationExchange & IPDManager
|
|
36
32
|
export type IRequiredContext = IAgentContext<IRequiredPlugins>
|
|
37
|
-
|
|
38
|
-
export type CreateAuthorizationRequestPayloadRequest = Request<Record<string, never>, any, CreateAuthorizationRequestPayload, Record<string, never>>
|
|
39
|
-
|
|
40
|
-
export type CreateAuthorizationResponsePayloadResponse = Response<CreateAuthorizationResponsePayload>
|
|
41
|
-
|
|
42
|
-
export type DeleteAuthorizationRequest = Request<DeleteAuthorizationRequestPathParameters, any, Record<string, any>, Record<string, any>>
|
|
43
|
-
|
|
44
|
-
export type DeleteAuthorizationRequestPathParameters = {
|
|
45
|
-
correlationId: string
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type GetAuthorizationRequestStatus = Request<GetAuthorizationRequestStatusPathParameters, any, Record<string, any>, Record<string, any>>
|
|
49
|
-
|
|
50
|
-
export type GetAuthorizationRequestStatusPathParameters = {
|
|
51
|
-
correlationId: string
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type RequestError = {
|
|
55
|
-
status: number
|
|
56
|
-
message: string
|
|
57
|
-
error_details?: string
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface AuthStatusResponse {
|
|
61
|
-
status: AuthorizationRequestStateStatus | AuthorizationResponseStateStatus
|
|
62
|
-
correlation_id: string
|
|
63
|
-
query_id: string
|
|
64
|
-
last_updated: number
|
|
65
|
-
verified_data?: VerifiedData
|
|
66
|
-
error?: RequestError
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export type VerifiedData = {
|
|
70
|
-
authorization_response?: AuthorizationResponse
|
|
71
|
-
credential_claims?: AdditionalClaims
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type AuthorizationResponse = {
|
|
75
|
-
presentation_submission?: Record<string, any>
|
|
76
|
-
vp_token?: VpToken
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type SingleObjectVpTokenPE = Record<string, any>
|
|
80
|
-
|
|
81
|
-
export type SingleStringVpTokenPE = string
|
|
82
|
-
|
|
83
|
-
export type MultipleVpTokens = Array<SingleObjectVpTokenPE> | Array<SingleStringVpTokenPE>
|
|
84
|
-
|
|
85
|
-
export type MultipleVpTokenDCQL = {
|
|
86
|
-
[key: string]: MultipleVpTokens
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export type VpToken = SingleObjectVpTokenPE | SingleStringVpTokenPE | MultipleVpTokens | MultipleVpTokenDCQL
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { AuthorizationRequestState, AuthorizationResponseStateStatus
|
|
1
|
+
import { AuthorizationRequestState, AuthorizationResponseStateStatus } from '@sphereon/did-auth-siop'
|
|
2
2
|
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
3
3
|
import { AuthStatusResponse, GenerateAuthRequestURIResponse, uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
4
|
-
import { VerifiedDataMode } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
5
|
-
import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
|
|
4
|
+
import { AuthorizationResponseStateWithVerifiedData, VerifiedDataMode } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
6
5
|
import { Request, Response, Router } from 'express'
|
|
7
6
|
import uuid from 'short-uuid'
|
|
8
7
|
import { ICreateAuthRequestWebappEndpointOpts, IRequiredContext } from './types'
|
|
8
|
+
import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
|
|
9
9
|
|
|
10
10
|
export function createAuthRequestWebappEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts) {
|
|
11
11
|
if (opts?.enabled === false) {
|
|
12
12
|
console.log(`createAuthRequest Webapp endpoint is disabled`)
|
|
13
13
|
return
|
|
14
14
|
}
|
|
15
|
-
const path = opts?.path ?? '/webapp/
|
|
15
|
+
const path = opts?.path ?? '/webapp/definitions/:definitionId/auth-requests'
|
|
16
16
|
router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
17
17
|
try {
|
|
18
18
|
// if (!request.agent) throw Error('No agent configured')
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
21
|
-
return sendErrorResponse(response, 400, 'No
|
|
19
|
+
const definitionId = request.params.definitionId
|
|
20
|
+
if (!definitionId) {
|
|
21
|
+
return sendErrorResponse(response, 400, 'No definitionId query parameter provided')
|
|
22
22
|
}
|
|
23
23
|
const state: string = request.body.state ?? uuid.uuid()
|
|
24
24
|
const correlationId = request.body.correlationId ?? state
|
|
25
25
|
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts
|
|
26
26
|
|
|
27
|
-
const requestByReferenceURI = uriWithBase(`/siop/
|
|
27
|
+
const requestByReferenceURI = uriWithBase(`/siop/definitions/${definitionId}/auth-requests/${state}`, {
|
|
28
28
|
baseURI: opts?.siopBaseURI,
|
|
29
29
|
})
|
|
30
|
-
const responseURI = uriWithBase(`/siop/
|
|
30
|
+
const responseURI = uriWithBase(`/siop/definitions/${definitionId}/auth-responses/${state}`, { baseURI: opts?.siopBaseURI })
|
|
31
31
|
// first version is for backwards compat
|
|
32
32
|
const responseRedirectURI =
|
|
33
33
|
('response_redirect_uri' in request.body && (request.body.response_redirect_uri as string | undefined)) ??
|
|
34
34
|
('responseRedirectURI' in request.body && (request.body.responseRedirectURI as string | undefined))
|
|
35
35
|
|
|
36
36
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
37
|
-
|
|
37
|
+
definitionId,
|
|
38
38
|
correlationId,
|
|
39
39
|
state,
|
|
40
40
|
nonce: uuid.uuid(),
|
|
@@ -53,7 +53,7 @@ export function createAuthRequestWebappEndpoint(router: Router, context: IRequir
|
|
|
53
53
|
const authRequestBody: GenerateAuthRequestURIResponse = {
|
|
54
54
|
correlationId,
|
|
55
55
|
state,
|
|
56
|
-
|
|
56
|
+
definitionId,
|
|
57
57
|
authRequestURI,
|
|
58
58
|
authStatusURI: `${uriWithBase(opts?.webappAuthStatusPath ?? '/webapp/auth-status', { baseURI: opts?.webappBaseURI })}`,
|
|
59
59
|
...(qrCodeDataUri && { qrCodeDataUri }),
|
|
@@ -76,24 +76,26 @@ export function authStatusWebappEndpoint(router: Router, context: IRequiredConte
|
|
|
76
76
|
try {
|
|
77
77
|
console.log('Received auth-status request...')
|
|
78
78
|
const correlationId: string = request.body.correlationId as string
|
|
79
|
-
const
|
|
79
|
+
const definitionId: string = request.body.definitionId as string
|
|
80
80
|
|
|
81
81
|
const requestState =
|
|
82
|
-
correlationId &&
|
|
82
|
+
correlationId && definitionId
|
|
83
83
|
? await context.agent.siopGetAuthRequestState({
|
|
84
84
|
correlationId,
|
|
85
|
-
|
|
85
|
+
definitionId,
|
|
86
86
|
errorOnNotFound: false,
|
|
87
87
|
})
|
|
88
88
|
: undefined
|
|
89
|
-
if (!requestState || !
|
|
90
|
-
console.log(
|
|
89
|
+
if (!requestState || !definitionId || !correlationId) {
|
|
90
|
+
console.log(
|
|
91
|
+
`No authentication request mapping could be found for the given URL. correlation: ${correlationId}, definitionId: ${definitionId}`,
|
|
92
|
+
)
|
|
91
93
|
response.statusCode = 404
|
|
92
94
|
const statusBody: AuthStatusResponse = {
|
|
93
95
|
status: requestState ? requestState.status : 'error',
|
|
94
96
|
error: 'No authentication request mapping could be found for the given URL.',
|
|
95
97
|
correlationId,
|
|
96
|
-
|
|
98
|
+
definitionId,
|
|
97
99
|
lastUpdated: requestState ? requestState.lastUpdated : Date.now(),
|
|
98
100
|
}
|
|
99
101
|
return response.json(statusBody)
|
|
@@ -105,10 +107,10 @@ export function authStatusWebappEndpoint(router: Router, context: IRequiredConte
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
let responseState
|
|
108
|
-
if (requestState.status === '
|
|
110
|
+
if (requestState.status === 'sent') {
|
|
109
111
|
responseState = (await context.agent.siopGetAuthResponseState({
|
|
110
112
|
correlationId,
|
|
111
|
-
|
|
113
|
+
definitionId,
|
|
112
114
|
includeVerifiedData: includeVerifiedData,
|
|
113
115
|
errorOnNotFound: false,
|
|
114
116
|
})) as AuthorizationResponseStateWithVerifiedData
|
|
@@ -119,7 +121,7 @@ export function authStatusWebappEndpoint(router: Router, context: IRequiredConte
|
|
|
119
121
|
status: overallState.status,
|
|
120
122
|
...(overallState.error ? { error: overallState.error?.message } : {}),
|
|
121
123
|
correlationId,
|
|
122
|
-
|
|
124
|
+
definitionId,
|
|
123
125
|
lastUpdated: overallState.lastUpdated,
|
|
124
126
|
...(responseState && responseState.status === AuthorizationResponseStateStatus.VERIFIED
|
|
125
127
|
? {
|
|
@@ -146,17 +148,17 @@ export function removeAuthRequestStateWebappEndpoint(router: Router, context: IR
|
|
|
146
148
|
console.log(`removeAuthStatus Webapp endpoint is disabled`)
|
|
147
149
|
return
|
|
148
150
|
}
|
|
149
|
-
const path = opts?.path ?? '/webapp/
|
|
151
|
+
const path = opts?.path ?? '/webapp/definitions/:definitionId/auth-requests/:correlationId'
|
|
150
152
|
router.delete(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
151
153
|
try {
|
|
152
154
|
const correlationId: string = request.params.correlationId
|
|
153
|
-
const
|
|
154
|
-
if (!correlationId || !
|
|
155
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
155
|
+
const definitionId: string = request.params.definitionId
|
|
156
|
+
if (!correlationId || !definitionId) {
|
|
157
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
|
|
156
158
|
return sendErrorResponse(response, 404, 'No authorization request could be found')
|
|
157
159
|
}
|
|
158
160
|
response.statusCode = 200
|
|
159
|
-
return response.json(await context.agent.siopDeleteAuthState({
|
|
161
|
+
return response.json(await context.agent.siopDeleteAuthState({ definitionId, correlationId }))
|
|
160
162
|
} catch (error) {
|
|
161
163
|
return sendErrorResponse(response, 500, error.message, error)
|
|
162
164
|
}
|
|
@@ -168,7 +170,7 @@ export function getDefinitionsEndpoint(router: Router, context: IRequiredContext
|
|
|
168
170
|
console.log(`getDefinitions Webapp endpoint is disabled`)
|
|
169
171
|
return
|
|
170
172
|
}
|
|
171
|
-
const path = opts?.path ?? '/webapp/
|
|
173
|
+
const path = opts?.path ?? '/webapp/definitions'
|
|
172
174
|
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
173
175
|
try {
|
|
174
176
|
const definitions = await context.agent.pdmGetDefinitions()
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
import { z, ZodError } from 'zod';
|
|
3
|
-
|
|
4
|
-
export const validateData = (schema: z.ZodObject<any, any>) => {
|
|
5
|
-
return (req: Request, res: Response, next: NextFunction) => {
|
|
6
|
-
try {
|
|
7
|
-
schema.parse(req.body);
|
|
8
|
-
next();
|
|
9
|
-
} catch (error) {
|
|
10
|
-
if (error instanceof ZodError) {
|
|
11
|
-
const errorMessages = error.issues.map((issue: any) => ({
|
|
12
|
-
message: `${issue.path.join('.')} is ${issue.message}`,
|
|
13
|
-
}))
|
|
14
|
-
res.status(400).json({ status: 400, message: 'Invalid data', error_details: errorMessages[0].message });
|
|
15
|
-
} else {
|
|
16
|
-
res.status(500).json({ status: 500, message: 'Internal Server Error' });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|