oauth4webapi 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,7 +41,7 @@ import * as oauth2 from 'oauth4webapi'
41
41
  **`example`** Deno import
42
42
 
43
43
  ```js
44
- import * as oauth2 from 'https://deno.land/x/oauth4webapi@v2.4.0/mod.ts'
44
+ import * as oauth2 from 'https://deno.land/x/oauth4webapi@v2.4.1/mod.ts'
45
45
  ```
46
46
 
47
47
  - Authorization Code Flow - OpenID Connect [source](examples/code.ts), or plain OAuth 2 [source](examples/oauth.ts)
package/build/index.d.ts CHANGED
@@ -1,9 +1,13 @@
1
- type JsonObject = {
1
+ /** JSON Object */
2
+ export type JsonObject = {
2
3
  [Key in string]?: JsonValue;
3
4
  };
4
- type JsonArray = JsonValue[];
5
- type JsonPrimitive = string | number | boolean | null;
6
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
5
+ /** JSON Array */
6
+ export type JsonArray = JsonValue[];
7
+ /** JSON Primitives */
8
+ export type JsonPrimitive = string | number | boolean | null;
9
+ /** JSON Values */
10
+ export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
7
11
  /**
8
12
  * Interface to pass an asymmetric private key and, optionally, its associated JWK Key ID to be
9
13
  * added as a `kid` JOSE Header Parameter.
@@ -45,7 +49,9 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
45
49
  /**
46
50
  * Supported JWS `alg` Algorithm identifiers.
47
51
  *
48
- * @example CryptoKey algorithm for the `PS256`, `PS384`, or `PS512` JWS Algorithm Identifiers
52
+ * @example
53
+ *
54
+ * CryptoKey algorithm for the `PS256`, `PS384`, or `PS512` JWS Algorithm Identifiers
49
55
  *
50
56
  * ```ts
51
57
  * interface PS256 extends RsaHashedKeyAlgorithm {
@@ -64,7 +70,9 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
64
70
  * }
65
71
  * ```
66
72
  *
67
- * @example CryptoKey algorithm for the `ES256`, `ES384`, or `ES512` JWS Algorithm Identifiers
73
+ * @example
74
+ *
75
+ * CryptoKey algorithm for the `ES256`, `ES384`, or `ES512` JWS Algorithm Identifiers
68
76
  *
69
77
  * ```ts
70
78
  * interface ES256 extends EcKeyAlgorithm {
@@ -83,7 +91,9 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
83
91
  * }
84
92
  * ```
85
93
  *
86
- * @example CryptoKey algorithm for the `RS256`, `RS384`, or `RS512` JWS Algorithm Identifiers
94
+ * @example
95
+ *
96
+ * CryptoKey algorithm for the `RS256`, `RS384`, or `RS512` JWS Algorithm Identifiers
87
97
  *
88
98
  * ```ts
89
99
  * interface RS256 extends RsaHashedKeyAlgorithm {
@@ -102,9 +112,11 @@ export type ClientAuthenticationMethod = 'client_secret_basic' | 'client_secret_
102
112
  * }
103
113
  * ```
104
114
  *
105
- * @example CryptoKey algorithm for the `EdDSA` JWS Algorithm Identifier (Experimental)
115
+ * @example
106
116
  *
107
- * Runtime support for this algorithm is very limited, it depends on the [Secure Curves in the Web
117
+ * CryptoKey algorithm for the `EdDSA` JWS Algorithm Identifier (Experimental)
118
+ *
119
+ * Runtime support for this algorithm is limited, it depends on the [Secure Curves in the Web
108
120
  * Cryptography API](https://wicg.github.io/webcrypto-secure-curves/) proposal which is yet to be
109
121
  * widely adopted. If the proposal changes this implementation will follow up with a minor release.
110
122
  *
@@ -473,7 +485,7 @@ export interface Client {
473
485
  *
474
486
  * @ignore during Documentation generation but part of the public API
475
487
  *
476
- * @example Tolerate 30 seconds clock skew when validating JWT claims like `exp` or `nbf`.
488
+ * @example Tolerate 30 seconds clock skew when validating JWT claims like exp or nbf.
477
489
  *
478
490
  * ```ts
479
491
  * const client: oauth.Client = {
@@ -486,9 +498,11 @@ export interface Client {
486
498
  [clockTolerance]?: number;
487
499
  [metadata: string]: JsonValue | undefined;
488
500
  }
501
+ /** @group Errors */
489
502
  export declare class UnsupportedOperationError extends Error {
490
503
  constructor(message?: string);
491
504
  }
505
+ /** @group Errors */
492
506
  export declare class OperationProcessingError extends Error {
493
507
  constructor(message: string, options?: {
494
508
  cause?: unknown;
@@ -499,7 +513,9 @@ export interface HttpRequestOptions {
499
513
  * An AbortSignal instance, or a factory returning one, to abort the HTTP Request(s) triggered by
500
514
  * this function's invocation.
501
515
  *
502
- * @example A 5000ms timeout AbortSignal for every request
516
+ * @example
517
+ *
518
+ * A 5000ms timeout AbortSignal for every request
503
519
  *
504
520
  * ```js
505
521
  * const signal = () => AbortSignal.timeout(5_000) // Note: AbortSignal.timeout may not yet be available in all runtimes.
@@ -526,6 +542,9 @@ export interface DiscoveryRequestOptions extends HttpRequestOptions {
526
542
  *
527
543
  * @param issuerIdentifier Issuer Identifier to resolve the well-known discovery URI for.
528
544
  *
545
+ * @group Authorization Server Metadata
546
+ * @group OpenID Connect (OIDC) Discovery
547
+ *
529
548
  * @see [RFC 8414 - OAuth 2.0 Authorization Server Metadata](https://www.rfc-editor.org/rfc/rfc8414.html#section-3)
530
549
  * @see [OpenID Connect Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig)
531
550
  */
@@ -539,6 +558,9 @@ export declare function discoveryRequest(issuerIdentifier: URL, options?: Discov
539
558
  *
540
559
  * @returns Resolves with the discovered Authorization Server Metadata.
541
560
  *
561
+ * @group Authorization Server Metadata
562
+ * @group OpenID Connect (OIDC) Discovery
563
+ *
542
564
  * @see [RFC 8414 - OAuth 2.0 Authorization Server Metadata](https://www.rfc-editor.org/rfc/rfc8414.html#section-3)
543
565
  * @see [OpenID Connect Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig)
544
566
  */
@@ -546,18 +568,27 @@ export declare function processDiscoveryResponse(expectedIssuerIdentifier: URL,
546
568
  /**
547
569
  * Generate random `code_verifier` value.
548
570
  *
571
+ * @group Utilities
572
+ * @group Authorization Code Grant
573
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
574
+ * @group Proof Key for Code Exchange by OAuth Public Clients (PKCE)
575
+ *
549
576
  * @see [RFC 7636 - Proof Key for Code Exchange by OAuth Public Clients (PKCE)](https://www.rfc-editor.org/rfc/rfc7636.html#section-4)
550
577
  */
551
578
  export declare function generateRandomCodeVerifier(): string;
552
579
  /**
553
580
  * Generate random `state` value.
554
581
  *
582
+ * @group Utilities
583
+ *
555
584
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1.1)
556
585
  */
557
586
  export declare function generateRandomState(): string;
558
587
  /**
559
588
  * Generate random `nonce` value.
560
589
  *
590
+ * @group Utilities
591
+ *
561
592
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#IDToken)
562
593
  */
563
594
  export declare function generateRandomNonce(): string;
@@ -567,6 +598,10 @@ export declare function generateRandomNonce(): string;
567
598
  *
568
599
  * @param codeVerifier `code_verifier` value generated e.g. from {@link generateRandomCodeVerifier}.
569
600
  *
601
+ * @group Authorization Code Grant
602
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
603
+ * @group Proof Key for Code Exchange by OAuth Public Clients (PKCE)
604
+ *
570
605
  * @see [RFC 7636 - Proof Key for Code Exchange by OAuth Public Clients (PKCE)](https://www.rfc-editor.org/rfc/rfc7636.html#section-4)
571
606
  */
572
607
  export declare function calculatePKCECodeChallenge(codeVerifier: string): Promise<string>;
@@ -607,6 +642,10 @@ export interface PushedAuthorizationRequestOptions extends HttpRequestOptions, A
607
642
  * @param client Client Metadata.
608
643
  * @param privateKey Private key to sign the Request Object with.
609
644
  *
645
+ * @group Authorization Code Grant
646
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
647
+ * @group JWT-Secured Authorization Request (JAR)
648
+ *
610
649
  * @see [RFC 9101 - The OAuth 2.0 Authorization Framework: JWT-Secured Authorization Request (JAR)](https://www.rfc-editor.org/rfc/rfc9101.html#name-request-object-2)
611
650
  */
612
651
  export declare function issueRequestObject(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], privateKey: CryptoKey | PrivateKey): Promise<string>;
@@ -618,7 +657,9 @@ export declare function issueRequestObject(as: AuthorizationServer, client: Clie
618
657
  * @param client Client Metadata.
619
658
  * @param parameters Authorization Request parameters.
620
659
  *
621
- * @see [RFC 9126 - OAuth 2.0 Pushed Authorization Requests](https://www.rfc-editor.org/rfc/rfc9126.html#name-pushed-authorization-reques)
660
+ * @group Pushed Authorization Requests (PAR)
661
+ *
662
+ * @see [RFC 9126 - OAuth 2.0 Pushed Authorization Requests (PAR)](https://www.rfc-editor.org/rfc/rfc9126.html#name-pushed-authorization-reques)
622
663
  * @see [RFC 9449 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.rfc-editor.org/rfc/rfc9449.html#name-dpop-with-pushed-authorizat)
623
664
  */
624
665
  export declare function pushedAuthorizationRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], options?: PushedAuthorizationRequestOptions): Promise<Response>;
@@ -635,7 +676,19 @@ export interface OAuth2Error {
635
676
  readonly scope?: string;
636
677
  readonly [parameter: string]: JsonValue | undefined;
637
678
  }
638
- /** A helper function used to determine if a response processing function returned an OAuth2Error. */
679
+ /**
680
+ * A helper function used to determine if a response processing function returned an OAuth2Error.
681
+ *
682
+ * @group Utilities
683
+ * @group Client Credentials Grant
684
+ * @group Device Authorization Grant
685
+ * @group Authorization Code Grant
686
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
687
+ * @group Token Introspection
688
+ * @group Token Revocation
689
+ * @group Refreshing an Access Token
690
+ * @group Pushed Authorization Requests (PAR)
691
+ */
639
692
  export declare function isOAuth2Error(input?: ReturnTypes): input is OAuth2Error;
640
693
  export interface WWWAuthenticateChallengeParameters {
641
694
  readonly realm?: string;
@@ -645,11 +698,11 @@ export interface WWWAuthenticateChallengeParameters {
645
698
  readonly algs?: string;
646
699
  readonly scope?: string;
647
700
  /** NOTE: because the parameter names are case insensitive they are always returned lowercased */
648
- readonly [parameter: string]: string | undefined;
701
+ readonly [parameter: Lowercase<string>]: string | undefined;
649
702
  }
650
703
  export interface WWWAuthenticateChallenge {
651
704
  /** NOTE: because the value is case insensitive it is always returned lowercased */
652
- readonly scheme: string;
705
+ readonly scheme: Lowercase<string>;
653
706
  readonly parameters: WWWAuthenticateChallengeParameters;
654
707
  }
655
708
  /**
@@ -657,6 +710,17 @@ export interface WWWAuthenticateChallenge {
657
710
  *
658
711
  * @returns Array of {@link WWWAuthenticateChallenge} objects. Their order from the response is
659
712
  * preserved. `undefined` when there wasn't a `WWW-Authenticate` HTTP Header returned.
713
+ *
714
+ * @group Accessing Protected Resources
715
+ * @group Utilities
716
+ * @group Client Credentials Grant
717
+ * @group Device Authorization Grant
718
+ * @group Authorization Code Grant
719
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
720
+ * @group Token Introspection
721
+ * @group Token Revocation
722
+ * @group Refreshing an Access Token
723
+ * @group Pushed Authorization Requests (PAR)
660
724
  */
661
725
  export declare function parseWwwAuthenticateChallenges(response: Response): WWWAuthenticateChallenge[] | undefined;
662
726
  /**
@@ -671,7 +735,9 @@ export declare function parseWwwAuthenticateChallenges(response: Response): WWWA
671
735
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
672
736
  * OAuth 2.0 error was returned.
673
737
  *
674
- * @see [RFC 9126 - OAuth 2.0 Pushed Authorization Requests](https://www.rfc-editor.org/rfc/rfc9126.html#name-pushed-authorization-reques)
738
+ * @group Pushed Authorization Requests (PAR)
739
+ *
740
+ * @see [RFC 9126 - OAuth 2.0 Pushed Authorization Requests (PAR)](https://www.rfc-editor.org/rfc/rfc9126.html#name-pushed-authorization-reques)
675
741
  */
676
742
  export declare function processPushedAuthorizationResponse(as: AuthorizationServer, client: Client, response: Response): Promise<PushedAuthorizationResponse | OAuth2Error>;
677
743
  export interface ProtectedResourceRequestOptions extends Omit<HttpRequestOptions, 'headers'>, DPoPRequestOptions {
@@ -697,6 +763,8 @@ export interface ProtectedResourceRequestOptions extends Omit<HttpRequestOptions
697
763
  * @param headers Headers for the request.
698
764
  * @param body Request body compatible with the Fetch API and the request's method.
699
765
  *
766
+ * @group Accessing Protected Resources
767
+ *
700
768
  * @see [RFC 6750 - The OAuth 2.0 Authorization Framework: Bearer Token Usage](https://www.rfc-editor.org/rfc/rfc6750.html#section-2.1)
701
769
  * @see [RFC 9449 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.rfc-editor.org/rfc/rfc9449.html#name-protected-resource-access)
702
770
  */
@@ -713,6 +781,9 @@ export interface UserInfoRequestOptions extends HttpRequestOptions, DPoPRequestO
713
781
  * @param client Client Metadata.
714
782
  * @param accessToken Access Token value.
715
783
  *
784
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
785
+ * @group OpenID Connect (OIDC) UserInfo
786
+ *
716
787
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
717
788
  * @see [RFC 9449 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.rfc-editor.org/rfc/rfc9449.html#name-protected-resource-access)
718
789
  */
@@ -772,6 +843,9 @@ export declare const skipSubjectCheck: unique symbol;
772
843
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
773
844
  * OAuth 2.0 error was returned.
774
845
  *
846
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
847
+ * @group OpenID Connect (OIDC) UserInfo
848
+ *
775
849
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
776
850
  */
777
851
  export declare function processUserInfoResponse(as: AuthorizationServer, client: Client, expectedSubject: string | typeof skipSubjectCheck, response: Response): Promise<UserInfoResponse>;
@@ -787,6 +861,8 @@ export interface TokenEndpointRequestOptions extends HttpRequestOptions, Authent
787
861
  * @param client Client Metadata.
788
862
  * @param refreshToken Refresh Token value.
789
863
  *
864
+ * @group Refreshing an Access Token
865
+ *
790
866
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-6)
791
867
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#RefreshTokens)
792
868
  * @see [RFC 9449 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.rfc-editor.org/rfc/rfc9449.html#name-dpop-access-token-request)
@@ -798,6 +874,8 @@ export declare function refreshTokenGrantRequest(as: AuthorizationServer, client
798
874
  * @param ref Value previously resolved from {@link processAuthorizationCodeOpenIDResponse}.
799
875
  *
800
876
  * @returns JWT Claims Set from an ID Token.
877
+ *
878
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
801
879
  */
802
880
  export declare function getValidatedIdTokenClaims(ref: OpenIDTokenEndpointResponse): IDToken;
803
881
  /**
@@ -822,6 +900,8 @@ export declare function getValidatedIdTokenClaims(ref: TokenEndpointResponse): I
822
900
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
823
901
  * OAuth 2.0 error was returned.
824
902
  *
903
+ * @group Refreshing an Access Token
904
+ *
825
905
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-6)
826
906
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#RefreshTokens)
827
907
  */
@@ -837,6 +917,9 @@ export declare function processRefreshTokenResponse(as: AuthorizationServer, cli
837
917
  * @param redirectUri `redirect_uri` value used in the authorization request.
838
918
  * @param codeVerifier PKCE `code_verifier` to send to the token endpoint.
839
919
  *
920
+ * @group Authorization Code Grant
921
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
922
+ *
840
923
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1)
841
924
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth)
842
925
  * @see [RFC 7636 - Proof Key for Code Exchange by OAuth Public Clients (PKCE)](https://www.rfc-editor.org/rfc/rfc7636.html#section-4)
@@ -870,7 +953,7 @@ export interface TokenEndpointResponse {
870
953
  readonly refresh_token?: string;
871
954
  readonly scope?: string;
872
955
  /** NOTE: because the value is case insensitive it is always returned lowercased */
873
- readonly token_type: string;
956
+ readonly token_type: 'bearer' | 'dpop' | Lowercase<string>;
874
957
  readonly [parameter: string]: JsonValue | undefined;
875
958
  }
876
959
  export interface OpenIDTokenEndpointResponse {
@@ -880,7 +963,7 @@ export interface OpenIDTokenEndpointResponse {
880
963
  readonly refresh_token?: string;
881
964
  readonly scope?: string;
882
965
  /** NOTE: because the value is case insensitive it is always returned lowercased */
883
- readonly token_type: string;
966
+ readonly token_type: 'bearer' | 'dpop' | Lowercase<string>;
884
967
  readonly [parameter: string]: JsonValue | undefined;
885
968
  }
886
969
  export interface OAuth2TokenEndpointResponse {
@@ -890,7 +973,7 @@ export interface OAuth2TokenEndpointResponse {
890
973
  readonly refresh_token?: string;
891
974
  readonly scope?: string;
892
975
  /** NOTE: because the value is case insensitive it is always returned lowercased */
893
- readonly token_type: string;
976
+ readonly token_type: 'bearer' | 'dpop' | Lowercase<string>;
894
977
  readonly [parameter: string]: JsonValue | undefined;
895
978
  }
896
979
  export interface ClientCredentialsGrantResponse {
@@ -898,7 +981,7 @@ export interface ClientCredentialsGrantResponse {
898
981
  readonly expires_in?: number;
899
982
  readonly scope?: string;
900
983
  /** NOTE: because the value is case insensitive it is always returned lowercased */
901
- readonly token_type: string;
984
+ readonly token_type: 'bearer' | 'dpop' | Lowercase<string>;
902
985
  readonly [parameter: string]: JsonValue | undefined;
903
986
  }
904
987
  /**
@@ -930,6 +1013,8 @@ export declare const skipAuthTimeCheck: unique symbol;
930
1013
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
931
1014
  * OAuth 2.0 error was returned.
932
1015
  *
1016
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
1017
+ *
933
1018
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1)
934
1019
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth)
935
1020
  */
@@ -946,6 +1031,8 @@ export declare function processAuthorizationCodeOpenIDResponse(as: Authorization
946
1031
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
947
1032
  * OAuth 2.0 error was returned.
948
1033
  *
1034
+ * @group Authorization Code Grant
1035
+ *
949
1036
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1)
950
1037
  */
951
1038
  export declare function processAuthorizationCodeOAuth2Response(as: AuthorizationServer, client: Client, response: Response): Promise<OAuth2TokenEndpointResponse | OAuth2Error>;
@@ -958,6 +1045,8 @@ export interface ClientCredentialsGrantRequestOptions extends HttpRequestOptions
958
1045
  * @param as Authorization Server Metadata.
959
1046
  * @param client Client Metadata.
960
1047
  *
1048
+ * @group Client Credentials Grant
1049
+ *
961
1050
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.4)
962
1051
  * @see [RFC 9449 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.rfc-editor.org/rfc/rfc9449.html#name-dpop-access-token-request)
963
1052
  */
@@ -974,6 +1063,8 @@ export declare function clientCredentialsGrantRequest(as: AuthorizationServer, c
974
1063
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
975
1064
  * OAuth 2.0 error was returned.
976
1065
  *
1066
+ * @group Client Credentials Grant
1067
+ *
977
1068
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.4)
978
1069
  */
979
1070
  export declare function processClientCredentialsResponse(as: AuthorizationServer, client: Client, response: Response): Promise<ClientCredentialsGrantResponse | OAuth2Error>;
@@ -990,6 +1081,8 @@ export interface RevocationRequestOptions extends HttpRequestOptions, Authentica
990
1081
  * @param token Token to revoke. You can provide the `token_type_hint` parameter via
991
1082
  * {@link RevocationRequestOptions.additionalParameters options}.
992
1083
  *
1084
+ * @group Token Revocation
1085
+ *
993
1086
  * @see [RFC 7009 - OAuth 2.0 Token Revocation](https://www.rfc-editor.org/rfc/rfc7009.html#section-2)
994
1087
  */
995
1088
  export declare function revocationRequest(as: AuthorizationServer, client: Client, token: string, options?: RevocationRequestOptions): Promise<Response>;
@@ -1002,6 +1095,8 @@ export declare function revocationRequest(as: AuthorizationServer, client: Clien
1002
1095
  * @returns Resolves with `undefined` when the request was successful, or an object representing an
1003
1096
  * OAuth 2.0 protocol style error.
1004
1097
  *
1098
+ * @group Token Revocation
1099
+ *
1005
1100
  * @see [RFC 7009 - OAuth 2.0 Token Revocation](https://www.rfc-editor.org/rfc/rfc7009.html#section-2)
1006
1101
  */
1007
1102
  export declare function processRevocationResponse(response: Response): Promise<undefined | OAuth2Error>;
@@ -1028,6 +1123,8 @@ export interface IntrospectionRequestOptions extends HttpRequestOptions, Authent
1028
1123
  * @param token Token to introspect. You can provide the `token_type_hint` parameter via
1029
1124
  * {@link IntrospectionRequestOptions.additionalParameters options}.
1030
1125
  *
1126
+ * @group Token Introspection
1127
+ *
1031
1128
  * @see [RFC 7662 - OAuth 2.0 Token Introspection](https://www.rfc-editor.org/rfc/rfc7662.html#section-2)
1032
1129
  * @see [draft-ietf-oauth-jwt-introspection-response-12 - JWT Response for OAuth Token Introspection](https://www.ietf.org/archive/id/draft-ietf-oauth-jwt-introspection-response-12.html#section-4)
1033
1130
  */
@@ -1066,6 +1163,8 @@ export interface IntrospectionResponse {
1066
1163
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
1067
1164
  * OAuth 2.0 error was returned.
1068
1165
  *
1166
+ * @group Token Introspection
1167
+ *
1069
1168
  * @see [RFC 7662 - OAuth 2.0 Token Introspection](https://www.rfc-editor.org/rfc/rfc7662.html#section-2)
1070
1169
  * @see [draft-ietf-oauth-jwt-introspection-response-12 - JWT Response for OAuth Token Introspection](https://www.ietf.org/archive/id/draft-ietf-oauth-jwt-introspection-response-12.html#section-5)
1071
1170
  */
@@ -1080,6 +1179,10 @@ export declare function processIntrospectionResponse(as: AuthorizationServer, cl
1080
1179
  *
1081
1180
  * @returns Validated Authorization Response parameters or Authorization Error Response.
1082
1181
  *
1182
+ * @group Authorization Code Grant
1183
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
1184
+ * @group JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)
1185
+ *
1083
1186
  * @see [JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)](https://openid.net/specs/openid-financial-api-jarm.html)
1084
1187
  */
1085
1188
  export declare function validateJwtAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck, options?: HttpRequestOptions): Promise<URLSearchParams | OAuth2Error>;
@@ -1111,6 +1214,9 @@ export declare const expectNoState: unique symbol;
1111
1214
  *
1112
1215
  * @returns Validated Authorization Response parameters or Authorization Error Response.
1113
1216
  *
1217
+ * @group Authorization Code Grant
1218
+ * @group Authorization Code Grant w/ OpenID Connect (OIDC)
1219
+ *
1114
1220
  * @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1.2)
1115
1221
  * @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication)
1116
1222
  * @see [RFC 9207 - OAuth 2.0 Authorization Server Issuer Identification](https://www.rfc-editor.org/rfc/rfc9207.html)
@@ -1127,6 +1233,8 @@ export interface DeviceAuthorizationRequestOptions extends HttpRequestOptions, A
1127
1233
  * @param client Client Metadata.
1128
1234
  * @param parameters Device Authorization Request parameters.
1129
1235
  *
1236
+ * @group Device Authorization Grant
1237
+ *
1130
1238
  * @see [RFC 8628 - OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628.html#section-3.1)
1131
1239
  */
1132
1240
  export declare function deviceAuthorizationRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], options?: DeviceAuthorizationRequestOptions): Promise<Response>;
@@ -1151,6 +1259,8 @@ export interface DeviceAuthorizationResponse {
1151
1259
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
1152
1260
  * OAuth 2.0 error was returned.
1153
1261
  *
1262
+ * @group Device Authorization Grant
1263
+ *
1154
1264
  * @see [RFC 8628 - OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628.html#section-3.1)
1155
1265
  */
1156
1266
  export declare function processDeviceAuthorizationResponse(as: AuthorizationServer, client: Client, response: Response): Promise<DeviceAuthorizationResponse | OAuth2Error>;
@@ -1162,6 +1272,8 @@ export declare function processDeviceAuthorizationResponse(as: AuthorizationServ
1162
1272
  * @param client Client Metadata.
1163
1273
  * @param deviceCode Device Code.
1164
1274
  *
1275
+ * @group Device Authorization Grant
1276
+ *
1165
1277
  * @see [RFC 8628 - OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628.html#section-3.4)
1166
1278
  * @see [RFC 9449 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.rfc-editor.org/rfc/rfc9449.html#name-dpop-access-token-request)
1167
1279
  */
@@ -1178,6 +1290,8 @@ export declare function deviceCodeGrantRequest(as: AuthorizationServer, client:
1178
1290
  * representing an OAuth 2.0 protocol style error. Use {@link isOAuth2Error} to determine if an
1179
1291
  * OAuth 2.0 error was returned.
1180
1292
  *
1293
+ * @group Device Authorization Grant
1294
+ *
1181
1295
  * @see [RFC 8628 - OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628.html#section-3.4)
1182
1296
  */
1183
1297
  export declare function processDeviceCodeResponse(as: AuthorizationServer, client: Client, response: Response): Promise<TokenEndpointResponse | OAuth2Error>;
@@ -1193,6 +1307,8 @@ export interface GenerateKeyPairOptions {
1193
1307
  * Generates a CryptoKeyPair for a given JWS `alg` Algorithm identifier.
1194
1308
  *
1195
1309
  * @param alg Supported JWS `alg` Algorithm identifier.
1310
+ *
1311
+ * @group Utilities
1196
1312
  */
1197
1313
  export declare function generateKeyPair(alg: JWSAlgorithm, options?: GenerateKeyPairOptions): Promise<CryptoKeyPair>;
1198
1314
  export {};
package/build/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  let USER_AGENT;
2
2
  if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
3
3
  const NAME = 'oauth4webapi';
4
- const VERSION = 'v2.4.0';
4
+ const VERSION = 'v2.4.1';
5
5
  USER_AGENT = `${NAME}/${VERSION}`;
6
6
  }
7
7
  export const clockSkew = Symbol();
@@ -194,12 +194,13 @@ export async function discoveryRequest(issuerIdentifier, options) {
194
194
  }
195
195
  const headers = prepareHeaders(options?.headers);
196
196
  headers.set('accept', 'application/json');
197
- return fetch(url.href, {
197
+ const request = new Request(url.href, {
198
198
  headers,
199
199
  method: 'GET',
200
200
  redirect: 'manual',
201
201
  signal: options?.signal ? signal(options.signal) : null,
202
- }).then(processDpopNonce);
202
+ });
203
+ return fetch(request).then(processDpopNonce);
203
204
  }
204
205
  function validateString(input) {
205
206
  return typeof input === 'string' && input.length !== 0;
@@ -654,13 +655,14 @@ export async function protectedResourceRequest(accessToken, method, url, headers
654
655
  await dpopProofJwt(headers, options.DPoP, url, 'GET', getClockSkew({ [clockSkew]: options?.clockSkew }), accessToken);
655
656
  headers.set('authorization', `DPoP ${accessToken}`);
656
657
  }
657
- return fetch(url.href, {
658
+ const request = new Request(url.href, {
658
659
  body,
659
660
  headers,
660
661
  method,
661
662
  redirect: 'manual',
662
663
  signal: options?.signal ? signal(options.signal) : null,
663
- }).then(processDpopNonce);
664
+ });
665
+ return fetch(request).then(processDpopNonce);
664
666
  }
665
667
  export async function userInfoRequest(as, client, accessToken, options) {
666
668
  assertAs(as);
@@ -820,13 +822,14 @@ export async function processUserInfoResponse(as, client, expectedSubject, respo
820
822
  async function authenticatedRequest(as, client, method, url, body, headers, options) {
821
823
  await clientAuthentication(as, client, body, headers, options?.clientPrivateKey);
822
824
  headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
823
- return fetch(url.href, {
825
+ const request = new Request(url.href, {
824
826
  body,
825
827
  headers,
826
828
  method,
827
829
  redirect: 'manual',
828
830
  signal: options?.signal ? signal(options.signal) : null,
829
- }).then(processDpopNonce);
831
+ });
832
+ return fetch(request).then(processDpopNonce);
830
833
  }
831
834
  async function tokenEndpointRequest(as, client, grantType, parameters, options) {
832
835
  if (typeof as.token_endpoint !== 'string') {
@@ -1186,12 +1189,13 @@ async function jwksRequest(as, options) {
1186
1189
  const headers = prepareHeaders(options?.headers);
1187
1190
  headers.set('accept', 'application/json');
1188
1191
  headers.append('accept', 'application/jwk-set+json');
1189
- return fetch(url.href, {
1192
+ const request = new Request(url.href, {
1190
1193
  headers,
1191
1194
  method: 'GET',
1192
1195
  redirect: 'manual',
1193
1196
  signal: options?.signal ? signal(options.signal) : null,
1194
- }).then(processDpopNonce);
1197
+ });
1198
+ return fetch(request).then(processDpopNonce);
1195
1199
  }
1196
1200
  async function processJwksResponse(response) {
1197
1201
  if (!(response instanceof Response)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth4webapi",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "OAuth 2 / OpenID Connect for JavaScript Runtimes",
5
5
  "keywords": [
6
6
  "auth",
@@ -63,22 +63,22 @@
63
63
  "test": "bash -c 'source .node_flags.sh && ava'"
64
64
  },
65
65
  "devDependencies": {
66
- "@esbuild-kit/esm-loader": "^2.6.5",
67
- "@types/node": "^20.9.0",
68
- "@types/qunit": "^2.19.8",
66
+ "@types/node": "^20.10.6",
67
+ "@types/qunit": "^2.19.9",
69
68
  "ava": "^5.3.1",
70
69
  "edge-runtime": "^2.5.7",
71
- "esbuild": "^0.19.5",
72
- "jose": "^5.1.1",
70
+ "esbuild": "^0.19.11",
71
+ "jose": "^5.2.0",
73
72
  "patch-package": "^8.0.0",
74
- "prettier": "^3.1.0",
75
- "prettier-plugin-jsdoc": "^1.1.1",
73
+ "prettier": "^3.1.1",
74
+ "prettier-plugin-jsdoc": "^1.3.0",
76
75
  "qunit": "^2.20.0",
77
76
  "timekeeper": "^2.3.1",
78
- "typedoc": "^0.25.3",
77
+ "tsx": "^4.7.0",
78
+ "typedoc": "^0.25.6",
79
79
  "typedoc-plugin-markdown": "^3.17.1",
80
- "typedoc-plugin-mdn-links": "^3.1.0",
81
- "typescript": "^5.2.2",
82
- "undici": "^5.27.2"
80
+ "typedoc-plugin-mdn-links": "^3.1.10",
81
+ "typescript": "^5.3.3",
82
+ "undici": "^5.28.2"
83
83
  }
84
84
  }