deno.land / x / oauth4webapi@v1.2.2 / tap / helper.ts

helper.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import * as lib from '../src/index.js'import * as jose from 'jose'
function url(pathname: string, search?: Record<string, string>) { const target = new URL(pathname, 'https://obscure-mesa-34474.deno.dev') target.search = new URLSearchParams(search).toString() return target.href}
export default async function setup(): Promise<{ client: lib.Client accountsEndpoint: URL issuerIdentifier: URL clientPrivateKey: lib.PrivateKey exposed: () => Promise<Record<string, string>> cleanup: () => Promise<void>}> { const uuid = jose.base64url.encode(crypto.getRandomValues(new Uint8Array(16)))
const serverKey = { ...(await crypto.subtle.exportKey( 'jwk', ( await lib.generateKeyPair('ES256', { extractable: true }) ).privateKey, )), alg: 'ES256', use: 'sig', kid: jose.base64url.encode(crypto.getRandomValues(new Uint8Array(16))), key_ops: undefined, ext: undefined, }
const clientKeyPair = await lib.generateKeyPair('ES256') const clientJwk = { ...(await crypto.subtle.exportKey('jwk', clientKeyPair.publicKey)), alg: 'ES256', use: 'sig', kid: jose.base64url.encode(crypto.getRandomValues(new Uint8Array(16))), key_ops: undefined, ext: undefined, }
const scope = 'openid email' const redirect_uri = `https://rp.example.com/${uuid}/cb`
let response = await fetch( url('/api/plan', { planName: 'fapi2-advanced-id1-client-test-plan', variant: JSON.stringify({ client_auth_type: 'private_key_jwt', sender_constrain: 'dpop', fapi_client_type: 'oidc', fapi_profile: 'plain_fapi', fapi_request_method: 'signed_non_repudiation', fapi_response_mode: 'jarm', }), }), { method: 'POST', headers: { 'content-type': 'application/json;charset=utf-8' }, body: JSON.stringify({ alias: uuid, client: { client_id: uuid, token_endpoint_auth_method: 'private_key_jwt', scope, redirect_uri, id_token_signed_response_alg: 'ES256', jwks: { keys: [clientJwk], }, }, waitTimeoutSeconds: 2, server: { jwks: { keys: [serverKey], }, }, }), }, )
if (response.status !== 201) { throw new Error(await response.text()) }
const plan = await response.json()
response = await fetch( url('/api/runner', { test: 'fapi2-baseline-id2-client-test-happy-path', plan: plan.id }), { method: 'POST', headers: { 'content-type': 'application/json;charset=utf-8' }, }, )
if (response.status !== 201) { throw new Error(await response.text()) }
const test = await response.json()
response = await fetch(url(`/api/runner/${test.id}`))
if (response.status !== 200) { throw new Error(await response.text()) }
const { exposed: { issuer, accounts_endpoint }, } = await response.json()
return { async exposed() { const response = await fetch(url(`/api/runner/${test.id}`)) if (response.status !== 200) { throw new Error(await response.text()) }
const { exposed } = await response.json() return exposed }, async cleanup() { await fetch(url(`/api/plan/${plan.id}`), { method: 'DELETE', }) }, client: { client_id: uuid, token_endpoint_auth_method: 'private_key_jwt', id_token_signed_response_alg: 'ES256', scope, redirect_uri, }, clientPrivateKey: { kid: clientJwk.kid, key: clientKeyPair.privateKey, }, issuerIdentifier: new URL(issuer), accountsEndpoint: new URL(accounts_endpoint), }}
oauth4webapi

Version Info

Tagged at
2 years ago