@@ -12,6 +12,8 @@ export type CommonCredentials = {
12
12
clientId : string ;
13
13
/** The endpoint of the OIDC IdP to authenticate against, ex. 'https://virtru.com/auth' */
14
14
oidcOrigin : string ;
15
+ oidcTokenEndpoint ?: string ;
16
+ oidcUserInfoEndpoint ?: string ;
15
17
/** Whether or not DPoP is enabled. */
16
18
dpopEnabled ?: boolean ;
17
19
@@ -89,6 +91,8 @@ export class AccessToken {
89
91
data ?: AccessTokenResponse ;
90
92
91
93
baseUrl : string ;
94
+ tokenEndpoint : string ;
95
+ userInfoEndpoint : string ;
92
96
93
97
signingKey ?: CryptoKeyPair ;
94
98
@@ -119,6 +123,9 @@ export class AccessToken {
119
123
this . config = cfg ;
120
124
this . request = request ;
121
125
this . baseUrl = rstrip ( cfg . oidcOrigin , '/' ) ;
126
+ this . tokenEndpoint = cfg . oidcTokenEndpoint || `${ this . baseUrl } /protocol/openid-connect/token` ;
127
+ this . userInfoEndpoint =
128
+ cfg . oidcUserInfoEndpoint || `${ this . baseUrl } /protocol/openid-connect/userinfo` ;
122
129
this . signingKey = cfg . signingKey ;
123
130
}
124
131
@@ -128,21 +135,20 @@ export class AccessToken {
128
135
* @returns
129
136
*/
130
137
async info ( accessToken : string ) : Promise < unknown > {
131
- const url = `${ this . baseUrl } /protocol/openid-connect/userinfo` ;
132
138
const headers = {
133
139
...this . extraHeaders ,
134
140
Authorization : `Bearer ${ accessToken } ` ,
135
141
} as Record < string , string > ;
136
142
if ( this . config . dpopEnabled && this . signingKey ) {
137
- headers . DPoP = await dpopFn ( this . signingKey , url , 'POST' ) ;
143
+ headers . DPoP = await dpopFn ( this . signingKey , this . userInfoEndpoint , 'POST' ) ;
138
144
}
139
- const response = await ( this . request || fetch ) ( url , {
145
+ const response = await ( this . request || fetch ) ( this . userInfoEndpoint , {
140
146
headers,
141
147
} ) ;
142
148
if ( ! response . ok ) {
143
149
console . error ( await response . text ( ) ) ;
144
150
throw new TdfError (
145
- `auth info fail: GET [${ url } ] => ${ response . status } ${ response . statusText } `
151
+ `auth info fail: GET [${ this . userInfoEndpoint } ] => ${ response . status } ${ response . statusText } `
146
152
) ;
147
153
}
148
154
@@ -171,7 +177,6 @@ export class AccessToken {
171
177
}
172
178
173
179
async accessTokenLookup ( cfg : OIDCCredentials ) {
174
- const url = `${ this . baseUrl } /protocol/openid-connect/token` ;
175
180
let body ;
176
181
switch ( cfg . exchange ) {
177
182
case 'client' :
@@ -198,11 +203,11 @@ export class AccessToken {
198
203
} ;
199
204
break ;
200
205
}
201
- const response = await this . doPost ( url , body ) ;
206
+ const response = await this . doPost ( this . tokenEndpoint , body ) ;
202
207
if ( ! response . ok ) {
203
208
console . error ( await response . text ( ) ) ;
204
209
throw new TdfError (
205
- `token/code exchange fail: POST [${ url } ] => ${ response . status } ${ response . statusText } `
210
+ `token/code exchange fail: POST [${ this . tokenEndpoint } ] => ${ response . status } ${ response . statusText } `
206
211
) ;
207
212
}
208
213
return response . json ( ) ;
0 commit comments