File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -502,6 +502,34 @@ export function extractWWWAuthenticateParams(res: Response): { resourceMetadataU
502502 } ;
503503}
504504
505+ /**
506+ * Extract resource_metadata from response header.
507+ * @deprecated Use `extractWWWAuthenticateParams` instead.
508+ */
509+ export function extractResourceMetadataUrl ( res : Response ) : URL | undefined {
510+ const authenticateHeader = res . headers . get ( 'WWW-Authenticate' ) ;
511+ if ( ! authenticateHeader ) {
512+ return undefined ;
513+ }
514+
515+ const [ type , scheme ] = authenticateHeader . split ( ' ' ) ;
516+ if ( type . toLowerCase ( ) !== 'bearer' || ! scheme ) {
517+ return undefined ;
518+ }
519+ const regex = / r e s o u r c e _ m e t a d a t a = " ( [ ^ " ] * ) " / ;
520+ const match = regex . exec ( authenticateHeader ) ;
521+
522+ if ( ! match ) {
523+ return undefined ;
524+ }
525+
526+ try {
527+ return new URL ( match [ 1 ] ) ;
528+ } catch {
529+ return undefined ;
530+ }
531+ }
532+
505533/**
506534 * Looks up RFC 9728 OAuth 2.0 Protected Resource Metadata.
507535 *
You can’t perform that action at this time.
0 commit comments