@@ -104,101 +104,113 @@ axios
104104
105105### Customization hooks
106106
107- It also provides a convenient way, through event emitters, to programmatically customize the server processing. This is particularly useful when expecting the OIDC service to behave in a specific way on one single test:
107+ It also provides a convenient way, through event emitters, to programmatically customize the server processing. This is particularly useful when expecting the OIDC service to behave in a specific way on one single test.
108108
109- - The JWT access token
109+ #### beforeTokenSigning
110110
111- ``` js
112- // Modify the expiration time on next token produced
113- service .once (' beforeTokenSigning' , (token , req ) => {
114- const timestamp = Math .floor (Date .now () / 1000 );
115- token .payload .exp = timestamp + 400 ;
116- });
117- ```
111+ Typed signature: ` (token: MutableToken, req: TokenRequestIncomingMessage) => void `
118112
119- ``` js
120- const basicAuth = require (' basic-auth' );
113+ ``` js
114+ // Modify the expiration time on next produced token
115+ service .once (' beforeTokenSigning' , (token , req ) => {
116+ const timestamp = Math .floor (Date .now () / 1000 );
117+ token .payload .exp = timestamp + 400 ;
118+ });
119+ ```
121120
122- // Add the client ID to a token
123- service .once (' beforeTokenSigning' , (token , req ) => {
124- const credentials = basicAuth (req);
125- const clientId = credentials ? credentials .name : req .body .client_id ;
126- token .payload .client_id = clientId;
127- });
128- ```
129-
130- - The token endpoint response body and status
131-
132- ``` js
133- // Force the oidc service to provide an invalid_grant response
134- // on next call to the token endpoint
135- service .once (' beforeResponse' , (tokenEndpointResponse , req ) => {
136- tokenEndpointResponse .body = {
137- error: ' invalid_grant' ,
138- };
139- tokenEndpointResponse .statusCode = 400 ;
140- });
141- ```
142-
143- - The userinfo endpoint response body and status
144-
145- ``` js
146- // Force the oidc service to provide an error
147- // on next call to userinfo endpoint
148- service .once (' beforeUserinfo' , (userInfoResponse , req ) => {
149- userInfoResponse .body = {
150- error: ' invalid_token' ,
151- error_message: ' token is expired' ,
152- };
153- userInfoResponse .statusCode = 401 ;
154- });
155- ```
121+ ``` js
122+ const basicAuth = require (' basic-auth' );
156123
157- - The revoke endpoint response body and status
124+ // Add the client ID to a token
125+ service .once (' beforeTokenSigning' , (token , req ) => {
126+ const credentials = basicAuth (req);
127+ const clientId = credentials ? credentials .name : req .body .client_id ;
128+ token .payload .client_id = clientId;
129+ });
130+ ```
158131
159- ``` js
160- // Simulates a custom token revocation body
161- service .once (' beforeRevoke' , (revokeResponse , req ) => {
162- revokeResponse .body = {
163- result: ' revoked' ,
164- };
165- });
166- ```
132+ #### beforeResponse
167133
168- - The authorization endpoint redirect uri and query parameters
134+ Typed signature: ` (tokenEndpointResponse: MutableResponse, req: TokenRequestIncomingMessage) => void `
169135
170- ``` js
171- // Modify the uri and query parameters
172- // before the authorization redirect
173- service .once (' beforeAuthorizeRedirect' , (authorizeRedirectUri , req ) => {
174- authorizeRedirectUri .url .searchParams .set (' foo' , ' bar' );
175- });
176- ```
136+ ``` js
137+ // Force the oidc service to provide an invalid_grant response
138+ // on next call to the token endpoint
139+ service .once (' beforeResponse' , (tokenEndpointResponse , req ) => {
140+ tokenEndpointResponse .body = {
141+ error: ' invalid_grant' ,
142+ };
143+ tokenEndpointResponse .statusCode = 400 ;
144+ });
145+ ```
177146
178- - The end session endpoint post logout redirect uri
147+ #### beforeUserinfo
179148
180- ``` js
181- // Modify the uri and query parameters
182- // before the post_logout_redirect_uri redirect
183- service .once (' beforePostLogoutRedirect' , (postLogoutRedirectUri , req ) => {
184- postLogoutRedirectUri .url .searchParams .set (' foo' , ' bar' );
185- });
186- ```
187-
188- - The introspect endpoint response body
189-
190- ``` js
191- // Simulate a custom token introspection response body
192- service .once (' beforeIntrospect' , (introspectResponse , req ) => {
193- introspectResponse .body = {
194- active: true ,
195- scope: ' read write email' ,
196- client_id: ' <client_id>' ,
197- username: ' dummy' ,
198- exp: 1643712575 ,
199- };
200- });
201- ```
149+ Typed signature: ` (userInfoResponse: MutableResponse, req: IncomingMessage) => void `
150+
151+ ``` js
152+ // Force the oidc service to provide an error
153+ // on next call to userinfo endpoint
154+ service .once (' beforeUserinfo' , (userInfoResponse , req ) => {
155+ userInfoResponse .body = {
156+ error: ' invalid_token' ,
157+ error_message: ' token is expired' ,
158+ };
159+ userInfoResponse .statusCode = 401 ;
160+ });
161+ ```
162+
163+ #### beforeRevoke
164+
165+ Typed signature: ` (revokeResponse: StatusCodeMutableResponse, req: IncomingMessage) => void `
166+
167+ ``` js
168+ // Simulates a custom token revocation result code
169+ service .once (' beforeRevoke' , (revokeResponse , req ) => {
170+ revokeResponse .statusCode = 418 ;
171+ });
172+ ```
173+
174+ #### beforeAuthorizeRedirect
175+
176+ Typed signature: ` (authorizeRedirectUri: MutableRedirectUri, req: IncomingMessage) => void `
177+
178+ ``` js
179+ // Modify the uri and query parameters
180+ // before the authorization redirect
181+ service .once (' beforeAuthorizeRedirect' , (authorizeRedirectUri , req ) => {
182+ authorizeRedirectUri .url .searchParams .set (' foo' , ' bar' );
183+ });
184+ ```
185+
186+ #### beforePostLogoutRedirect
187+
188+ Typed signature: ` (postLogoutRedirectUri: MutableRedirectUri, req: IncomingMessage) => void `
189+
190+ ``` js
191+ // Modify the uri and query parameters
192+ // before the post_logout_redirect_uri redirect
193+ service .once (' beforePostLogoutRedirect' , (postLogoutRedirectUri , req ) => {
194+ postLogoutRedirectUri .url .searchParams .set (' foo' , ' bar' );
195+ });
196+ ```
197+
198+ #### beforeIntrospect
199+
200+ Typed signature: ` (introspectResponse: MutableResponse, req: IncomingMessage) => void `
201+
202+ ``` js
203+ // Simulate a custom token introspection response body
204+ service .once (' beforeIntrospect' , (introspectResponse , req ) => {
205+ introspectResponse .body = {
206+ active: true ,
207+ scope: ' read write email' ,
208+ client_id: ' <client_id>' ,
209+ username: ' dummy' ,
210+ exp: 1643712575 ,
211+ };
212+ });
213+ ```
202214
203215### HTTPS support
204216
@@ -231,24 +243,24 @@ Issues access tokens.
231243
232244### GET ` /authorize `
233245
234- It simulates the user authentication. It will automatically redirect to the callback endpoint sent as parameter.
246+ Simulates the user authentication. It will automatically redirect to the callback endpoint sent as parameter.
235247It currently supports only 'code' response_type.
236248
237249### GET ` /userinfo `
238250
239- It provides extra userinfo claims.
251+ Provides extra userinfo claims.
240252
241253### POST ` /revoke `
242254
243- It simulates a token revocation. This endpoint should always return 200 as stated by [ RFC 7009] ( https://tools.ietf.org/html/rfc7009#section-2.2 ) .
255+ Simulates a token revocation. This endpoint should always return 200 as stated by [ RFC 7009] ( https://tools.ietf.org/html/rfc7009#section-2.2 ) .
244256
245257### GET ` /endsession `
246258
247- It simulates the end session endpoint. It will automatically redirect to the post_logout_redirect_uri sent as parameter.
259+ Simulates the end session endpoint. It will automatically redirect to the post_logout_redirect_uri sent as parameter.
248260
249261### POST ` /introspect `
250262
251- It simulates the [ token introspection endpoint] ( https://www.oauth.com/oauth2-servers/token-introspection-endpoint/ ) .
263+ Simulates the [ token introspection endpoint] ( https://www.oauth.com/oauth2-servers/token-introspection-endpoint/ ) .
252264
253265## Command-Line Interface
254266
0 commit comments