altair-graphql-core 6.4.2 → 7.0.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/build/authorization/providers/oauth2.d.ts +10 -0
- package/build/authorization/providers/oauth2.js +11 -0
- package/build/cjs/authorization/providers/oauth2.d.ts +10 -0
- package/build/cjs/authorization/providers/oauth2.js +14 -0
- package/build/cjs/config.d.ts +6 -1
- package/build/cjs/config.js +15 -13
- package/build/cjs/oauth2/client.d.ts +34 -0
- package/build/cjs/oauth2/client.js +95 -0
- package/build/cjs/oauth2/client.spec.d.ts +2 -0
- package/build/cjs/oauth2/client.spec.js +25 -0
- package/build/cjs/oauth2/events.d.ts +6 -0
- package/build/cjs/oauth2/events.js +9 -0
- package/build/cjs/oauth2/helpers.d.ts +6 -0
- package/build/cjs/oauth2/helpers.js +44 -0
- package/build/cjs/oauth2/helpers.spec.d.ts +2 -0
- package/build/cjs/oauth2/helpers.spec.js +55 -0
- package/build/cjs/oauth2/index.d.ts +5 -0
- package/build/cjs/oauth2/index.js +21 -0
- package/build/cjs/oauth2/types.d.ts +89 -0
- package/build/cjs/oauth2/types.js +9 -0
- package/build/cjs/origins.d.ts +2 -0
- package/build/cjs/origins.js +14 -0
- package/build/cjs/script/context.d.ts +6 -0
- package/build/cjs/script/context.js +115 -0
- package/build/cjs/script/errors.d.ts +5 -0
- package/build/cjs/script/errors.js +13 -0
- package/build/cjs/script/evaluator-client-engine.d.ts +11 -0
- package/build/cjs/script/evaluator-client-engine.js +78 -0
- package/build/cjs/script/evaluator-engine.d.ts +3 -0
- package/build/cjs/script/evaluator-engine.js +7 -0
- package/build/cjs/script/evaluator-worker-engine.d.ts +12 -0
- package/build/cjs/script/evaluator-worker-engine.js +94 -0
- package/build/cjs/script/events.d.ts +5 -0
- package/build/cjs/script/events.js +9 -0
- package/build/cjs/script/types.d.ts +136 -0
- package/build/cjs/script/types.js +23 -0
- package/build/cjs/theme/theme.d.ts +1 -1
- package/build/cjs/theme/theme.js +13 -4
- package/build/cjs/types/state/authorization.interface.d.ts +3 -2
- package/build/cjs/types/state/authorization.interface.js +1 -0
- package/build/cjs/types/state/dialog.interfaces.d.ts +1 -0
- package/build/cjs/types/state/environments.interfaces.d.ts +4 -0
- package/build/cjs/types/state/query.interfaces.d.ts +2 -1
- package/build/cjs/utils/logger.d.ts +8 -2
- package/build/config.d.ts +6 -1
- package/build/config.js +16 -14
- package/build/oauth2/client.d.ts +34 -0
- package/build/oauth2/client.js +91 -0
- package/build/oauth2/client.spec.d.ts +2 -0
- package/build/oauth2/client.spec.js +23 -0
- package/build/oauth2/events.d.ts +6 -0
- package/build/oauth2/events.js +6 -0
- package/build/oauth2/helpers.d.ts +6 -0
- package/build/oauth2/helpers.js +36 -0
- package/build/oauth2/helpers.spec.d.ts +2 -0
- package/build/oauth2/helpers.spec.js +53 -0
- package/build/oauth2/index.d.ts +5 -0
- package/build/oauth2/index.js +5 -0
- package/build/oauth2/types.d.ts +89 -0
- package/build/oauth2/types.js +6 -0
- package/build/origins.d.ts +2 -0
- package/build/origins.js +11 -0
- package/build/partial_settings.schema.json +139 -0
- package/build/script/context.d.ts +6 -0
- package/build/script/context.js +86 -0
- package/build/script/errors.d.ts +5 -0
- package/build/script/errors.js +9 -0
- package/build/script/evaluator-client-engine.d.ts +11 -0
- package/build/script/evaluator-client-engine.js +74 -0
- package/build/script/evaluator-engine.d.ts +3 -0
- package/build/script/evaluator-engine.js +3 -0
- package/build/script/evaluator-worker-engine.d.ts +12 -0
- package/build/script/evaluator-worker-engine.js +90 -0
- package/build/script/events.d.ts +5 -0
- package/build/script/events.js +4 -0
- package/build/script/types.d.ts +136 -0
- package/build/script/types.js +18 -0
- package/build/settings.schema.json +139 -0
- package/build/theme/theme.d.ts +1 -1
- package/build/theme/theme.js +13 -4
- package/build/types/state/authorization.interface.d.ts +3 -2
- package/build/types/state/authorization.interface.js +1 -0
- package/build/types/state/dialog.interfaces.d.ts +1 -0
- package/build/types/state/environments.interfaces.d.ts +4 -0
- package/build/types/state/query.interfaces.d.ts +2 -1
- package/build/utils/logger.d.ts +8 -2
- package/build/validate-partial-settings.d.ts +4 -0
- package/build/validate-partial-settings.js +1 -0
- package/build/validate-settings.d.ts +4 -0
- package/build/validate-settings.js +1 -0
- package/jest.config.js +3 -2
- package/jest.setup.js +26 -0
- package/package.json +8 -4
- package/scripts/copy_settings_d_ts.js +30 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AccessTokenResponse } from '../../oauth2';
|
|
2
|
+
import { AuthorizationResult } from '../../types/state/authorization.interface';
|
|
3
|
+
import { AuthorizationProvider, AuthorizationProviderExecuteOptions } from '../authorization-provider';
|
|
4
|
+
export interface OAuth2AuthorizationProviderData {
|
|
5
|
+
accessTokenResponse: AccessTokenResponse;
|
|
6
|
+
}
|
|
7
|
+
export default class OAuth2AuthorizationProvider extends AuthorizationProvider<OAuth2AuthorizationProviderData> {
|
|
8
|
+
execute(options: AuthorizationProviderExecuteOptions<OAuth2AuthorizationProviderData>): Promise<AuthorizationResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=oauth2.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AuthorizationProvider, } from '../authorization-provider';
|
|
2
|
+
export default class OAuth2AuthorizationProvider extends AuthorizationProvider {
|
|
3
|
+
async execute(options) {
|
|
4
|
+
return {
|
|
5
|
+
headers: {
|
|
6
|
+
Authorization: `Bearer ${this.hydrate(options.data.accessTokenResponse.access_token)}`,
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=oauth2.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AccessTokenResponse } from '../../oauth2';
|
|
2
|
+
import { AuthorizationResult } from '../../types/state/authorization.interface';
|
|
3
|
+
import { AuthorizationProvider, AuthorizationProviderExecuteOptions } from '../authorization-provider';
|
|
4
|
+
export interface OAuth2AuthorizationProviderData {
|
|
5
|
+
accessTokenResponse: AccessTokenResponse;
|
|
6
|
+
}
|
|
7
|
+
export default class OAuth2AuthorizationProvider extends AuthorizationProvider<OAuth2AuthorizationProviderData> {
|
|
8
|
+
execute(options: AuthorizationProviderExecuteOptions<OAuth2AuthorizationProviderData>): Promise<AuthorizationResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=oauth2.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const authorization_provider_1 = require("../authorization-provider");
|
|
4
|
+
class OAuth2AuthorizationProvider extends authorization_provider_1.AuthorizationProvider {
|
|
5
|
+
async execute(options) {
|
|
6
|
+
return {
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${this.hydrate(options.data.accessTokenResponse.access_token)}`,
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = OAuth2AuthorizationProvider;
|
|
14
|
+
//# sourceMappingURL=oauth2.js.map
|
package/build/cjs/config.d.ts
CHANGED
|
@@ -99,6 +99,10 @@ export interface AltairConfigOptions extends AltairWindowOptions {
|
|
|
99
99
|
* List of options for windows to be loaded
|
|
100
100
|
*/
|
|
101
101
|
initialWindows?: AltairWindowOptions[];
|
|
102
|
+
/**
|
|
103
|
+
* Persisted settings for the app. The settings will be merged with the app settings.
|
|
104
|
+
*/
|
|
105
|
+
persistedSettings?: Partial<SettingsState>;
|
|
102
106
|
/**
|
|
103
107
|
* Disable the account and remote syncing functionality
|
|
104
108
|
*/
|
|
@@ -150,6 +154,7 @@ export declare class AltairConfig {
|
|
|
150
154
|
postRequestScript: string;
|
|
151
155
|
instanceStorageNamespace: string;
|
|
152
156
|
settings: Partial<SettingsState> | undefined;
|
|
157
|
+
persistedSettings: Partial<SettingsState> | undefined;
|
|
153
158
|
initialSubscriptionsProvider: SubscriptionProviderIds | undefined;
|
|
154
159
|
initialSubscriptionsPayload: IDictionary;
|
|
155
160
|
initialHttpMethod: "POST" | "GET" | "PUT" | "DELETE";
|
|
@@ -157,7 +162,7 @@ export declare class AltairConfig {
|
|
|
157
162
|
windows: AltairWindowOptions[];
|
|
158
163
|
disableAccount: boolean;
|
|
159
164
|
};
|
|
160
|
-
constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, initialSubscriptionsProvider, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, disableAccount, }?: AltairConfigOptions);
|
|
165
|
+
constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript, instanceStorageNamespace, initialSettings, persistedSettings, initialSubscriptionsProvider, initialSubscriptionsPayload, initialHttpMethod, preserveState, initialWindows, disableAccount, }?: AltairConfigOptions);
|
|
161
166
|
}
|
|
162
167
|
export declare const setAltairConfig: (_config: AltairConfig) => void;
|
|
163
168
|
export declare const getAltairConfig: () => AltairConfig;
|
package/build/cjs/config.js
CHANGED
|
@@ -8,7 +8,7 @@ const subscriptions_1 = require("./subscriptions");
|
|
|
8
8
|
const is_electron_1 = __importDefault(require("./utils/is_electron"));
|
|
9
9
|
const isTranslateMode = window.__ALTAIR_TRANSLATE__;
|
|
10
10
|
class AltairConfig {
|
|
11
|
-
constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript = '', instanceStorageNamespace, initialSettings, initialSubscriptionsProvider = subscriptions_1.WEBSOCKET_PROVIDER_ID, initialSubscriptionsPayload = {}, initialHttpMethod = 'POST', preserveState = true, initialWindows = [], disableAccount = false, } = {}) {
|
|
11
|
+
constructor({ endpointURL, subscriptionsEndpoint, subscriptionsProtocol, initialQuery, initialHeaders, initialEnvironments, initialVariables, initialPreRequestScript, initialPostRequestScript = '', instanceStorageNamespace, initialSettings, persistedSettings, initialSubscriptionsProvider = subscriptions_1.WEBSOCKET_PROVIDER_ID, initialSubscriptionsPayload = {}, initialHttpMethod = 'POST', preserveState = true, initialWindows = [], disableAccount = false, } = {}) {
|
|
12
12
|
this.donation = {
|
|
13
13
|
url: 'https://opencollective.com/altair/donate',
|
|
14
14
|
action_count_threshold: 50,
|
|
@@ -55,6 +55,7 @@ class AltairConfig {
|
|
|
55
55
|
postRequestScript: '',
|
|
56
56
|
instanceStorageNamespace: 'altair_',
|
|
57
57
|
settings: undefined,
|
|
58
|
+
persistedSettings: undefined,
|
|
58
59
|
initialSubscriptionsProvider: undefined,
|
|
59
60
|
initialSubscriptionsPayload: {},
|
|
60
61
|
initialHttpMethod: 'POST',
|
|
@@ -63,29 +64,30 @@ class AltairConfig {
|
|
|
63
64
|
disableAccount: false,
|
|
64
65
|
};
|
|
65
66
|
this.initialData.url =
|
|
66
|
-
window.__ALTAIR_ENDPOINT_URL__
|
|
67
|
+
window.__ALTAIR_ENDPOINT_URL__ ?? endpointURL ?? '';
|
|
67
68
|
this.initialData.subscriptionsEndpoint =
|
|
68
|
-
window.__ALTAIR_SUBSCRIPTIONS_ENDPOINT__
|
|
69
|
-
subscriptionsEndpoint
|
|
69
|
+
window.__ALTAIR_SUBSCRIPTIONS_ENDPOINT__ ??
|
|
70
|
+
subscriptionsEndpoint ??
|
|
70
71
|
'';
|
|
71
|
-
this.initialData.subscriptionsProtocol = subscriptionsProtocol
|
|
72
|
+
this.initialData.subscriptionsProtocol = subscriptionsProtocol ?? '';
|
|
72
73
|
this.initialData.query =
|
|
73
|
-
window.__ALTAIR_INITIAL_QUERY__
|
|
74
|
+
window.__ALTAIR_INITIAL_QUERY__ ?? initialQuery ?? '';
|
|
74
75
|
this.initialData.variables =
|
|
75
|
-
window.__ALTAIR_INITIAL_VARIABLES__
|
|
76
|
+
window.__ALTAIR_INITIAL_VARIABLES__ ?? initialVariables ?? '';
|
|
76
77
|
this.initialData.headers =
|
|
77
|
-
window.__ALTAIR_INITIAL_HEADERS__
|
|
78
|
-
this.initialData.environments = initialEnvironments
|
|
78
|
+
window.__ALTAIR_INITIAL_HEADERS__ ?? initialHeaders ?? '';
|
|
79
|
+
this.initialData.environments = initialEnvironments ?? {};
|
|
79
80
|
this.initialData.preRequestScript =
|
|
80
|
-
window.__ALTAIR_INITIAL_PRE_REQUEST_SCRIPT__
|
|
81
|
-
initialPreRequestScript
|
|
81
|
+
window.__ALTAIR_INITIAL_PRE_REQUEST_SCRIPT__ ??
|
|
82
|
+
initialPreRequestScript ??
|
|
82
83
|
'';
|
|
83
84
|
this.initialData.postRequestScript = initialPostRequestScript;
|
|
84
85
|
this.initialData.instanceStorageNamespace =
|
|
85
|
-
window.__ALTAIR_INSTANCE_STORAGE_NAMESPACE__
|
|
86
|
-
instanceStorageNamespace
|
|
86
|
+
window.__ALTAIR_INSTANCE_STORAGE_NAMESPACE__ ??
|
|
87
|
+
instanceStorageNamespace ??
|
|
87
88
|
'altair_';
|
|
88
89
|
this.initialData.settings = initialSettings;
|
|
90
|
+
this.initialData.persistedSettings = persistedSettings;
|
|
89
91
|
this.initialData.initialSubscriptionsProvider = initialSubscriptionsProvider;
|
|
90
92
|
this.initialData.initialSubscriptionsPayload = initialSubscriptionsPayload;
|
|
91
93
|
this.initialData.initialHttpMethod = initialHttpMethod;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AccessTokenErrorResponse, AccessTokenResponse, AuthorizationRedirectErrorResponse, AuthorizationRedirectResponse, OAuth2Type } from './types';
|
|
2
|
+
interface CommonOAuth2ClientOptions {
|
|
3
|
+
clientId: string;
|
|
4
|
+
redirectUri: string;
|
|
5
|
+
scopes: string[];
|
|
6
|
+
/**
|
|
7
|
+
* An opaque string used to store request-specific data and/or prevent CSRF attacks by verifying the value of state later
|
|
8
|
+
*/
|
|
9
|
+
state: string;
|
|
10
|
+
}
|
|
11
|
+
interface AuthorizationCode_OAuth2ClientOptions extends CommonOAuth2ClientOptions {
|
|
12
|
+
type: OAuth2Type.AUTHORIZATION_CODE;
|
|
13
|
+
clientSecret: string;
|
|
14
|
+
authorizationEndpoint: string;
|
|
15
|
+
tokenEndpoint: string;
|
|
16
|
+
}
|
|
17
|
+
interface AuthorizationCodePKCE_OAuth2ClientOptions extends Omit<AuthorizationCode_OAuth2ClientOptions, 'type'> {
|
|
18
|
+
type: OAuth2Type.AUTHORIZATION_CODE_PKCE;
|
|
19
|
+
/**
|
|
20
|
+
* A cryptographically random string between 43 and 128 characters long that will be used to verify the authorization code
|
|
21
|
+
* using the character set [A-Z, a-z, 0-9, "-", ".", "_", "~"]
|
|
22
|
+
*/
|
|
23
|
+
codeVerifier: string;
|
|
24
|
+
}
|
|
25
|
+
export type OAuth2ClientOptions = AuthorizationCode_OAuth2ClientOptions | AuthorizationCodePKCE_OAuth2ClientOptions;
|
|
26
|
+
export declare class OAuth2Client {
|
|
27
|
+
private options;
|
|
28
|
+
constructor(options: OAuth2ClientOptions);
|
|
29
|
+
getAuthorizationUrl(): Promise<string>;
|
|
30
|
+
getAuthorizationRedirectResponse(): Promise<AuthorizationRedirectResponse | AuthorizationRedirectErrorResponse | undefined>;
|
|
31
|
+
getAccessTokenFromCode(code: string): Promise<AccessTokenResponse | AccessTokenErrorResponse>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuth2Client = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
class OAuth2Client {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
async getAuthorizationUrl() {
|
|
10
|
+
const params = {
|
|
11
|
+
response_type: 'code',
|
|
12
|
+
client_id: this.options.clientId,
|
|
13
|
+
redirect_uri: this.options.redirectUri,
|
|
14
|
+
state: this.options.state,
|
|
15
|
+
scope: this.options.scopes.join(' '),
|
|
16
|
+
...(this.options.type === 'auth_code_pkce'
|
|
17
|
+
? {
|
|
18
|
+
code_challenge: await (0, helpers_1.getCodeChallenge)(this.options.codeVerifier),
|
|
19
|
+
code_challenge_method: 'S256',
|
|
20
|
+
}
|
|
21
|
+
: {}),
|
|
22
|
+
};
|
|
23
|
+
const urlParams = new URLSearchParams(params);
|
|
24
|
+
const u = new URL(this.options.authorizationEndpoint);
|
|
25
|
+
const url = new URL(`${u.origin}${u.pathname}?${urlParams.toString()}`);
|
|
26
|
+
return url.toString();
|
|
27
|
+
}
|
|
28
|
+
async getAuthorizationRedirectResponse() {
|
|
29
|
+
// Get params from url
|
|
30
|
+
const url = new URL(window.location.href);
|
|
31
|
+
const obj = Object.fromEntries(url.searchParams.entries());
|
|
32
|
+
if (obj.error) {
|
|
33
|
+
return {
|
|
34
|
+
error: obj.error,
|
|
35
|
+
state: obj.state ?? '',
|
|
36
|
+
error_description: obj.error_description,
|
|
37
|
+
error_uri: obj.error_uri,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Validate params
|
|
41
|
+
if (!obj.code || !obj.state) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// verify state is the same as the one generated
|
|
45
|
+
if (obj.state !== this.options.state) {
|
|
46
|
+
return {
|
|
47
|
+
error: 'invalid_state',
|
|
48
|
+
state: obj.state,
|
|
49
|
+
error_description: 'The state is invalid',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// Return params
|
|
53
|
+
return { code: obj.code, state: obj.state };
|
|
54
|
+
}
|
|
55
|
+
// Since this will be a CORS request, we only support it in the desktop app for now
|
|
56
|
+
async getAccessTokenFromCode(code) {
|
|
57
|
+
const params = {
|
|
58
|
+
grant_type: 'authorization_code',
|
|
59
|
+
code,
|
|
60
|
+
redirect_uri: this.options.redirectUri,
|
|
61
|
+
client_id: this.options.clientId,
|
|
62
|
+
client_secret: this.options.clientSecret,
|
|
63
|
+
...(this.options.type === 'auth_code_pkce'
|
|
64
|
+
? { code_verifier: this.options.codeVerifier }
|
|
65
|
+
: {}),
|
|
66
|
+
};
|
|
67
|
+
const response = await fetch(this.options.tokenEndpoint, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
Accept: 'application/json',
|
|
71
|
+
'Content-Type': 'application/json',
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(params),
|
|
74
|
+
});
|
|
75
|
+
const data = await response.json();
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.OAuth2Client = OAuth2Client;
|
|
80
|
+
/*
|
|
81
|
+
in app:
|
|
82
|
+
listen for ready message from auth window
|
|
83
|
+
send [options + action] to the auth window
|
|
84
|
+
listen for authorization code from auth window
|
|
85
|
+
close auth window
|
|
86
|
+
exchange code for access token
|
|
87
|
+
|
|
88
|
+
in auth window:
|
|
89
|
+
send ready message to app
|
|
90
|
+
listen for options message from app
|
|
91
|
+
- redirect to authorization url
|
|
92
|
+
- get code from url
|
|
93
|
+
- send code to app
|
|
94
|
+
*/
|
|
95
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const globals_1 = require("@jest/globals");
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
(0, globals_1.describe)('oauth2 client', () => {
|
|
7
|
+
(0, globals_1.describe)('getAuthorizationUrl', () => {
|
|
8
|
+
(0, globals_1.it)('should return the authorization url', async () => {
|
|
9
|
+
const client = new client_1.OAuth2Client({
|
|
10
|
+
type: types_1.OAuth2Type.AUTHORIZATION_CODE_PKCE,
|
|
11
|
+
authorizationEndpoint: 'https://auth-server.com/oauth/authorize',
|
|
12
|
+
tokenEndpoint: 'https://auth-server.com/oauth/token',
|
|
13
|
+
clientId: 'clientId',
|
|
14
|
+
clientSecret: 'clientSecret',
|
|
15
|
+
redirectUri: 'redirectUri',
|
|
16
|
+
scopes: ['scope1', 'scope2'],
|
|
17
|
+
codeVerifier: 'codeVerifier',
|
|
18
|
+
state: 'random-state',
|
|
19
|
+
});
|
|
20
|
+
const url = await client.getAuthorizationUrl();
|
|
21
|
+
(0, globals_1.expect)(url).toBe('https://auth-server.com/oauth/authorize?response_type=code&client_id=clientId&redirect_uri=redirectUri&state=random-state&scope=scope1+scope2&code_challenge=N1E4yRMD7xixn_oFyO_W3htYN3rY7-HMDKJe6z6r928&code_challenge_method=S256');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=client.spec.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVENT_TYPES = void 0;
|
|
4
|
+
exports.EVENT_TYPES = {
|
|
5
|
+
FRAME_READY: 'frame-ready',
|
|
6
|
+
ACTION: 'action',
|
|
7
|
+
AUTHORIZATION_CODE: 'authorization-code',
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const secureRandomString: (length?: number) => string;
|
|
2
|
+
export declare const base64UrlEncode: (buffer: ArrayBuffer) => string;
|
|
3
|
+
export declare const sha256: (str: string) => Promise<ArrayBuffer>;
|
|
4
|
+
export declare const hex: (buffer: ArrayBuffer) => string;
|
|
5
|
+
export declare const getCodeChallenge: (codeVerifier: string) => Promise<string>;
|
|
6
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCodeChallenge = exports.hex = exports.sha256 = exports.base64UrlEncode = exports.secureRandomString = void 0;
|
|
4
|
+
const secureRandomString = (length = 16) => {
|
|
5
|
+
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
|
|
6
|
+
const randomValues = new Uint32Array(length);
|
|
7
|
+
window.crypto.getRandomValues(randomValues);
|
|
8
|
+
return Array.from(randomValues)
|
|
9
|
+
.map((x) => charset[x % charset.length])
|
|
10
|
+
.join('');
|
|
11
|
+
};
|
|
12
|
+
exports.secureRandomString = secureRandomString;
|
|
13
|
+
// https://thewoods.blog/base64url/
|
|
14
|
+
const base64UrlEncode = (buffer) => {
|
|
15
|
+
return btoa(Array.from(new Uint8Array(buffer), (b) => String.fromCharCode(b)).join(''))
|
|
16
|
+
.replace(/\+/g, '-')
|
|
17
|
+
.replace(/\//g, '_')
|
|
18
|
+
.replace(/={1,4}$/, '');
|
|
19
|
+
};
|
|
20
|
+
exports.base64UrlEncode = base64UrlEncode;
|
|
21
|
+
const sha256 = async (str) => {
|
|
22
|
+
const buffer = new TextEncoder().encode(str);
|
|
23
|
+
const hashBuffer = await window.crypto.subtle.digest('SHA-256', buffer);
|
|
24
|
+
return hashBuffer;
|
|
25
|
+
};
|
|
26
|
+
exports.sha256 = sha256;
|
|
27
|
+
const hex = (buffer) => {
|
|
28
|
+
const hexCodes = [];
|
|
29
|
+
const view = new DataView(buffer);
|
|
30
|
+
for (let i = 0; i < view.byteLength; i += 4) {
|
|
31
|
+
const value = view.getUint32(i);
|
|
32
|
+
const stringValue = value.toString(16);
|
|
33
|
+
const padding = '00000000';
|
|
34
|
+
const paddedValue = (padding + stringValue).slice(-padding.length);
|
|
35
|
+
hexCodes.push(paddedValue);
|
|
36
|
+
}
|
|
37
|
+
return hexCodes.join('');
|
|
38
|
+
};
|
|
39
|
+
exports.hex = hex;
|
|
40
|
+
const getCodeChallenge = async (codeVerifier) => {
|
|
41
|
+
return (0, exports.base64UrlEncode)(await (0, exports.sha256)(codeVerifier));
|
|
42
|
+
};
|
|
43
|
+
exports.getCodeChallenge = getCodeChallenge;
|
|
44
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const globals_1 = require("@jest/globals");
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
(0, globals_1.describe)('oauth2 helpers', () => {
|
|
6
|
+
(0, globals_1.describe)('secureRandomString', () => {
|
|
7
|
+
(0, globals_1.it)('should generate a random string', () => {
|
|
8
|
+
const out = (0, helpers_1.secureRandomString)(64);
|
|
9
|
+
(0, globals_1.expect)(out).toHaveLength(64);
|
|
10
|
+
});
|
|
11
|
+
(0, globals_1.it)('should generate a code verifier spec compliant string', () => {
|
|
12
|
+
const out = (0, helpers_1.secureRandomString)(128);
|
|
13
|
+
(0, globals_1.expect)(out).toMatch(/^[A-Za-z0-9\-._~]{43,128}$/);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
(0, globals_1.describe)('base64UrlEncode', () => {
|
|
17
|
+
(0, globals_1.it)('should encode a string to base64url', () => {
|
|
18
|
+
const out = (0, helpers_1.base64UrlEncode)(new TextEncoder().encode('hello world'));
|
|
19
|
+
(0, globals_1.expect)(out).toBe('aGVsbG8gd29ybGQ');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
(0, globals_1.describe)('sha256', () => {
|
|
23
|
+
(0, globals_1.it)('should hash a string using SHA-256', async () => {
|
|
24
|
+
const str = JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } });
|
|
25
|
+
const out = await (0, helpers_1.sha256)(str);
|
|
26
|
+
const hexed = (0, helpers_1.hex)(out);
|
|
27
|
+
(0, globals_1.expect)(hexed).toBe('04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
(0, globals_1.describe)('getCodeChallenge', () => {
|
|
31
|
+
globals_1.it.each([
|
|
32
|
+
// random samples from https://example-app.com/pkce
|
|
33
|
+
[
|
|
34
|
+
'075f4a07eb8e645d4857f9c8debd85fc867e963da49a7f76583ed453',
|
|
35
|
+
'boifgebQR7BmZyyNRkG-Q8B-f-Ex8VGD3hRK1tTfmic',
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'd874bb0fcb35b0a7b52af7c3f3fc5180667fe427ba3dedbfa0dadd5b',
|
|
39
|
+
'I8r8ci9TjlPpOvU6Vm32Ya3sLXIS4XVQwZ4_hrFWIz8',
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
'63a4b655ae5a4e2204d984f516c8c36b628b040fbd1840fb546e943a',
|
|
43
|
+
'CiU3jN5rx9NMCmgFG-PETaoPTlBjkhT9U6bH68CoUdk',
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
'bWrd3MfgGswVQXR54T3nnXY7lGgnIDrpcFEL5cSqxrdQpZCP30Ls5UKuviRS2R6kwtbOUyFjtKjthuZe6MucVdZtXZFrr9v2BkydYvGbAB7FOx6_-_whBvhF1XNpC9il',
|
|
47
|
+
'entSJG70NsTQypzbSNd6Koq6Zv2hBT6aXpHncJ5AX8M',
|
|
48
|
+
],
|
|
49
|
+
])('should encode a string to base64url', async (str, expected) => {
|
|
50
|
+
const out = await (0, helpers_1.getCodeChallenge)(str);
|
|
51
|
+
(0, globals_1.expect)(out).toBe(expected);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=helpers.spec.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client"), exports);
|
|
18
|
+
__exportStar(require("./helpers"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./events"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export declare enum OAuth2Type {
|
|
2
|
+
AUTHORIZATION_CODE = "auth_code",
|
|
3
|
+
AUTHORIZATION_CODE_PKCE = "auth_code_pkce"
|
|
4
|
+
}
|
|
5
|
+
export interface SimpleAuthorizationRequestParams extends Record<string, string> {
|
|
6
|
+
response_type: 'code';
|
|
7
|
+
/**
|
|
8
|
+
* The client ID of your application
|
|
9
|
+
*/
|
|
10
|
+
client_id: string;
|
|
11
|
+
/**
|
|
12
|
+
* The URL in your app where users will be sent after authorization
|
|
13
|
+
*/
|
|
14
|
+
redirect_uri: string;
|
|
15
|
+
/**
|
|
16
|
+
* A random string generated by your application, which you'll verify later
|
|
17
|
+
*/
|
|
18
|
+
state: string;
|
|
19
|
+
/**
|
|
20
|
+
* A space-separated list of scopes
|
|
21
|
+
*/
|
|
22
|
+
scope: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CodeChallengeAuthorizationRequestParams extends SimpleAuthorizationRequestParams {
|
|
25
|
+
code_challenge: string;
|
|
26
|
+
code_challenge_method: 'S256';
|
|
27
|
+
}
|
|
28
|
+
export type AuthorizationRequestParams = SimpleAuthorizationRequestParams | CodeChallengeAuthorizationRequestParams;
|
|
29
|
+
export interface AuthorizationRedirectResponse {
|
|
30
|
+
/**
|
|
31
|
+
* The authorization code received from the authorization server
|
|
32
|
+
*/
|
|
33
|
+
code: string;
|
|
34
|
+
/**
|
|
35
|
+
* The exact value of the state parameter passed by the client in the authorization request
|
|
36
|
+
*/
|
|
37
|
+
state: string;
|
|
38
|
+
}
|
|
39
|
+
export interface AuthorizationRedirectErrorResponse {
|
|
40
|
+
error: string;
|
|
41
|
+
state: string;
|
|
42
|
+
error_description?: string;
|
|
43
|
+
error_uri?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface AuthorizationCode_AccessTokenRequest {
|
|
46
|
+
grant_type: 'authorization_code';
|
|
47
|
+
/**
|
|
48
|
+
* The authorization code received from the authorization server
|
|
49
|
+
*/
|
|
50
|
+
code: string;
|
|
51
|
+
/**
|
|
52
|
+
* The redirect URI used in the initial request
|
|
53
|
+
*/
|
|
54
|
+
redirect_uri: string;
|
|
55
|
+
client_id: string;
|
|
56
|
+
client_secret: string;
|
|
57
|
+
}
|
|
58
|
+
export interface AuthorizationCodePKCE_AccessTokenRequest extends AuthorizationCode_AccessTokenRequest {
|
|
59
|
+
code_verifier: string;
|
|
60
|
+
}
|
|
61
|
+
export type AccessTokenRequest = AuthorizationCode_AccessTokenRequest | AuthorizationCodePKCE_AccessTokenRequest;
|
|
62
|
+
export interface AccessTokenResponse {
|
|
63
|
+
/**
|
|
64
|
+
* The access token issued by the authorization server
|
|
65
|
+
*/
|
|
66
|
+
access_token: string;
|
|
67
|
+
/**
|
|
68
|
+
* The type of the token issued
|
|
69
|
+
*/
|
|
70
|
+
token_type: string;
|
|
71
|
+
/**
|
|
72
|
+
* The exact value of the state parameter passed by the client in the authorization request
|
|
73
|
+
*/
|
|
74
|
+
state: string;
|
|
75
|
+
/**
|
|
76
|
+
* The lifetime in seconds of the access token
|
|
77
|
+
*/
|
|
78
|
+
expires_in?: number;
|
|
79
|
+
refresh_token?: string;
|
|
80
|
+
id_token?: string;
|
|
81
|
+
scope?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface AccessTokenErrorResponse {
|
|
84
|
+
error: string;
|
|
85
|
+
state: string;
|
|
86
|
+
error_description?: string;
|
|
87
|
+
error_uri?: string;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuth2Type = void 0;
|
|
4
|
+
var OAuth2Type;
|
|
5
|
+
(function (OAuth2Type) {
|
|
6
|
+
OAuth2Type["AUTHORIZATION_CODE"] = "auth_code";
|
|
7
|
+
OAuth2Type["AUTHORIZATION_CODE_PKCE"] = "auth_code_pkce";
|
|
8
|
+
})(OAuth2Type || (exports.OAuth2Type = OAuth2Type = {}));
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validOrigins = void 0;
|
|
4
|
+
exports.validOrigins = [
|
|
5
|
+
'chrome-extension://flnheeellpciglgpaodhkhmapeljopja',
|
|
6
|
+
'chrome-extension://aiopipphfnlndegenpkclffgaiillbdd',
|
|
7
|
+
'moz-extension://567d7e27-43b8-994e-ab50-e770fa7eab4b',
|
|
8
|
+
'http://localhost:4200',
|
|
9
|
+
'https://dash.altairgraphql.dev',
|
|
10
|
+
'https://altair-gql.sirmuel.design',
|
|
11
|
+
'https://web.altairgraphql.dev',
|
|
12
|
+
'altair://-',
|
|
13
|
+
];
|
|
14
|
+
//# sourceMappingURL=origins.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GlobalContextBuilderHandlers, GlobalHelperContext, ModuleImportsMap, ScriptContextData, ScriptContextResponse } from './types';
|
|
2
|
+
export declare const ModuleImports: ModuleImportsMap;
|
|
3
|
+
export declare const buildContextResponse: (data: ScriptContextData) => ScriptContextResponse | undefined;
|
|
4
|
+
export declare const importModuleHelper: (moduleName: string) => Promise<any>;
|
|
5
|
+
export declare const getGlobalContext: (data: ScriptContextData, handlers: GlobalContextBuilderHandlers) => GlobalHelperContext;
|
|
6
|
+
//# sourceMappingURL=context.d.ts.map
|