oauth4webapi 2.2.3 → 2.3.0
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 +1 -1
- package/build/index.d.ts +17 -19
- package/build/index.js +9 -15
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ import * as oauth2 from 'oauth4webapi'
|
|
|
39
39
|
**`example`** Deno import
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
|
-
import * as oauth2 from 'https://deno.land/x/oauth4webapi@v2.
|
|
42
|
+
import * as oauth2 from 'https://deno.land/x/oauth4webapi@v2.3.0/mod.ts'
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
- Authorization Code Flow - OpenID Connect [source](examples/code.ts), or plain OAuth 2 [source](examples/oauth.ts)
|
package/build/index.d.ts
CHANGED
|
@@ -613,7 +613,7 @@ export interface PushedAuthorizationRequestOptions extends HttpRequestOptions, A
|
|
|
613
613
|
*
|
|
614
614
|
* @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)
|
|
615
615
|
*/
|
|
616
|
-
export declare function issueRequestObject(as: AuthorizationServer, client: Client, parameters: URLSearchParams, privateKey: CryptoKey | PrivateKey): Promise<string>;
|
|
616
|
+
export declare function issueRequestObject(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], privateKey: CryptoKey | PrivateKey): Promise<string>;
|
|
617
617
|
/**
|
|
618
618
|
* Performs a Pushed Authorization Request at the
|
|
619
619
|
* {@link AuthorizationServer.pushed_authorization_request_endpoint `as.pushed_authorization_request_endpoint`}.
|
|
@@ -623,9 +623,9 @@ export declare function issueRequestObject(as: AuthorizationServer, client: Clie
|
|
|
623
623
|
* @param parameters Authorization Request parameters.
|
|
624
624
|
*
|
|
625
625
|
* @see [RFC 9126 - OAuth 2.0 Pushed Authorization Requests](https://www.rfc-editor.org/rfc/rfc9126.html#name-pushed-authorization-reques)
|
|
626
|
-
* @see [draft-ietf-oauth-dpop-
|
|
626
|
+
* @see [draft-ietf-oauth-dpop-16 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.ietf.org/archive/id/draft-ietf-oauth-dpop-16.html#name-dpop-with-pushed-authorizat)
|
|
627
627
|
*/
|
|
628
|
-
export declare function pushedAuthorizationRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams, options?: PushedAuthorizationRequestOptions): Promise<Response>;
|
|
628
|
+
export declare function pushedAuthorizationRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], options?: PushedAuthorizationRequestOptions): Promise<Response>;
|
|
629
629
|
export interface PushedAuthorizationResponse {
|
|
630
630
|
readonly request_uri: string;
|
|
631
631
|
readonly expires_in: number;
|
|
@@ -701,7 +701,7 @@ export interface ProtectedResourceRequestOptions extends Omit<HttpRequestOptions
|
|
|
701
701
|
* @param body Request body compatible with the Fetch API and the request's method.
|
|
702
702
|
*
|
|
703
703
|
* @see [RFC 6750 - The OAuth 2.0 Authorization Framework: Bearer Token Usage](https://www.rfc-editor.org/rfc/rfc6750.html#section-2.1)
|
|
704
|
-
* @see [draft-ietf-oauth-dpop-
|
|
704
|
+
* @see [draft-ietf-oauth-dpop-16 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.ietf.org/archive/id/draft-ietf-oauth-dpop-16.html#name-protected-resource-access)
|
|
705
705
|
*/
|
|
706
706
|
export declare function protectedResourceRequest(accessToken: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | string, url: URL, headers: Headers, body: RequestInit['body'], options?: ProtectedResourceRequestOptions): Promise<Response>;
|
|
707
707
|
export interface UserInfoRequestOptions extends HttpRequestOptions, DPoPRequestOptions {
|
|
@@ -717,7 +717,7 @@ export interface UserInfoRequestOptions extends HttpRequestOptions, DPoPRequestO
|
|
|
717
717
|
* @param accessToken Access Token value.
|
|
718
718
|
*
|
|
719
719
|
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
|
|
720
|
-
* @see [draft-ietf-oauth-dpop-
|
|
720
|
+
* @see [draft-ietf-oauth-dpop-16 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.ietf.org/archive/id/draft-ietf-oauth-dpop-16.html#name-protected-resource-access)
|
|
721
721
|
*/
|
|
722
722
|
export declare function userInfoRequest(as: AuthorizationServer, client: Client, accessToken: string, options?: UserInfoRequestOptions): Promise<Response>;
|
|
723
723
|
export interface UserInfoAddress {
|
|
@@ -779,7 +779,7 @@ export declare const skipSubjectCheck: unique symbol;
|
|
|
779
779
|
export declare function processUserInfoResponse(as: AuthorizationServer, client: Client, expectedSubject: string | typeof skipSubjectCheck, response: Response): Promise<UserInfoResponse>;
|
|
780
780
|
export interface TokenEndpointRequestOptions extends HttpRequestOptions, AuthenticatedRequestOptions, DPoPRequestOptions {
|
|
781
781
|
/** Any additional parameters to send. This cannot override existing parameter values. */
|
|
782
|
-
additionalParameters?: URLSearchParams;
|
|
782
|
+
additionalParameters?: URLSearchParams | Record<string, string> | string[][];
|
|
783
783
|
}
|
|
784
784
|
/**
|
|
785
785
|
* Performs a Refresh Token Grant request at the
|
|
@@ -791,7 +791,7 @@ export interface TokenEndpointRequestOptions extends HttpRequestOptions, Authent
|
|
|
791
791
|
*
|
|
792
792
|
* @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-6)
|
|
793
793
|
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#RefreshTokens)
|
|
794
|
-
* @see [draft-ietf-oauth-dpop-
|
|
794
|
+
* @see [draft-ietf-oauth-dpop-16 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.ietf.org/archive/id/draft-ietf-oauth-dpop-16.html#name-dpop-access-token-request)
|
|
795
795
|
*/
|
|
796
796
|
export declare function refreshTokenGrantRequest(as: AuthorizationServer, client: Client, refreshToken: string, options?: TokenEndpointRequestOptions): Promise<Response>;
|
|
797
797
|
/**
|
|
@@ -841,9 +841,9 @@ export declare function processRefreshTokenResponse(as: AuthorizationServer, cli
|
|
|
841
841
|
* @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1)
|
|
842
842
|
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth)
|
|
843
843
|
* @see [RFC 7636 - Proof Key for Code Exchange by OAuth Public Clients (PKCE)](https://www.rfc-editor.org/rfc/rfc7636.html#section-4)
|
|
844
|
-
* @see [draft-ietf-oauth-dpop-
|
|
844
|
+
* @see [draft-ietf-oauth-dpop-16 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.ietf.org/archive/id/draft-ietf-oauth-dpop-16.html#name-dpop-access-token-request)
|
|
845
845
|
*/
|
|
846
|
-
export declare function authorizationCodeGrantRequest(as: AuthorizationServer, client: Client, callbackParameters:
|
|
846
|
+
export declare function authorizationCodeGrantRequest(as: AuthorizationServer, client: Client, callbackParameters: URLSearchParams, redirectUri: string, codeVerifier: string, options?: TokenEndpointRequestOptions): Promise<Response>;
|
|
847
847
|
interface JWTPayload {
|
|
848
848
|
readonly iss?: string;
|
|
849
849
|
readonly sub?: string;
|
|
@@ -958,9 +958,9 @@ export interface ClientCredentialsGrantRequestOptions extends HttpRequestOptions
|
|
|
958
958
|
* @param client Client Metadata.
|
|
959
959
|
*
|
|
960
960
|
* @see [RFC 6749 - The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html#section-4.4)
|
|
961
|
-
* @see [draft-ietf-oauth-dpop-
|
|
961
|
+
* @see [draft-ietf-oauth-dpop-16 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.ietf.org/archive/id/draft-ietf-oauth-dpop-16.html#name-dpop-access-token-request)
|
|
962
962
|
*/
|
|
963
|
-
export declare function clientCredentialsGrantRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams, options?: ClientCredentialsGrantRequestOptions): Promise<Response>;
|
|
963
|
+
export declare function clientCredentialsGrantRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], options?: ClientCredentialsGrantRequestOptions): Promise<Response>;
|
|
964
964
|
/**
|
|
965
965
|
* Validates Client Credentials Grant Response instance to be one coming from the
|
|
966
966
|
* {@link AuthorizationServer.token_endpoint `as.token_endpoint`}.
|
|
@@ -977,7 +977,7 @@ export declare function clientCredentialsGrantRequest(as: AuthorizationServer, c
|
|
|
977
977
|
export declare function processClientCredentialsResponse(as: AuthorizationServer, client: Client, response: Response): Promise<ClientCredentialsGrantResponse | OAuth2Error>;
|
|
978
978
|
export interface RevocationRequestOptions extends HttpRequestOptions, AuthenticatedRequestOptions {
|
|
979
979
|
/** Any additional parameters to send. This cannot override existing parameter values. */
|
|
980
|
-
additionalParameters?: URLSearchParams;
|
|
980
|
+
additionalParameters?: URLSearchParams | Record<string, string> | string[][];
|
|
981
981
|
}
|
|
982
982
|
/**
|
|
983
983
|
* Performs a Revocation Request at the
|
|
@@ -1003,7 +1003,7 @@ export declare function revocationRequest(as: AuthorizationServer, client: Clien
|
|
|
1003
1003
|
export declare function processRevocationResponse(response: Response): Promise<undefined | OAuth2Error>;
|
|
1004
1004
|
export interface IntrospectionRequestOptions extends HttpRequestOptions, AuthenticatedRequestOptions {
|
|
1005
1005
|
/** Any additional parameters to send. This cannot override existing parameter values. */
|
|
1006
|
-
additionalParameters?: URLSearchParams;
|
|
1006
|
+
additionalParameters?: URLSearchParams | Record<string, string> | string[][];
|
|
1007
1007
|
/**
|
|
1008
1008
|
* Request a JWT Response from the
|
|
1009
1009
|
* {@link AuthorizationServer.introspection_endpoint `as.introspection_endpoint`}. Default is
|
|
@@ -1076,7 +1076,7 @@ export declare function processIntrospectionResponse(as: AuthorizationServer, cl
|
|
|
1076
1076
|
*
|
|
1077
1077
|
* @see [JWT Secured Authorization Response Mode for OAuth 2.0 (JARM)](https://openid.net/specs/openid-financial-api-jarm.html)
|
|
1078
1078
|
*/
|
|
1079
|
-
export declare function validateJwtAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck, options?: HttpRequestOptions): Promise<
|
|
1079
|
+
export declare function validateJwtAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck, options?: HttpRequestOptions): Promise<URLSearchParams | OAuth2Error>;
|
|
1080
1080
|
/**
|
|
1081
1081
|
* DANGER ZONE
|
|
1082
1082
|
*
|
|
@@ -1093,8 +1093,6 @@ export declare const skipStateCheck: unique symbol;
|
|
|
1093
1093
|
* authorization request.
|
|
1094
1094
|
*/
|
|
1095
1095
|
export declare const expectNoState: unique symbol;
|
|
1096
|
-
declare class CallbackParameters extends URLSearchParams {
|
|
1097
|
-
}
|
|
1098
1096
|
/**
|
|
1099
1097
|
* Validates an OAuth 2.0 Authorization Response or Authorization Error Response message returned
|
|
1100
1098
|
* from the authorization server's
|
|
@@ -1111,7 +1109,7 @@ declare class CallbackParameters extends URLSearchParams {
|
|
|
1111
1109
|
* @see [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication)
|
|
1112
1110
|
* @see [RFC 9207 - OAuth 2.0 Authorization Server Issuer Identification](https://www.rfc-editor.org/rfc/rfc9207.html)
|
|
1113
1111
|
*/
|
|
1114
|
-
export declare function validateAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck):
|
|
1112
|
+
export declare function validateAuthResponse(as: AuthorizationServer, client: Client, parameters: URLSearchParams | URL, expectedState?: string | typeof expectNoState | typeof skipStateCheck): URLSearchParams | OAuth2Error;
|
|
1115
1113
|
type ReturnTypes = TokenEndpointResponse | OAuth2TokenEndpointResponse | OpenIDTokenEndpointResponse | ClientCredentialsGrantResponse | DeviceAuthorizationResponse | IntrospectionResponse | OAuth2Error | PushedAuthorizationResponse | URLSearchParams | UserInfoResponse;
|
|
1116
1114
|
export interface DeviceAuthorizationRequestOptions extends HttpRequestOptions, AuthenticatedRequestOptions {
|
|
1117
1115
|
}
|
|
@@ -1125,7 +1123,7 @@ export interface DeviceAuthorizationRequestOptions extends HttpRequestOptions, A
|
|
|
1125
1123
|
*
|
|
1126
1124
|
* @see [RFC 8628 - OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628.html#section-3.1)
|
|
1127
1125
|
*/
|
|
1128
|
-
export declare function deviceAuthorizationRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams, options?: DeviceAuthorizationRequestOptions): Promise<Response>;
|
|
1126
|
+
export declare function deviceAuthorizationRequest(as: AuthorizationServer, client: Client, parameters: URLSearchParams | Record<string, string> | string[][], options?: DeviceAuthorizationRequestOptions): Promise<Response>;
|
|
1129
1127
|
export interface DeviceAuthorizationResponse {
|
|
1130
1128
|
readonly device_code: string;
|
|
1131
1129
|
readonly user_code: string;
|
|
@@ -1158,7 +1156,7 @@ export declare function processDeviceAuthorizationResponse(as: AuthorizationServ
|
|
|
1158
1156
|
* @param deviceCode Device Code.
|
|
1159
1157
|
*
|
|
1160
1158
|
* @see [RFC 8628 - OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628.html#section-3.4)
|
|
1161
|
-
* @see [draft-ietf-oauth-dpop-
|
|
1159
|
+
* @see [draft-ietf-oauth-dpop-16 - OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://www.ietf.org/archive/id/draft-ietf-oauth-dpop-16.html#name-dpop-access-token-request)
|
|
1162
1160
|
*/
|
|
1163
1161
|
export declare function deviceCodeGrantRequest(as: AuthorizationServer, client: Client, deviceCode: string, options?: TokenEndpointRequestOptions): Promise<Response>;
|
|
1164
1162
|
/**
|
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
|
+
const VERSION = 'v2.3.0';
|
|
5
5
|
USER_AGENT = `${NAME}/${VERSION}`;
|
|
6
6
|
}
|
|
7
7
|
export const clockSkew = Symbol();
|
|
@@ -443,9 +443,6 @@ async function jwt(header, claimsSet, key) {
|
|
|
443
443
|
export async function issueRequestObject(as, client, parameters, privateKey) {
|
|
444
444
|
assertAs(as);
|
|
445
445
|
assertClient(client);
|
|
446
|
-
if (!(parameters instanceof URLSearchParams)) {
|
|
447
|
-
throw new TypeError('"parameters" must be an instance of URLSearchParams');
|
|
448
|
-
}
|
|
449
446
|
parameters = new URLSearchParams(parameters);
|
|
450
447
|
const { key, kid } = getKeyAndKid(privateKey);
|
|
451
448
|
if (!isPrivateKey(key)) {
|
|
@@ -534,9 +531,6 @@ async function publicJwk(key) {
|
|
|
534
531
|
export async function pushedAuthorizationRequest(as, client, parameters, options) {
|
|
535
532
|
assertAs(as);
|
|
536
533
|
assertClient(client);
|
|
537
|
-
if (!(parameters instanceof URLSearchParams)) {
|
|
538
|
-
throw new TypeError('"parameters" must be an instance of URLSearchParams');
|
|
539
|
-
}
|
|
540
534
|
if (typeof as.pushed_authorization_request_endpoint !== 'string') {
|
|
541
535
|
throw new TypeError('"as.pushed_authorization_request_endpoint" must be a string');
|
|
542
536
|
}
|
|
@@ -968,11 +962,16 @@ function validateIssuer(expected, result) {
|
|
|
968
962
|
}
|
|
969
963
|
return result;
|
|
970
964
|
}
|
|
965
|
+
const branded = new WeakSet();
|
|
966
|
+
function brand(searchParams) {
|
|
967
|
+
branded.add(searchParams);
|
|
968
|
+
return searchParams;
|
|
969
|
+
}
|
|
971
970
|
export async function authorizationCodeGrantRequest(as, client, callbackParameters, redirectUri, codeVerifier, options) {
|
|
972
971
|
assertAs(as);
|
|
973
972
|
assertClient(client);
|
|
974
|
-
if (!(callbackParameters
|
|
975
|
-
throw new TypeError('"callbackParameters" must be an instance of
|
|
973
|
+
if (!branded.has(callbackParameters)) {
|
|
974
|
+
throw new TypeError('"callbackParameters" must be an instance of URLSearchParams obtained from "validateAuthResponse()", or "validateJwtAuthResponse()');
|
|
976
975
|
}
|
|
977
976
|
if (!validateString(redirectUri)) {
|
|
978
977
|
throw new TypeError('"redirectUri" must be a non-empty string');
|
|
@@ -1430,8 +1429,6 @@ function getURLSearchParameter(parameters, name) {
|
|
|
1430
1429
|
}
|
|
1431
1430
|
export const skipStateCheck = Symbol();
|
|
1432
1431
|
export const expectNoState = Symbol();
|
|
1433
|
-
class CallbackParameters extends URLSearchParams {
|
|
1434
|
-
}
|
|
1435
1432
|
export function validateAuthResponse(as, client, parameters, expectedState) {
|
|
1436
1433
|
assertAs(as);
|
|
1437
1434
|
assertClient(client);
|
|
@@ -1485,7 +1482,7 @@ export function validateAuthResponse(as, client, parameters, expectedState) {
|
|
|
1485
1482
|
if (id_token !== undefined || token !== undefined) {
|
|
1486
1483
|
throw new UnsupportedOperationError('implicit and hybrid flows are not supported');
|
|
1487
1484
|
}
|
|
1488
|
-
return new
|
|
1485
|
+
return brand(new URLSearchParams(parameters));
|
|
1489
1486
|
}
|
|
1490
1487
|
function algToSubtle(alg, crv) {
|
|
1491
1488
|
switch (alg) {
|
|
@@ -1523,9 +1520,6 @@ async function importJwk(alg, jwk) {
|
|
|
1523
1520
|
export async function deviceAuthorizationRequest(as, client, parameters, options) {
|
|
1524
1521
|
assertAs(as);
|
|
1525
1522
|
assertClient(client);
|
|
1526
|
-
if (!(parameters instanceof URLSearchParams)) {
|
|
1527
|
-
throw new TypeError('"parameters" must be an instance of URLSearchParams');
|
|
1528
|
-
}
|
|
1529
1523
|
if (typeof as.device_authorization_endpoint !== 'string') {
|
|
1530
1524
|
throw new TypeError('"as.device_authorization_endpoint" must be a string');
|
|
1531
1525
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oauth4webapi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "OAuth 2 / OpenID Connect for Web Platform API JavaScript runtimes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -63,18 +63,18 @@
|
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@esbuild-kit/esm-loader": "^2.5.5",
|
|
66
|
-
"@types/node": "^18.
|
|
66
|
+
"@types/node": "^18.16.1",
|
|
67
67
|
"@types/qunit": "^2.19.4",
|
|
68
68
|
"ava": "^5.2.0",
|
|
69
69
|
"edge-runtime": "^2.1.4",
|
|
70
|
-
"esbuild": "^0.17.
|
|
70
|
+
"esbuild": "^0.17.18",
|
|
71
71
|
"jose": "^4.14.1",
|
|
72
|
-
"patch-package": "^
|
|
73
|
-
"prettier": "^2.8.
|
|
72
|
+
"patch-package": "^7.0.0",
|
|
73
|
+
"prettier": "^2.8.8",
|
|
74
74
|
"prettier-plugin-jsdoc": "^0.4.2",
|
|
75
75
|
"qunit": "^2.19.4",
|
|
76
76
|
"timekeeper": "^2.2.0",
|
|
77
|
-
"typedoc": "^0.24.
|
|
77
|
+
"typedoc": "^0.24.6",
|
|
78
78
|
"typedoc-plugin-markdown": "^3.15.2",
|
|
79
79
|
"typedoc-plugin-mdn-links": "^3.0.3",
|
|
80
80
|
"typescript": "^5.0.4",
|