@@ -8,6 +8,7 @@ import paramsMiddleware from '../shared/assemble_params.js';
88import { InvalidRequest } from '../helpers/errors.js' ;
99import rejectStructuredTokens from '../shared/reject_structured_tokens.js' ;
1010import { checkAttestBinding } from '../helpers/check_attest_binding.js' ;
11+ import { createTokenFinder } from '../helpers/token_find.js' ;
1112
1213const introspectable = new Set ( [ 'AccessToken' , 'ClientCredentials' , 'RefreshToken' ] ) ;
1314const JWT = 'application/token-introspection+jwt' ;
@@ -26,30 +27,10 @@ export default function introspectionAction(provider) {
2627 } = configuration ;
2728 const { grantTypeHandlers } = instance ( provider ) ;
2829 const {
29- IdToken, AccessToken , ClientCredentials , RefreshToken , Client,
30+ IdToken, Client,
3031 } = provider ;
3132
32- function getAccessToken ( token ) {
33- return AccessToken . find ( token ) ;
34- }
35-
36- function getClientCredentials ( token ) {
37- if ( ! grantTypeHandlers . has ( 'client_credentials' ) ) {
38- return undefined ;
39- }
40- return ClientCredentials . find ( token ) ;
41- }
42-
43- function getRefreshToken ( token ) {
44- if ( ! grantTypeHandlers . has ( 'refresh_token' ) ) {
45- return undefined ;
46- }
47- return RefreshToken . find ( token ) ;
48- }
49-
50- function findResult ( results ) {
51- return results . find ( ( found ) => ! ! found ) ;
52- }
33+ const findToken = createTokenFinder ( provider , grantTypeHandlers ) ;
5334
5435 return [
5536 noCache ,
@@ -101,32 +82,7 @@ export default function introspectionAction(provider) {
10182
10283 ctx . body = { active : false } ;
10384
104- let token ;
105- switch ( params . token_type_hint ) {
106- case 'access_token' :
107- case 'urn:ietf:params:oauth:token-type:access_token' :
108- token = await Promise . all ( [
109- getAccessToken ( params . token ) ,
110- getClientCredentials ( params . token ) ,
111- ] )
112- . then ( findResult )
113- . then ( ( result ) => result || getRefreshToken ( params . token ) ) ;
114- break ;
115- case 'refresh_token' :
116- case 'urn:ietf:params:oauth:token-type:refresh_token' :
117- token = await getRefreshToken ( params . token )
118- . then ( ( result ) => result || Promise . all ( [
119- getAccessToken ( params . token ) ,
120- getClientCredentials ( params . token ) ,
121- ] ) . then ( findResult ) ) ;
122- break ;
123- default :
124- token = await Promise . all ( [
125- getAccessToken ( params . token ) ,
126- getClientCredentials ( params . token ) ,
127- getRefreshToken ( params . token ) ,
128- ] ) . then ( findResult ) ;
129- }
85+ const token = await findToken ( params . token , params . token_type_hint ) ;
13086
13187 if ( ! token ?. isValid ) {
13288 return ;
0 commit comments