11import { createSolidTokenVerifier } from '@solid/access-token-verifier' ;
2- import { BadRequestHttpError } from '@solid/community-server' ;
2+ import { BadRequestHttpError , joinUrl } from '@solid/community-server' ;
33import { getLoggerFor } from 'global-logger-factory' ;
44import { createRemoteJWKSet , decodeJwt , JWTPayload , jwtVerify , JWTVerifyOptions } from 'jose' ;
55import { CLIENTID , WEBID } from '../Claims' ;
@@ -52,9 +52,10 @@ export class OidcVerifier implements Verifier {
5252 }
5353
5454 protected validateToken ( payload : JWTPayload ) : void {
55- if ( payload . aud !== this . baseUrl && ! ( Array . isArray ( payload . aud ) && payload . aud . includes ( this . baseUrl ) ) ) {
56- throw new BadRequestHttpError ( 'This server is not valid audience for the token' ) ;
57- }
55+ // TODO: disable audience check for now, need to investigate required values further
56+ // if (payload.aud !== this.baseUrl && !(Array.isArray(payload.aud) && payload.aud.includes(this.baseUrl))) {
57+ // throw new BadRequestHttpError('This server is not valid audience for the token');
58+ // }
5859 if ( ! payload . iss || this . allowedIssuers . length > 0 && ! this . allowedIssuers . includes ( payload . iss ) ) {
5960 throw new BadRequestHttpError ( 'Unsupported issuer' ) ;
6061 }
@@ -77,7 +78,16 @@ export class OidcVerifier implements Verifier {
7778
7879 protected async verifyStandardToken ( token : string , issuer : string ) :
7980 Promise < { [ WEBID ] : string , [ CLIENTID ] ?: string } > {
80- const jwkSet = createRemoteJWKSet ( new URL ( issuer ) ) ;
81+ const configUrl = joinUrl ( issuer , '/.well-known/openid-configuration' ) ;
82+ const configResponse = await fetch ( configUrl ) ;
83+ if ( configResponse . status !== 200 ) {
84+ throw new BadRequestHttpError ( `Unable to access ${ configUrl } ` ) ;
85+ }
86+ const config = await configResponse . json ( ) as { jwks_uri ?: string } ;
87+ if ( ! config . jwks_uri ) {
88+ throw new BadRequestHttpError ( `Missing jwks_uri from ${ configUrl } ` ) ;
89+ }
90+ const jwkSet = createRemoteJWKSet ( new URL ( config . jwks_uri ) ) ;
8191 const decoded = await jwtVerify ( token , jwkSet , this . verifyOptions ) ;
8292 if ( ! decoded . payload . sub ) {
8393 throw new BadRequestHttpError ( 'Invalid OIDC token: missing `sub` claim' ) ;
0 commit comments