@api-client/core 0.5.20 → 0.5.21

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.
Files changed (48) hide show
  1. package/build/browser.d.ts +7 -0
  2. package/build/browser.js +10 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +4 -0
  5. package/build/index.js +7 -0
  6. package/build/index.js.map +1 -1
  7. package/build/src/authorization/AuthorizationError.d.ts +23 -0
  8. package/build/src/authorization/AuthorizationError.js +33 -0
  9. package/build/src/authorization/AuthorizationError.js.map +1 -0
  10. package/build/src/authorization/CustomParameters.d.ts +24 -0
  11. package/build/src/authorization/CustomParameters.js +59 -0
  12. package/build/src/authorization/CustomParameters.js.map +1 -0
  13. package/build/src/authorization/OAuth2Authorization.d.ts +332 -0
  14. package/build/src/authorization/OAuth2Authorization.js +965 -0
  15. package/build/src/authorization/OAuth2Authorization.js.map +1 -0
  16. package/build/src/authorization/OidcAuthorization.d.ts +34 -0
  17. package/build/src/authorization/OidcAuthorization.js +139 -0
  18. package/build/src/authorization/OidcAuthorization.js.map +1 -0
  19. package/build/src/authorization/Utils.d.ts +51 -0
  20. package/build/src/authorization/Utils.js +122 -0
  21. package/build/src/authorization/Utils.js.map +1 -0
  22. package/build/src/authorization/lib/IframeAuthorization.d.ts +53 -0
  23. package/build/src/authorization/lib/IframeAuthorization.js +116 -0
  24. package/build/src/authorization/lib/IframeAuthorization.js.map +1 -0
  25. package/build/src/authorization/lib/KnownGrants.d.ts +6 -0
  26. package/build/src/authorization/lib/KnownGrants.js +7 -0
  27. package/build/src/authorization/lib/KnownGrants.js.map +1 -0
  28. package/build/src/authorization/lib/PopupAuthorization.d.ts +41 -0
  29. package/build/src/authorization/lib/PopupAuthorization.js +73 -0
  30. package/build/src/authorization/lib/PopupAuthorization.js.map +1 -0
  31. package/build/src/authorization/lib/Tokens.d.ts +55 -0
  32. package/build/src/authorization/lib/Tokens.js +117 -0
  33. package/build/src/authorization/lib/Tokens.js.map +1 -0
  34. package/build/src/authorization/types.d.ts +174 -0
  35. package/build/src/authorization/types.js +2 -0
  36. package/build/src/authorization/types.js.map +1 -0
  37. package/oauth-popup.html +29 -0
  38. package/package.json +3 -1
  39. package/src/authorization/AuthorizationError.ts +25 -0
  40. package/src/authorization/CustomParameters.ts +61 -0
  41. package/src/authorization/OAuth2Authorization.ts +1027 -0
  42. package/src/authorization/OidcAuthorization.ts +143 -0
  43. package/src/authorization/Utils.ts +126 -0
  44. package/src/authorization/lib/IframeAuthorization.ts +128 -0
  45. package/src/authorization/lib/KnownGrants.ts +6 -0
  46. package/src/authorization/lib/PopupAuthorization.ts +80 -0
  47. package/src/authorization/lib/Tokens.ts +124 -0
  48. package/src/authorization/types.ts +176 -0
@@ -0,0 +1,73 @@
1
+ export const observePopupState = Symbol('observePopupState');
2
+ export const popupInterval = Symbol('popupInterval');
3
+ export const popupObserver = Symbol('popupObserver');
4
+ export const intervalValue = Symbol('intervalValue');
5
+ /**
6
+ * Adds support for the popup window authorization.
7
+ *
8
+ * The set timeout hack is used because I can't see other way of doing this
9
+ * as load/unload events are called only once (even with redirects)
10
+ * and there's no way of knowing what is happening in the popup (so no timeouts).
11
+ * The user may need more time to authorize themselves and then the application.
12
+ *
13
+ * This class dispatches the `close` event when the popup was closed.
14
+ *
15
+ * Call the `cleanUp()` function when the authorization data is received.
16
+ */
17
+ export class PopupAuthorization extends EventTarget {
18
+ [intervalValue];
19
+ popup;
20
+ [popupInterval];
21
+ /**
22
+ * @param interval The popup state check interval
23
+ */
24
+ constructor(interval = 50) {
25
+ super();
26
+ this[intervalValue] = interval;
27
+ this[popupObserver] = this[popupObserver].bind(this);
28
+ }
29
+ /**
30
+ * Removes any existing frame and removes any remaining listeners.
31
+ */
32
+ cleanUp() {
33
+ if (this[popupInterval]) {
34
+ clearInterval(this[popupInterval]);
35
+ this[popupInterval] = undefined;
36
+ }
37
+ const { popup } = this;
38
+ if (popup && !popup.closed) {
39
+ popup.close();
40
+ }
41
+ this.popup = undefined;
42
+ }
43
+ /**
44
+ * Opens a popup to request authorization from the user.
45
+ * @param url The URL to open.
46
+ */
47
+ load(url) {
48
+ const op = 'menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=800,height=600';
49
+ const popup = window.open(url, 'oauth-window', op);
50
+ if (!popup) {
51
+ throw new Error('Authorization popup is being blocked.');
52
+ }
53
+ popup.window.focus();
54
+ this.popup = popup;
55
+ this[observePopupState]();
56
+ }
57
+ /**
58
+ * Initializes an interval to check whether the popup window is still present.
59
+ * The web security model does not allow pages to read the URL for the cross domain
60
+ * connections.
61
+ */
62
+ [observePopupState]() {
63
+ this[popupInterval] = setInterval(this[popupObserver], this[intervalValue]);
64
+ }
65
+ [popupObserver]() {
66
+ const { popup } = this;
67
+ if (!popup || popup.closed) {
68
+ this.cleanUp();
69
+ this.dispatchEvent(new Event('close'));
70
+ }
71
+ }
72
+ }
73
+ //# sourceMappingURL=PopupAuthorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PopupAuthorization.js","sourceRoot":"","sources":["../../../../src/authorization/lib/PopupAuthorization.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,CAAC,aAAa,CAAC,CAAS;IAExB,KAAK,CAAU;IAEf,CAAC,aAAa,CAAC,CAAM;IAErB;;OAEG;IACH,YAAY,QAAQ,GAAG,EAAE;QACvB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;QAC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I,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;SACxC;IACH,CAAC;CACF"}
@@ -0,0 +1,55 @@
1
+ import { IOidcTokenInfo, ITokenInfo } from "../../models/Authorization.js";
2
+ export declare class Tokens {
3
+ /**
4
+ * Creates a OidcTokenInfo object for the corresponding response type.
5
+ *
6
+ * @param responseType The response type of the token to prepare the info for.
7
+ * @param params params received from the authorization endpoint.
8
+ * @param time Timestamp when the tokens were created
9
+ * @param requestedScopes The list of requested scopes. Optional.
10
+ * @returns
11
+ */
12
+ static createTokenInfo(responseType: string, params: URLSearchParams, time: number, requestedScopes?: string[]): IOidcTokenInfo | null;
13
+ /**
14
+ * Creates a "code" response type token info.
15
+ * @param params
16
+ * @param time Timestamp when the tokens were created
17
+ * @param requestedScopes The list of requested scopes. Optional.
18
+ * @returns
19
+ */
20
+ static createBaseToken(params: URLSearchParams, time: number, requestedScopes?: string[]): IOidcTokenInfo;
21
+ /**
22
+ * Creates a "code" response type token info.
23
+ * @param params
24
+ * @param time Timestamp when the tokens were created
25
+ * @param requestedScopes The list of requested scopes. Optional.
26
+ * @returns
27
+ */
28
+ static createCodeToken(params: URLSearchParams, time: number, requestedScopes?: string[]): IOidcTokenInfo;
29
+ /**
30
+ * Creates a "token" response type token info.
31
+ * @param params
32
+ * @param time Timestamp when the tokens were created
33
+ * @param requestedScopes The list of requested scopes. Optional.
34
+ * @returns
35
+ */
36
+ static createTokenToken(params: URLSearchParams, time: number, requestedScopes?: string[]): IOidcTokenInfo;
37
+ /**
38
+ * Creates a "id_token" response type token info.
39
+ * @param time Timestamp when the tokens were created
40
+ * @param requestedScopes The list of requested scopes. Optional.
41
+ */
42
+ static createIdTokenToken(params: URLSearchParams, time: number, requestedScopes?: string[]): IOidcTokenInfo;
43
+ /**
44
+ * Computes the final list of granted scopes.
45
+ * It is a list of scopes received in the response or the list of requested scopes.
46
+ * Because the user may change the list of scopes during the authorization process
47
+ * the received list of scopes can be different than the one requested by the user.
48
+ *
49
+ * @param requestedScopes The list of requested scopes. Optional.
50
+ * @param tokenScopes The `scope` parameter received with the response. It's null safe.
51
+ * @returns The list of scopes for the token.
52
+ */
53
+ static computeTokenInfoScopes(requestedScopes?: string[], tokenScopes?: string): string[];
54
+ static fromTokenInfo(info: ITokenInfo): IOidcTokenInfo;
55
+ }
@@ -0,0 +1,117 @@
1
+ export class Tokens {
2
+ /**
3
+ * Creates a OidcTokenInfo object for the corresponding response type.
4
+ *
5
+ * @param responseType The response type of the token to prepare the info for.
6
+ * @param params params received from the authorization endpoint.
7
+ * @param time Timestamp when the tokens were created
8
+ * @param requestedScopes The list of requested scopes. Optional.
9
+ * @returns
10
+ */
11
+ static createTokenInfo(responseType, params, time, requestedScopes) {
12
+ switch (responseType) {
13
+ case 'code': return Tokens.createCodeToken(params, time, requestedScopes);
14
+ case 'token': return Tokens.createTokenToken(params, time, requestedScopes);
15
+ case 'id_token': return Tokens.createIdTokenToken(params, time, requestedScopes);
16
+ default: return null;
17
+ }
18
+ }
19
+ /**
20
+ * Creates a "code" response type token info.
21
+ * @param params
22
+ * @param time Timestamp when the tokens were created
23
+ * @param requestedScopes The list of requested scopes. Optional.
24
+ * @returns
25
+ */
26
+ static createBaseToken(params, time, requestedScopes) {
27
+ const scope = Tokens.computeTokenInfoScopes(requestedScopes, params.get('scope'));
28
+ const tokenInfo = {
29
+ state: params.get('state'),
30
+ expiresIn: Number(params.get('expires_in')),
31
+ tokenType: params.get('token_type'),
32
+ scope,
33
+ time,
34
+ responseType: '',
35
+ };
36
+ return tokenInfo;
37
+ }
38
+ /**
39
+ * Creates a "code" response type token info.
40
+ * @param params
41
+ * @param time Timestamp when the tokens were created
42
+ * @param requestedScopes The list of requested scopes. Optional.
43
+ * @returns
44
+ */
45
+ static createCodeToken(params, time, requestedScopes) {
46
+ const token = Tokens.createBaseToken(params, time, requestedScopes);
47
+ token.responseType = 'code';
48
+ token.code = params.get('code');
49
+ return token;
50
+ }
51
+ /**
52
+ * Creates a "token" response type token info.
53
+ * @param params
54
+ * @param time Timestamp when the tokens were created
55
+ * @param requestedScopes The list of requested scopes. Optional.
56
+ * @returns
57
+ */
58
+ static createTokenToken(params, time, requestedScopes) {
59
+ const token = Tokens.createBaseToken(params, time, requestedScopes);
60
+ token.responseType = 'token';
61
+ token.accessToken = params.get('access_token');
62
+ token.refreshToken = params.get('refresh_token');
63
+ return token;
64
+ }
65
+ /**
66
+ * Creates a "id_token" response type token info.
67
+ * @param time Timestamp when the tokens were created
68
+ * @param requestedScopes The list of requested scopes. Optional.
69
+ */
70
+ static createIdTokenToken(params, time, requestedScopes) {
71
+ const token = Tokens.createBaseToken(params, time, requestedScopes);
72
+ token.responseType = 'id_token';
73
+ token.accessToken = params.get('access_token');
74
+ token.refreshToken = params.get('refresh_token');
75
+ token.idToken = params.get('id_token');
76
+ return token;
77
+ }
78
+ /**
79
+ * Computes the final list of granted scopes.
80
+ * It is a list of scopes received in the response or the list of requested scopes.
81
+ * Because the user may change the list of scopes during the authorization process
82
+ * the received list of scopes can be different than the one requested by the user.
83
+ *
84
+ * @param requestedScopes The list of requested scopes. Optional.
85
+ * @param tokenScopes The `scope` parameter received with the response. It's null safe.
86
+ * @returns The list of scopes for the token.
87
+ */
88
+ static computeTokenInfoScopes(requestedScopes, tokenScopes) {
89
+ if (!tokenScopes && requestedScopes) {
90
+ return requestedScopes;
91
+ }
92
+ let listScopes = [];
93
+ if (typeof tokenScopes === 'string') {
94
+ listScopes = tokenScopes.split(' ');
95
+ }
96
+ return listScopes;
97
+ }
98
+ static fromTokenInfo(info) {
99
+ const result = {
100
+ responseType: '',
101
+ state: info.state,
102
+ accessToken: info.accessToken,
103
+ time: Date.now(),
104
+ };
105
+ if (info.scope) {
106
+ result.scope = info.scope;
107
+ }
108
+ if (info.tokenType) {
109
+ result.tokenType = info.tokenType;
110
+ }
111
+ if (info.expiresIn) {
112
+ result.expiresIn = info.expiresIn;
113
+ }
114
+ return result;
115
+ }
116
+ }
117
+ //# sourceMappingURL=Tokens.js.map
@@ -0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AI,OAAO,WAAW,KAAK,QAAQ,EAAE;YACnC,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACrC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,IAAgB;QACnC,MAAM,MAAM,GAAmB;YAC7B,YAAY,EAAE,EAAE;YAChB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;SACjB,CAAC;QACF,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;SAC3B;QACD,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;SACnC;QACD,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;SACnC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,174 @@
1
+ export interface OauthProcessingOptions {
2
+ /**
3
+ * The number of milliseconds of an interval to check the popup state.
4
+ * Default to 250 ms.
5
+ */
6
+ popupPullTimeout?: number;
7
+ /**
8
+ * The event target on which to listen to the redirect page `message` event.
9
+ * This event should contain a list of authorization parameters returned by the authorization server.
10
+ *
11
+ * The library contains `oauth-popup.html` page that reads the data from the URL and posts it back to the opener.
12
+ * However, you can create `tokenInfoTranslation` to map returned by the popup parameters to the onces used by the library.
13
+ */
14
+ messageTarget?: EventTarget;
15
+ /**
16
+ * A number of milliseconds after which the iframe triggers a timeout if the response is not present.
17
+ * Defaults to `1020`.
18
+ */
19
+ iframeTimeout?: number;
20
+ /**
21
+ * When set it uses this value to prefix the call to the
22
+ * OAuth 2 token endpoint. This is to support use cases when
23
+ * the requests should be proxied through a server to avoid CORS problems.
24
+ */
25
+ tokenProxy?: string;
26
+ /**
27
+ * When set it encodes the token URI value before adding it to the
28
+ * `tokenProxy`. This is to be used when the proxy takes the target
29
+ * URL as a query parameter.
30
+ */
31
+ tokenProxyEncode?: boolean;
32
+ }
33
+ export interface IOpenIdProviderMetadata {
34
+ /**
35
+ * URL using the https scheme with no query or fragment component that the OP asserts as its Issuer Identifier. If Issuer discovery is supported (see Section 2), this value MUST be identical to the issuer value returned by WebFinger. This also MUST be identical to the iss Claim value in ID Tokens issued from this Issuer.
36
+ */
37
+ issuer: string;
38
+ /**
39
+ * URL of the OP's OAuth 2.0 Authorization Endpoint [OpenID.Core].
40
+ */
41
+ authorization_endpoint: string;
42
+ /**
43
+ * URL of the OP's OAuth 2.0 Token Endpoint [OpenID.Core]. This is REQUIRED unless only the Implicit Flow is used.
44
+ */
45
+ token_endpoint?: string;
46
+ /**
47
+ * URL of the OP's UserInfo Endpoint [OpenID.Core]. This URL MUST use the https scheme and MAY contain port, path, and query parameter components.
48
+ */
49
+ userinfo_endpoint?: string;
50
+ /**
51
+ * URL of the OP's JSON Web Key Set [JWK] document. This contains the signing key(s) the RP uses to validate signatures from the OP. The JWK Set MAY also contain the Server's encryption key(s), which are used by RPs to encrypt requests to the Server. When both signing and encryption keys are made available, a use (Key Use) parameter value is REQUIRED for all keys in the referenced JWK Set to indicate each key's intended usage. Although some algorithms allow the same key to be used for both signatures and encryption, doing so is NOT RECOMMENDED, as it is less secure. The JWK x5c parameter MAY be used to provide X.509 representations of keys provided. When used, the bare key values MUST still be present and MUST match those in the certificate.
52
+ */
53
+ jwks_uri: string;
54
+ /**
55
+ * URL of the OP's Dynamic Client Registration Endpoint.
56
+ */
57
+ registration_endpoint?: string;
58
+ /**
59
+ * JSON array containing a list of the OAuth 2.0 [RFC6749] scope values that this server supports. The server MUST support the openid scope value. Servers MAY choose not to advertise some supported scope values even when this parameter is used, although those defined in [OpenID.Core] SHOULD be listed, if supported.
60
+ */
61
+ scopes_supported?: string[];
62
+ /**
63
+ * JSON array containing a list of the OAuth 2.0 response_type values that this OP supports. Dynamic OpenID Providers MUST support the code, id_token, and the token id_token Response Type values.
64
+ */
65
+ response_types_supported: string[];
66
+ /**
67
+ * JSON array containing a list of the OAuth 2.0 response_mode values that this OP supports, as specified in OAuth 2.0 Multiple Response Type Encoding Practices [OAuth.Responses]. If omitted, the default for Dynamic OpenID Providers is ["query", "fragment"].
68
+ */
69
+ response_modes_supported?: string[];
70
+ /**
71
+ * JSON array containing a list of the OAuth 2.0 Grant Type values that this OP supports. Dynamic OpenID Providers MUST support the authorization_code and implicit Grant Type values and MAY support other Grant Types. If omitted, the default value is ["authorization_code", "implicit"].
72
+ */
73
+ grant_types_supported?: string[];
74
+ /**
75
+ * JSON array containing a list of the Authentication Context Class References that this OP supports.
76
+ */
77
+ acr_values_supported?: string[];
78
+ /**
79
+ * JSON array containing a list of the Subject Identifier types that this OP supports. Valid types include pairwise and public.
80
+ */
81
+ subject_types_supported: string[];
82
+ /**
83
+ * JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT]. The algorithm RS256 MUST be included. The value none MAY be supported, but MUST NOT be used unless the Response Type used returns no ID Token from the Authorization Endpoint (such as when using the Authorization Code Flow).
84
+ */
85
+ id_token_signing_alg_values_supported: string[];
86
+ /**
87
+ * JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT].
88
+ */
89
+ id_token_encryption_alg_values_supported?: string[];
90
+ /**
91
+ * JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT].
92
+ */
93
+ id_token_encryption_enc_values_supported?: string[];
94
+ /**
95
+ * JSON array containing a list of the JWS [JWS] signing algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT]. The value none MAY be included.
96
+ */
97
+ userinfo_signing_alg_values_supported?: string[];
98
+ /**
99
+ * JSON array containing a list of the JWE [JWE] encryption algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT].
100
+ */
101
+ userinfo_encryption_alg_values_supported?: string[];
102
+ /**
103
+ * JSON array containing a list of the JWE encryption algorithms (enc values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT].
104
+ */
105
+ userinfo_encryption_enc_values_supported?: string[];
106
+ /**
107
+ * JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for Request Objects, which are described in Section 6.1 of OpenID Connect Core 1.0 [OpenID.Core]. These algorithms are used both when the Request Object is passed by value (using the request parameter) and when it is passed by reference (using the request_uri parameter). Servers SHOULD support none and RS256.
108
+ */
109
+ request_object_signing_alg_values_supported?: string[];
110
+ /**
111
+ * JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for Request Objects. These algorithms are used both when the Request Object is passed by value and when it is passed by reference.
112
+ */
113
+ request_object_encryption_alg_values_supported?: string[];
114
+ /**
115
+ * JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for Request Objects. These algorithms are used both when the Request Object is passed by value and when it is passed by reference.
116
+ */
117
+ request_object_encryption_enc_values_supported?: string[];
118
+ /**
119
+ * JSON array containing a list of Client Authentication methods supported by this Token Endpoint. The options are client_secret_post, client_secret_basic, client_secret_jwt, and private_key_jwt, as described in Section 9 of OpenID Connect Core 1.0 [OpenID.Core]. Other authentication methods MAY be defined by extensions. If omitted, the default is client_secret_basic -- the HTTP Basic Authentication Scheme specified in Section 2.3.1 of OAuth 2.0 [RFC6749].
120
+ */
121
+ token_endpoint_auth_methods_supported?: string[];
122
+ /**
123
+ * JSON array containing a list of the JWS signing algorithms (alg values) supported by the Token Endpoint for the signature on the JWT [JWT] used to authenticate the Client at the Token Endpoint for the private_key_jwt and client_secret_jwt authentication methods. Servers SHOULD support RS256. The value none MUST NOT be used.
124
+ */
125
+ token_endpoint_auth_signing_alg_values_supported?: string[];
126
+ /**
127
+ * JSON array containing a list of the display parameter values that the OpenID Provider supports. These values are described in Section 3.1.2.1 of OpenID Connect Core 1.0 [OpenID.Core].
128
+ */
129
+ display_values_supported?: string[];
130
+ /**
131
+ * JSON array containing a list of the Claim Types that the OpenID Provider supports. These Claim Types are described in Section 5.6 of OpenID Connect Core 1.0 [OpenID.Core]. Values defined by this specification are normal, aggregated, and distributed. If omitted, the implementation supports only normal Claims.
132
+ */
133
+ claim_types_supported?: string[];
134
+ /**
135
+ * JSON array containing a list of the Claim Names of the Claims that the OpenID Provider MAY be able to supply values for. Note that for privacy or other reasons, this might not be an exhaustive list.
136
+ */
137
+ claims_supported?: string[];
138
+ /**
139
+ * URL of a page containing human-readable information that developers might want or need to know when using the OpenID Provider. In particular, if the OpenID Provider does not support Dynamic Client Registration, then information on how to register Clients needs to be provided in this documentation.
140
+ */
141
+ service_documentation?: string;
142
+ /**
143
+ * Languages and scripts supported for values in Claims being returned, represented as a JSON array of BCP47 [RFC5646] language tag values. Not all languages and scripts are necessarily supported for all Claim values.
144
+ */
145
+ claims_locales_supported?: string[];
146
+ /**
147
+ * Languages and scripts supported for the user interface, represented as a JSON array of BCP47 [RFC5646] language tag values.
148
+ */
149
+ ui_locales_supported?: string[];
150
+ /**
151
+ * Boolean value specifying whether the OP supports use of the claims parameter, with true indicating support. If omitted, the default value is false.
152
+ */
153
+ claims_parameter_supported?: boolean;
154
+ /**
155
+ * Boolean value specifying whether the OP supports use of the request parameter, with true indicating support. If omitted, the default value is false.
156
+ */
157
+ request_parameter_supported?: boolean;
158
+ /**
159
+ * Boolean value specifying whether the OP supports use of the request_uri parameter, with true indicating support. If omitted, the default value is true.
160
+ */
161
+ request_uri_parameter_supported?: boolean;
162
+ /**
163
+ * Boolean value specifying whether the OP requires any request_uri values used to be pre-registered using the request_uris registration parameter. Pre-registration is REQUIRED when the value is true. If omitted, the default value is false.
164
+ */
165
+ require_request_uri_registration?: boolean;
166
+ /**
167
+ * URL that the OpenID Provider provides to the person registering the Client to read about the OP's requirements on how the Relying Party can use the data provided by the OP. The registration process SHOULD display this URL to the person registering the Client if it is given.
168
+ */
169
+ op_policy_uri?: string;
170
+ /**
171
+ * URL that the OpenID Provider provides to the person registering the Client to read about OpenID Provider's terms of service. The registration process SHOULD display this URL to the person registering the Client if it is given.
172
+ */
173
+ op_tos_uri?: string;
174
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/authorization/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Oauth2 callback window</title>
6
+ <style>*[hidden] { display: none; } </style>
7
+ </head>
8
+ <body>
9
+ <h1>Sending the authorization data to the application</h1>
10
+ <p id="general-error" hidden>
11
+ The window wasn't opened as a popup and therefore it can't pass the authorization information.<br/>
12
+ This is an error.
13
+ </p>
14
+ <script>
15
+ const messageTarget = (window.opener || window.parent || window.top);
16
+ if (!messageTarget || messageTarget === window || !messageTarget.postMessage) {
17
+ const elm = document.getElementById('general-error');
18
+ elm.removeAttribute('hidden');
19
+ } else {
20
+ const search = window.location.search.substr(1);
21
+ if (search) {
22
+ messageTarget.postMessage(search, '*');
23
+ } else {
24
+ messageTarget.postMessage(window.location.hash.substr(1), '*');
25
+ }
26
+ }
27
+ </script>
28
+ </body>
29
+ </html>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.5.20",
4
+ "version": "0.5.21",
5
5
  "license": "Apache-2.0",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",
@@ -50,9 +50,11 @@
50
50
  "eslint-plugin-unused-imports": "^2.0.0",
51
51
  "express": "^4.17.1",
52
52
  "express-ntlm": "^2.6.1",
53
+ "get-port": "^6.1.2",
53
54
  "husky": "^7.0.4",
54
55
  "lint-staged": "^12.3.4",
55
56
  "mocha": "^9.1.3",
57
+ "oauth2-mock-server": "^4.3.1",
56
58
  "shrink-ray-current": "^4.1.3",
57
59
  "sinon": "^13.0.1",
58
60
  "source-map-support": "^0.5.21",
@@ -0,0 +1,25 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ /**
3
+ * An object describing an error during the authorization process.
4
+ */
5
+ export class AuthorizationError extends Error {
6
+ /**
7
+ * @param message The human readable message.
8
+ * @param code The error code
9
+ * @param state Used state parameter
10
+ * @param interactive Whether the request was interactive.
11
+ */
12
+ constructor(message: string, public code: string, public state: string, public interactive: boolean) {
13
+ super(message);
14
+ }
15
+ }
16
+
17
+ export class CodeError extends Error {
18
+ /**
19
+ * @param message The human readable message.
20
+ * @param code The error code
21
+ */
22
+ constructor(message: string, public code: string) {
23
+ super(message);
24
+ }
25
+ }
@@ -0,0 +1,61 @@
1
+ import { IOAuth2AuthorizationRequestCustomData, IOAuth2CustomData } from "../models/Authorization.js";
2
+
3
+ /**
4
+ * Applies custom properties defined in the OAuth settings object to the URL.
5
+ *
6
+ * @param url The instance of the URL class to use
7
+ * @param data `customData.[type]` property from the settings object. The type is either `auth` or `token`.
8
+ */
9
+ export function applyCustomSettingsQuery(url: URL, data: IOAuth2AuthorizationRequestCustomData): void {
10
+ if (!data || !data.parameters) {
11
+ return;
12
+ }
13
+ data.parameters.forEach((item) => {
14
+ const { name, value='' } = item;
15
+ if (!name) {
16
+ return;
17
+ }
18
+ url.searchParams.set(name, value);
19
+ });
20
+ }
21
+
22
+ /**
23
+ * Applies custom body properties from the settings to the body value.
24
+ *
25
+ * @param body Already computed body for OAuth request. Custom properties are appended at the end of OAuth string.
26
+ * @param data Value of settings' `customData` property
27
+ * @returns Request body
28
+ */
29
+ export function applyCustomSettingsBody(body: string, data: IOAuth2CustomData): string {
30
+ if (!data || !data.token || !data.token.body) {
31
+ return body;
32
+ }
33
+ const params = data.token.body.map((item) => {
34
+ let { value } = item;
35
+ if (value) {
36
+ value = encodeURIComponent(value);
37
+ } else {
38
+ value = '';
39
+ }
40
+ return `${encodeURIComponent(item.name)}=${value}`;
41
+ }).join('&');
42
+ return `${body}&${params}`;
43
+ }
44
+
45
+ /**
46
+ * Applies custom headers from the settings object
47
+ *
48
+ * @param headers A regular JS map with headers definition
49
+ * @param data Value of settings' `customData` property
50
+ * @returns The copy of the headers object, if it was altered. Otherwise the same object.
51
+ */
52
+ export function applyCustomSettingsHeaders(headers: Record<string, string>, data: IOAuth2CustomData): Record<string, string> {
53
+ if (!data || !data.token || !data.token.headers) {
54
+ return headers;
55
+ }
56
+ const copy = { ...headers };
57
+ data.token.headers.forEach((item) => {
58
+ copy[item.name] = item.value;
59
+ });
60
+ return copy;
61
+ }