@jbrowse/plugin-authentication 3.6.5 → 4.0.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/esm/DropboxOAuthModel/configSchema.d.ts +5 -5
- package/esm/DropboxOAuthModel/configSchema.js +1 -1
- package/esm/DropboxOAuthModel/index.d.ts +2 -2
- package/esm/DropboxOAuthModel/index.js +2 -2
- package/esm/DropboxOAuthModel/model.d.ts +18 -18
- package/esm/DropboxOAuthModel/model.js +5 -5
- package/esm/DropboxOAuthModel/util.js +1 -1
- package/esm/ExternalTokenModel/configSchema.d.ts +4 -4
- package/esm/ExternalTokenModel/index.d.ts +2 -2
- package/esm/ExternalTokenModel/index.js +2 -2
- package/esm/ExternalTokenModel/model.d.ts +13 -13
- package/esm/ExternalTokenModel/model.js +2 -2
- package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +1 -0
- package/esm/GoogleDriveOAuthModel/configSchema.d.ts +5 -5
- package/esm/GoogleDriveOAuthModel/configSchema.js +1 -1
- package/esm/GoogleDriveOAuthModel/index.d.ts +2 -2
- package/esm/GoogleDriveOAuthModel/index.js +2 -2
- package/esm/GoogleDriveOAuthModel/model.d.ts +19 -19
- package/esm/GoogleDriveOAuthModel/model.js +7 -7
- package/esm/GoogleDriveOAuthModel/util.js +1 -1
- package/esm/HTTPBasicModel/configSchema.d.ts +4 -4
- package/esm/HTTPBasicModel/index.d.ts +2 -2
- package/esm/HTTPBasicModel/index.js +2 -2
- package/esm/HTTPBasicModel/model.d.ts +13 -13
- package/esm/HTTPBasicModel/model.js +3 -3
- package/esm/OAuthModel/configSchema.d.ts +4 -4
- package/esm/OAuthModel/index.d.ts +2 -2
- package/esm/OAuthModel/index.js +2 -2
- package/esm/OAuthModel/model.d.ts +12 -12
- package/esm/OAuthModel/model.js +3 -3
- package/esm/OAuthModel/util.js +1 -2
- package/esm/index.d.ts +68 -68
- package/esm/index.js +23 -26
- package/esm/util.js +1 -1
- package/package.json +23 -30
- package/dist/DropboxOAuthModel/DropboxIcon.d.ts +0 -2
- package/dist/DropboxOAuthModel/DropboxIcon.js +0 -8
- package/dist/DropboxOAuthModel/configSchema.d.ts +0 -93
- package/dist/DropboxOAuthModel/configSchema.js +0 -42
- package/dist/DropboxOAuthModel/index.d.ts +0 -2
- package/dist/DropboxOAuthModel/index.js +0 -10
- package/dist/DropboxOAuthModel/model.d.ts +0 -279
- package/dist/DropboxOAuthModel/model.js +0 -65
- package/dist/DropboxOAuthModel/util.d.ts +0 -1
- package/dist/DropboxOAuthModel/util.js +0 -21
- package/dist/ExternalTokenModel/ExternalTokenEntryForm.d.ts +0 -4
- package/dist/ExternalTokenModel/ExternalTokenEntryForm.js +0 -24
- package/dist/ExternalTokenModel/configSchema.d.ts +0 -37
- package/dist/ExternalTokenModel/configSchema.js +0 -16
- package/dist/ExternalTokenModel/index.d.ts +0 -2
- package/dist/ExternalTokenModel/index.js +0 -10
- package/dist/ExternalTokenModel/model.d.ts +0 -126
- package/dist/ExternalTokenModel/model.js +0 -57
- package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +0 -15
- package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +0 -19
- package/dist/GoogleDriveOAuthModel/GoogleDriveIcon.d.ts +0 -2
- package/dist/GoogleDriveOAuthModel/GoogleDriveIcon.js +0 -8
- package/dist/GoogleDriveOAuthModel/configSchema.d.ts +0 -93
- package/dist/GoogleDriveOAuthModel/configSchema.js +0 -34
- package/dist/GoogleDriveOAuthModel/index.d.ts +0 -2
- package/dist/GoogleDriveOAuthModel/index.js +0 -10
- package/dist/GoogleDriveOAuthModel/model.d.ts +0 -283
- package/dist/GoogleDriveOAuthModel/model.js +0 -72
- package/dist/GoogleDriveOAuthModel/util.d.ts +0 -1
- package/dist/GoogleDriveOAuthModel/util.js +0 -14
- package/dist/HTTPBasicModel/HTTPBasicLoginForm.d.ts +0 -4
- package/dist/HTTPBasicModel/HTTPBasicLoginForm.js +0 -32
- package/dist/HTTPBasicModel/configSchema.d.ts +0 -42
- package/dist/HTTPBasicModel/configSchema.js +0 -21
- package/dist/HTTPBasicModel/index.d.ts +0 -2
- package/dist/HTTPBasicModel/index.js +0 -10
- package/dist/HTTPBasicModel/model.d.ts +0 -131
- package/dist/HTTPBasicModel/model.js +0 -54
- package/dist/OAuthModel/configSchema.d.ts +0 -72
- package/dist/OAuthModel/configSchema.js +0 -51
- package/dist/OAuthModel/index.d.ts +0 -2
- package/dist/OAuthModel/index.js +0 -10
- package/dist/OAuthModel/model.d.ts +0 -182
- package/dist/OAuthModel/model.js +0 -289
- package/dist/OAuthModel/util.d.ts +0 -7
- package/dist/OAuthModel/util.js +0 -66
- package/dist/index.d.ts +0 -1026
- package/dist/index.js +0 -84
- package/dist/util.d.ts +0 -6
- package/dist/util.js +0 -21
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { Instance } from 'mobx-state-tree';
|
|
2
|
-
declare const OAuthConfigSchema: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
|
|
3
|
-
tokenType: {
|
|
4
|
-
description: string;
|
|
5
|
-
type: string;
|
|
6
|
-
defaultValue: string;
|
|
7
|
-
};
|
|
8
|
-
authEndpoint: {
|
|
9
|
-
description: string;
|
|
10
|
-
type: string;
|
|
11
|
-
defaultValue: string;
|
|
12
|
-
};
|
|
13
|
-
tokenEndpoint: {
|
|
14
|
-
description: string;
|
|
15
|
-
type: string;
|
|
16
|
-
defaultValue: string;
|
|
17
|
-
};
|
|
18
|
-
needsPKCE: {
|
|
19
|
-
description: string;
|
|
20
|
-
type: string;
|
|
21
|
-
defaultValue: boolean;
|
|
22
|
-
};
|
|
23
|
-
clientId: {
|
|
24
|
-
description: string;
|
|
25
|
-
type: string;
|
|
26
|
-
defaultValue: string;
|
|
27
|
-
};
|
|
28
|
-
scopes: {
|
|
29
|
-
description: string;
|
|
30
|
-
type: string;
|
|
31
|
-
defaultValue: string;
|
|
32
|
-
};
|
|
33
|
-
state: {
|
|
34
|
-
description: string;
|
|
35
|
-
type: string;
|
|
36
|
-
defaultValue: string;
|
|
37
|
-
};
|
|
38
|
-
responseType: {
|
|
39
|
-
description: string;
|
|
40
|
-
type: string;
|
|
41
|
-
defaultValue: string;
|
|
42
|
-
};
|
|
43
|
-
}, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
|
|
44
|
-
name: {
|
|
45
|
-
description: string;
|
|
46
|
-
type: string;
|
|
47
|
-
defaultValue: string;
|
|
48
|
-
};
|
|
49
|
-
description: {
|
|
50
|
-
description: string;
|
|
51
|
-
type: string;
|
|
52
|
-
defaultValue: string;
|
|
53
|
-
};
|
|
54
|
-
authHeader: {
|
|
55
|
-
description: string;
|
|
56
|
-
type: string;
|
|
57
|
-
defaultValue: string;
|
|
58
|
-
};
|
|
59
|
-
tokenType: {
|
|
60
|
-
description: string;
|
|
61
|
-
type: string;
|
|
62
|
-
defaultValue: string;
|
|
63
|
-
};
|
|
64
|
-
domains: {
|
|
65
|
-
description: string;
|
|
66
|
-
type: string;
|
|
67
|
-
defaultValue: never[];
|
|
68
|
-
};
|
|
69
|
-
}, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>, undefined>>;
|
|
70
|
-
export type OAuthInternetAccountConfigModel = typeof OAuthConfigSchema;
|
|
71
|
-
export type OAuthInternetAccountConfig = Instance<OAuthInternetAccountConfigModel>;
|
|
72
|
-
export default OAuthConfigSchema;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const configuration_1 = require("@jbrowse/core/configuration");
|
|
4
|
-
const models_1 = require("@jbrowse/core/pluggableElementTypes/models");
|
|
5
|
-
function x() { }
|
|
6
|
-
const OAuthConfigSchema = (0, configuration_1.ConfigurationSchema)('OAuthInternetAccount', {
|
|
7
|
-
tokenType: {
|
|
8
|
-
description: 'a custom name for a token to include in the header',
|
|
9
|
-
type: 'string',
|
|
10
|
-
defaultValue: 'Bearer',
|
|
11
|
-
},
|
|
12
|
-
authEndpoint: {
|
|
13
|
-
description: 'the authorization code endpoint of the internet account',
|
|
14
|
-
type: 'string',
|
|
15
|
-
defaultValue: '',
|
|
16
|
-
},
|
|
17
|
-
tokenEndpoint: {
|
|
18
|
-
description: 'the token endpoint of the internet account',
|
|
19
|
-
type: 'string',
|
|
20
|
-
defaultValue: '',
|
|
21
|
-
},
|
|
22
|
-
needsPKCE: {
|
|
23
|
-
description: 'boolean to indicate if the endpoint needs a PKCE code',
|
|
24
|
-
type: 'boolean',
|
|
25
|
-
defaultValue: false,
|
|
26
|
-
},
|
|
27
|
-
clientId: {
|
|
28
|
-
description: 'id for the OAuth application',
|
|
29
|
-
type: 'string',
|
|
30
|
-
defaultValue: '',
|
|
31
|
-
},
|
|
32
|
-
scopes: {
|
|
33
|
-
description: 'optional scopes for the authorization call',
|
|
34
|
-
type: 'string',
|
|
35
|
-
defaultValue: '',
|
|
36
|
-
},
|
|
37
|
-
state: {
|
|
38
|
-
description: 'optional state for the authorization call',
|
|
39
|
-
type: 'string',
|
|
40
|
-
defaultValue: '',
|
|
41
|
-
},
|
|
42
|
-
responseType: {
|
|
43
|
-
description: "the type of response from the authorization endpoint. can be 'token' or 'code'",
|
|
44
|
-
type: 'string',
|
|
45
|
-
defaultValue: 'code',
|
|
46
|
-
},
|
|
47
|
-
}, {
|
|
48
|
-
baseConfiguration: models_1.BaseInternetAccountConfig,
|
|
49
|
-
explicitlyTyped: true,
|
|
50
|
-
});
|
|
51
|
-
exports.default = OAuthConfigSchema;
|
package/dist/OAuthModel/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.modelFactory = exports.configSchema = void 0;
|
|
7
|
-
var configSchema_1 = require("./configSchema");
|
|
8
|
-
Object.defineProperty(exports, "configSchema", { enumerable: true, get: function () { return __importDefault(configSchema_1).default; } });
|
|
9
|
-
var model_1 = require("./model");
|
|
10
|
-
Object.defineProperty(exports, "modelFactory", { enumerable: true, get: function () { return __importDefault(model_1).default; } });
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import type { OAuthInternetAccountConfigModel } from './configSchema';
|
|
2
|
-
import type { UriLocation } from '@jbrowse/core/util';
|
|
3
|
-
import type { Instance } from 'mobx-state-tree';
|
|
4
|
-
declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel) => import("mobx-state-tree").IModelType<{
|
|
5
|
-
id: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<string>, [undefined]>;
|
|
6
|
-
type: import("mobx-state-tree").ISimpleType<string>;
|
|
7
|
-
configuration: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
|
|
8
|
-
name: {
|
|
9
|
-
description: string;
|
|
10
|
-
type: string;
|
|
11
|
-
defaultValue: string;
|
|
12
|
-
};
|
|
13
|
-
description: {
|
|
14
|
-
description: string;
|
|
15
|
-
type: string;
|
|
16
|
-
defaultValue: string;
|
|
17
|
-
};
|
|
18
|
-
authHeader: {
|
|
19
|
-
description: string;
|
|
20
|
-
type: string;
|
|
21
|
-
defaultValue: string;
|
|
22
|
-
};
|
|
23
|
-
tokenType: {
|
|
24
|
-
description: string;
|
|
25
|
-
type: string;
|
|
26
|
-
defaultValue: string;
|
|
27
|
-
};
|
|
28
|
-
domains: {
|
|
29
|
-
description: string;
|
|
30
|
-
type: string;
|
|
31
|
-
defaultValue: never[];
|
|
32
|
-
};
|
|
33
|
-
}, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>;
|
|
34
|
-
} & {
|
|
35
|
-
type: import("mobx-state-tree").ISimpleType<"OAuthInternetAccount">;
|
|
36
|
-
configuration: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
|
|
37
|
-
tokenType: {
|
|
38
|
-
description: string;
|
|
39
|
-
type: string;
|
|
40
|
-
defaultValue: string;
|
|
41
|
-
};
|
|
42
|
-
authEndpoint: {
|
|
43
|
-
description: string;
|
|
44
|
-
type: string;
|
|
45
|
-
defaultValue: string;
|
|
46
|
-
};
|
|
47
|
-
tokenEndpoint: {
|
|
48
|
-
description: string;
|
|
49
|
-
type: string;
|
|
50
|
-
defaultValue: string;
|
|
51
|
-
};
|
|
52
|
-
needsPKCE: {
|
|
53
|
-
description: string;
|
|
54
|
-
type: string;
|
|
55
|
-
defaultValue: boolean;
|
|
56
|
-
};
|
|
57
|
-
clientId: {
|
|
58
|
-
description: string;
|
|
59
|
-
type: string;
|
|
60
|
-
defaultValue: string;
|
|
61
|
-
};
|
|
62
|
-
scopes: {
|
|
63
|
-
description: string;
|
|
64
|
-
type: string;
|
|
65
|
-
defaultValue: string;
|
|
66
|
-
};
|
|
67
|
-
state: {
|
|
68
|
-
description: string;
|
|
69
|
-
type: string;
|
|
70
|
-
defaultValue: string;
|
|
71
|
-
};
|
|
72
|
-
responseType: {
|
|
73
|
-
description: string;
|
|
74
|
-
type: string;
|
|
75
|
-
defaultValue: string;
|
|
76
|
-
};
|
|
77
|
-
}, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
|
|
78
|
-
name: {
|
|
79
|
-
description: string;
|
|
80
|
-
type: string;
|
|
81
|
-
defaultValue: string;
|
|
82
|
-
};
|
|
83
|
-
description: {
|
|
84
|
-
description: string;
|
|
85
|
-
type: string;
|
|
86
|
-
defaultValue: string;
|
|
87
|
-
};
|
|
88
|
-
authHeader: {
|
|
89
|
-
description: string;
|
|
90
|
-
type: string;
|
|
91
|
-
defaultValue: string;
|
|
92
|
-
};
|
|
93
|
-
tokenType: {
|
|
94
|
-
description: string;
|
|
95
|
-
type: string;
|
|
96
|
-
defaultValue: string;
|
|
97
|
-
};
|
|
98
|
-
domains: {
|
|
99
|
-
description: string;
|
|
100
|
-
type: string;
|
|
101
|
-
defaultValue: never[];
|
|
102
|
-
};
|
|
103
|
-
}, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>, undefined>>;
|
|
104
|
-
}, {
|
|
105
|
-
readonly name: string;
|
|
106
|
-
readonly description: string;
|
|
107
|
-
readonly internetAccountId: string;
|
|
108
|
-
readonly authHeader: string;
|
|
109
|
-
readonly tokenType: string;
|
|
110
|
-
readonly domains: string[];
|
|
111
|
-
readonly toggleContents: React.ReactNode;
|
|
112
|
-
readonly SelectorComponent: import("@jbrowse/core/util").AnyReactComponentType | undefined;
|
|
113
|
-
readonly selectorLabel: string | undefined;
|
|
114
|
-
} & {
|
|
115
|
-
handlesLocation(location: UriLocation): boolean;
|
|
116
|
-
readonly tokenKey: string;
|
|
117
|
-
} & {
|
|
118
|
-
getTokenFromUser(_resolve: (token: string) => void, _reject: (error: Error) => void): void;
|
|
119
|
-
storeToken(token: string): void;
|
|
120
|
-
removeToken(): void;
|
|
121
|
-
retrieveToken(): string | null;
|
|
122
|
-
validateToken(token: string, _loc: UriLocation): Promise<string>;
|
|
123
|
-
} & {
|
|
124
|
-
getToken(location?: UriLocation): Promise<string>;
|
|
125
|
-
} & {
|
|
126
|
-
addAuthHeaderToInit(init?: RequestInit, token?: string): {
|
|
127
|
-
headers: Headers;
|
|
128
|
-
body?: BodyInit | null;
|
|
129
|
-
cache?: RequestCache;
|
|
130
|
-
credentials?: RequestCredentials;
|
|
131
|
-
integrity?: string;
|
|
132
|
-
keepalive?: boolean;
|
|
133
|
-
method?: string;
|
|
134
|
-
mode?: RequestMode;
|
|
135
|
-
priority?: RequestPriority;
|
|
136
|
-
redirect?: RequestRedirect;
|
|
137
|
-
referrer?: string;
|
|
138
|
-
referrerPolicy?: ReferrerPolicy;
|
|
139
|
-
signal?: AbortSignal | null;
|
|
140
|
-
window?: null;
|
|
141
|
-
};
|
|
142
|
-
getPreAuthorizationInformation(location: UriLocation): Promise<{
|
|
143
|
-
internetAccountType: string;
|
|
144
|
-
authInfo: {
|
|
145
|
-
token: string;
|
|
146
|
-
configuration: any;
|
|
147
|
-
};
|
|
148
|
-
}>;
|
|
149
|
-
} & {
|
|
150
|
-
getFetcher(loc?: UriLocation): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
151
|
-
} & {
|
|
152
|
-
openLocation(location: UriLocation): import("@jbrowse/core/util/io").RemoteFileWithRangeCache;
|
|
153
|
-
} & {
|
|
154
|
-
readonly codeVerifierPKCE: string;
|
|
155
|
-
} & {
|
|
156
|
-
readonly authEndpoint: string;
|
|
157
|
-
readonly tokenEndpoint: string;
|
|
158
|
-
readonly needsPKCE: boolean;
|
|
159
|
-
readonly clientId: string;
|
|
160
|
-
readonly scopes: string;
|
|
161
|
-
state(): string | undefined;
|
|
162
|
-
readonly responseType: "token" | "code";
|
|
163
|
-
readonly refreshTokenKey: string;
|
|
164
|
-
} & {
|
|
165
|
-
storeRefreshToken(refreshToken: string): void;
|
|
166
|
-
removeRefreshToken(): void;
|
|
167
|
-
retrieveRefreshToken(): string | null;
|
|
168
|
-
exchangeAuthorizationForAccessToken(token: string, redirectUri: string): Promise<string>;
|
|
169
|
-
exchangeRefreshForAccessToken(refreshToken: string): Promise<string>;
|
|
170
|
-
} & {
|
|
171
|
-
addMessageChannel(resolve: (token: string) => void, reject: (error: Error) => void): void;
|
|
172
|
-
deleteMessageChannel(): void;
|
|
173
|
-
finishOAuthWindow(event: MessageEvent, resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
|
|
174
|
-
useEndpointForAuthorization(resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
|
|
175
|
-
getTokenFromUser(resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
|
|
176
|
-
validateToken(token: string, location: UriLocation): Promise<string>;
|
|
177
|
-
} & {
|
|
178
|
-
getFetcher(loc?: UriLocation): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
179
|
-
}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
|
|
180
|
-
export default stateModelFactory;
|
|
181
|
-
export type OAuthStateModel = ReturnType<typeof stateModelFactory>;
|
|
182
|
-
export type OAuthModel = Instance<OAuthStateModel>;
|
package/dist/OAuthModel/model.js
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const configuration_1 = require("@jbrowse/core/configuration");
|
|
4
|
-
const models_1 = require("@jbrowse/core/pluggableElementTypes/models");
|
|
5
|
-
const util_1 = require("@jbrowse/core/util");
|
|
6
|
-
const mobx_state_tree_1 = require("mobx-state-tree");
|
|
7
|
-
const util_2 = require("./util");
|
|
8
|
-
const util_3 = require("../util");
|
|
9
|
-
function encode(uint8array) {
|
|
10
|
-
const output = [];
|
|
11
|
-
for (let i = 0, length = uint8array.length; i < length; i++) {
|
|
12
|
-
output.push(String.fromCharCode(uint8array[i]));
|
|
13
|
-
}
|
|
14
|
-
return btoa(output.join(''));
|
|
15
|
-
}
|
|
16
|
-
const stateModelFactory = (configSchema) => {
|
|
17
|
-
return models_1.InternetAccount.named('OAuthInternetAccount')
|
|
18
|
-
.props({
|
|
19
|
-
type: mobx_state_tree_1.types.literal('OAuthInternetAccount'),
|
|
20
|
-
configuration: (0, configuration_1.ConfigurationReference)(configSchema),
|
|
21
|
-
})
|
|
22
|
-
.views(() => {
|
|
23
|
-
let codeVerifier = undefined;
|
|
24
|
-
return {
|
|
25
|
-
get codeVerifierPKCE() {
|
|
26
|
-
if (!codeVerifier) {
|
|
27
|
-
const array = new Uint8Array(32);
|
|
28
|
-
globalThis.crypto.getRandomValues(array);
|
|
29
|
-
codeVerifier = (0, util_2.fixup)(encode(array));
|
|
30
|
-
}
|
|
31
|
-
return codeVerifier;
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
})
|
|
35
|
-
.views(self => ({
|
|
36
|
-
get authEndpoint() {
|
|
37
|
-
return (0, configuration_1.getConf)(self, 'authEndpoint');
|
|
38
|
-
},
|
|
39
|
-
get tokenEndpoint() {
|
|
40
|
-
return (0, configuration_1.getConf)(self, 'tokenEndpoint');
|
|
41
|
-
},
|
|
42
|
-
get needsPKCE() {
|
|
43
|
-
return (0, configuration_1.getConf)(self, 'needsPKCE');
|
|
44
|
-
},
|
|
45
|
-
get clientId() {
|
|
46
|
-
return (0, configuration_1.getConf)(self, 'clientId');
|
|
47
|
-
},
|
|
48
|
-
get scopes() {
|
|
49
|
-
return (0, configuration_1.getConf)(self, 'scopes');
|
|
50
|
-
},
|
|
51
|
-
state() {
|
|
52
|
-
return (0, configuration_1.getConf)(self, 'state');
|
|
53
|
-
},
|
|
54
|
-
get responseType() {
|
|
55
|
-
return (0, configuration_1.getConf)(self, 'responseType');
|
|
56
|
-
},
|
|
57
|
-
get refreshTokenKey() {
|
|
58
|
-
return `${self.internetAccountId}-refreshToken`;
|
|
59
|
-
},
|
|
60
|
-
}))
|
|
61
|
-
.actions(self => ({
|
|
62
|
-
storeRefreshToken(refreshToken) {
|
|
63
|
-
localStorage.setItem(self.refreshTokenKey, refreshToken);
|
|
64
|
-
},
|
|
65
|
-
removeRefreshToken() {
|
|
66
|
-
localStorage.removeItem(self.refreshTokenKey);
|
|
67
|
-
},
|
|
68
|
-
retrieveRefreshToken() {
|
|
69
|
-
return localStorage.getItem(self.refreshTokenKey);
|
|
70
|
-
},
|
|
71
|
-
async exchangeAuthorizationForAccessToken(token, redirectUri) {
|
|
72
|
-
const params = new URLSearchParams(Object.entries({
|
|
73
|
-
code: token,
|
|
74
|
-
grant_type: 'authorization_code',
|
|
75
|
-
client_id: self.clientId,
|
|
76
|
-
redirect_uri: redirectUri,
|
|
77
|
-
...(self.needsPKCE ? { code_verifier: self.codeVerifierPKCE } : {}),
|
|
78
|
-
}));
|
|
79
|
-
const response = await fetch(self.tokenEndpoint, {
|
|
80
|
-
method: 'POST',
|
|
81
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
82
|
-
body: params.toString(),
|
|
83
|
-
});
|
|
84
|
-
if (!response.ok) {
|
|
85
|
-
throw new Error(await (0, util_3.getResponseError)({
|
|
86
|
-
response,
|
|
87
|
-
reason: 'Failed to obtain token',
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
const data = await response.json();
|
|
91
|
-
return (0, util_2.processTokenResponse)(data, token => {
|
|
92
|
-
this.storeRefreshToken(token);
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
async exchangeRefreshForAccessToken(refreshToken) {
|
|
96
|
-
const response = await fetch(self.tokenEndpoint, {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
99
|
-
body: new URLSearchParams(Object.entries({
|
|
100
|
-
grant_type: 'refresh_token',
|
|
101
|
-
refresh_token: refreshToken,
|
|
102
|
-
client_id: self.clientId,
|
|
103
|
-
})).toString(),
|
|
104
|
-
});
|
|
105
|
-
if (!response.ok) {
|
|
106
|
-
self.removeToken();
|
|
107
|
-
const text = await response.text();
|
|
108
|
-
throw new Error(await (0, util_3.getResponseError)({
|
|
109
|
-
response,
|
|
110
|
-
statusText: (0, util_2.processError)(text, () => {
|
|
111
|
-
this.removeRefreshToken();
|
|
112
|
-
}),
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
const data = await response.json();
|
|
116
|
-
return (0, util_2.processTokenResponse)(data, token => {
|
|
117
|
-
this.storeRefreshToken(token);
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
}))
|
|
121
|
-
.actions(self => {
|
|
122
|
-
let listener;
|
|
123
|
-
let exchangedTokenPromise = undefined;
|
|
124
|
-
return {
|
|
125
|
-
addMessageChannel(resolve, reject) {
|
|
126
|
-
listener = event => {
|
|
127
|
-
this.finishOAuthWindow(event, resolve, reject);
|
|
128
|
-
};
|
|
129
|
-
window.addEventListener('message', listener);
|
|
130
|
-
},
|
|
131
|
-
deleteMessageChannel() {
|
|
132
|
-
window.removeEventListener('message', listener);
|
|
133
|
-
},
|
|
134
|
-
async finishOAuthWindow(event, resolve, reject) {
|
|
135
|
-
if (event.data.name !== `JBrowseAuthWindow-${self.internetAccountId}`) {
|
|
136
|
-
this.deleteMessageChannel();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const redirectUriWithInfo = event.data.redirectUri;
|
|
140
|
-
const fixedQueryString = redirectUriWithInfo.replace('#', '?');
|
|
141
|
-
const redirectUrl = new URL(fixedQueryString);
|
|
142
|
-
const queryStringSearch = redirectUrl.search;
|
|
143
|
-
const urlParams = new URLSearchParams(queryStringSearch);
|
|
144
|
-
if (urlParams.has('access_token')) {
|
|
145
|
-
const token = urlParams.get('access_token');
|
|
146
|
-
if (!token) {
|
|
147
|
-
reject(new Error('Error with token endpoint'));
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
self.storeToken(token);
|
|
151
|
-
resolve(token);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (urlParams.has('code')) {
|
|
155
|
-
const code = urlParams.get('code');
|
|
156
|
-
if (!code) {
|
|
157
|
-
reject(new Error('Error with authorization endpoint'));
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const token = await self.exchangeAuthorizationForAccessToken(code, redirectUrl.origin + redirectUrl.pathname);
|
|
162
|
-
self.storeToken(token);
|
|
163
|
-
resolve(token);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
catch (e) {
|
|
167
|
-
if (e instanceof Error) {
|
|
168
|
-
reject(e);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
reject(new Error(String(e)));
|
|
172
|
-
}
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (redirectUriWithInfo.includes('access_denied')) {
|
|
177
|
-
reject(new Error('OAuth flow was cancelled'));
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if (redirectUriWithInfo.includes('error')) {
|
|
181
|
-
reject(new Error(`OAuth flow error: ${queryStringSearch}`));
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
this.deleteMessageChannel();
|
|
185
|
-
},
|
|
186
|
-
async useEndpointForAuthorization(resolve, reject) {
|
|
187
|
-
const redirectUri = util_1.isElectron
|
|
188
|
-
? 'http://localhost/auth'
|
|
189
|
-
: window.location.origin + window.location.pathname;
|
|
190
|
-
const data = {
|
|
191
|
-
client_id: self.clientId,
|
|
192
|
-
redirect_uri: redirectUri,
|
|
193
|
-
response_type: self.responseType,
|
|
194
|
-
token_access_type: 'offline',
|
|
195
|
-
};
|
|
196
|
-
if (self.state()) {
|
|
197
|
-
data.state = self.state();
|
|
198
|
-
}
|
|
199
|
-
if (self.scopes) {
|
|
200
|
-
data.scope = self.scopes;
|
|
201
|
-
}
|
|
202
|
-
if (self.needsPKCE) {
|
|
203
|
-
data.code_challenge = await (0, util_2.generateChallenge)(self.codeVerifierPKCE);
|
|
204
|
-
data.code_challenge_method = 'S256';
|
|
205
|
-
}
|
|
206
|
-
const params = new URLSearchParams(Object.entries(data));
|
|
207
|
-
const url = new URL(self.authEndpoint);
|
|
208
|
-
url.search = params.toString();
|
|
209
|
-
const eventName = `JBrowseAuthWindow-${self.internetAccountId}`;
|
|
210
|
-
if (util_1.isElectron) {
|
|
211
|
-
const { ipcRenderer } = window.require('electron');
|
|
212
|
-
const redirectUri = await ipcRenderer.invoke('openAuthWindow', {
|
|
213
|
-
internetAccountId: self.internetAccountId,
|
|
214
|
-
data,
|
|
215
|
-
url: url.toString(),
|
|
216
|
-
});
|
|
217
|
-
const eventFromDesktop = new MessageEvent('message', {
|
|
218
|
-
data: { name: eventName, redirectUri: redirectUri },
|
|
219
|
-
});
|
|
220
|
-
this.finishOAuthWindow(eventFromDesktop, resolve, reject);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
window.open(url, eventName, 'width=500,height=600,left=0,top=0');
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
async getTokenFromUser(resolve, reject) {
|
|
227
|
-
const refreshToken = self.retrieveRefreshToken();
|
|
228
|
-
let doUserFlow = true;
|
|
229
|
-
if (refreshToken) {
|
|
230
|
-
try {
|
|
231
|
-
const token = await self.exchangeRefreshForAccessToken(refreshToken);
|
|
232
|
-
resolve(token);
|
|
233
|
-
doUserFlow = false;
|
|
234
|
-
}
|
|
235
|
-
catch (e) {
|
|
236
|
-
console.error(e);
|
|
237
|
-
self.removeRefreshToken();
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (doUserFlow) {
|
|
241
|
-
this.addMessageChannel(resolve, reject);
|
|
242
|
-
this.useEndpointForAuthorization(resolve, reject);
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
async validateToken(token, location) {
|
|
246
|
-
const newInit = self.addAuthHeaderToInit({ method: 'HEAD' }, token);
|
|
247
|
-
const response = await fetch(location.uri, newInit);
|
|
248
|
-
if (!response.ok) {
|
|
249
|
-
self.removeToken();
|
|
250
|
-
const refreshToken = self.retrieveRefreshToken();
|
|
251
|
-
if (refreshToken) {
|
|
252
|
-
try {
|
|
253
|
-
if (!exchangedTokenPromise) {
|
|
254
|
-
exchangedTokenPromise =
|
|
255
|
-
self.exchangeRefreshForAccessToken(refreshToken);
|
|
256
|
-
}
|
|
257
|
-
const newToken = await exchangedTokenPromise;
|
|
258
|
-
exchangedTokenPromise = undefined;
|
|
259
|
-
return newToken;
|
|
260
|
-
}
|
|
261
|
-
catch (err) {
|
|
262
|
-
console.error('Token could not be refreshed', err);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
throw new Error(await (0, util_3.getResponseError)({
|
|
266
|
-
response,
|
|
267
|
-
reason: 'Error validating token',
|
|
268
|
-
}));
|
|
269
|
-
}
|
|
270
|
-
return token;
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
})
|
|
274
|
-
.actions(self => {
|
|
275
|
-
const superGetFetcher = self.getFetcher;
|
|
276
|
-
return {
|
|
277
|
-
getFetcher(loc) {
|
|
278
|
-
const fetcher = superGetFetcher(loc);
|
|
279
|
-
return async (input, init) => {
|
|
280
|
-
if (loc) {
|
|
281
|
-
await self.validateToken(await self.getToken(loc), loc);
|
|
282
|
-
}
|
|
283
|
-
return fetcher(input, init);
|
|
284
|
-
};
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
});
|
|
288
|
-
};
|
|
289
|
-
exports.default = stateModelFactory;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare function fixup(buf: string): string;
|
|
2
|
-
export declare function generateChallenge(val: string): Promise<string>;
|
|
3
|
-
export declare function processError(text: string, invalidErrorCb: () => void): any;
|
|
4
|
-
export declare function processTokenResponse(data: {
|
|
5
|
-
refresh_token?: string;
|
|
6
|
-
access_token: string;
|
|
7
|
-
}, storeRefreshTokenCb: (str: string) => void): string;
|
package/dist/OAuthModel/util.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.fixup = fixup;
|
|
37
|
-
exports.generateChallenge = generateChallenge;
|
|
38
|
-
exports.processError = processError;
|
|
39
|
-
exports.processTokenResponse = processTokenResponse;
|
|
40
|
-
function fixup(buf) {
|
|
41
|
-
return buf.replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '');
|
|
42
|
-
}
|
|
43
|
-
async function generateChallenge(val) {
|
|
44
|
-
const sha256 = await Promise.resolve().then(() => __importStar(require('crypto-js/sha256'))).then(f => f.default);
|
|
45
|
-
const Base64 = await Promise.resolve().then(() => __importStar(require('crypto-js/enc-base64')));
|
|
46
|
-
return fixup(Base64.stringify(sha256(val)));
|
|
47
|
-
}
|
|
48
|
-
function processError(text, invalidErrorCb) {
|
|
49
|
-
var _a;
|
|
50
|
-
try {
|
|
51
|
-
const obj = JSON.parse(text);
|
|
52
|
-
if (obj.error === 'invalid_grant') {
|
|
53
|
-
invalidErrorCb();
|
|
54
|
-
}
|
|
55
|
-
return (_a = obj === null || obj === void 0 ? void 0 : obj.error_description) !== null && _a !== void 0 ? _a : text;
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
}
|
|
59
|
-
return text;
|
|
60
|
-
}
|
|
61
|
-
function processTokenResponse(data, storeRefreshTokenCb) {
|
|
62
|
-
if (data.refresh_token) {
|
|
63
|
-
storeRefreshTokenCb(data.refresh_token);
|
|
64
|
-
}
|
|
65
|
-
return data.access_token;
|
|
66
|
-
}
|