@jbrowse/plugin-authentication 2.16.1 → 2.18.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/dist/DropboxOAuthModel/DropboxIcon.d.ts +1 -1
- package/dist/DropboxOAuthModel/configSchema.d.ts +1 -13
- package/dist/DropboxOAuthModel/configSchema.js +1 -19
- package/dist/DropboxOAuthModel/model.d.ts +3 -25
- package/dist/DropboxOAuthModel/model.js +2 -24
- package/dist/DropboxOAuthModel/util.js +0 -5
- package/dist/ExternalTokenModel/ExternalTokenEntryForm.js +8 -4
- package/dist/ExternalTokenModel/configSchema.d.ts +1 -4
- package/dist/ExternalTokenModel/configSchema.js +1 -10
- package/dist/ExternalTokenModel/model.d.ts +3 -3
- package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +1 -1
- package/dist/GoogleDriveOAuthModel/GoogleDriveIcon.d.ts +1 -1
- package/dist/GoogleDriveOAuthModel/configSchema.d.ts +1 -13
- package/dist/GoogleDriveOAuthModel/configSchema.js +1 -19
- package/dist/GoogleDriveOAuthModel/model.d.ts +3 -28
- package/dist/GoogleDriveOAuthModel/model.js +2 -27
- package/dist/GoogleDriveOAuthModel/util.js +0 -1
- package/dist/HTTPBasicModel/HTTPBasicLoginForm.js +12 -6
- package/dist/HTTPBasicModel/configSchema.d.ts +1 -7
- package/dist/HTTPBasicModel/configSchema.js +1 -13
- package/dist/HTTPBasicModel/model.d.ts +3 -21
- package/dist/HTTPBasicModel/model.js +0 -18
- package/dist/OAuthModel/configSchema.d.ts +1 -25
- package/dist/OAuthModel/configSchema.js +1 -31
- package/dist/OAuthModel/model.d.ts +3 -89
- package/dist/OAuthModel/model.js +1 -96
- package/dist/OAuthModel/util.js +0 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/esm/DropboxOAuthModel/DropboxIcon.d.ts +1 -1
- package/esm/DropboxOAuthModel/configSchema.d.ts +1 -13
- package/esm/DropboxOAuthModel/configSchema.js +1 -19
- package/esm/DropboxOAuthModel/model.d.ts +3 -25
- package/esm/DropboxOAuthModel/model.js +2 -24
- package/esm/DropboxOAuthModel/util.js +0 -5
- package/esm/ExternalTokenModel/ExternalTokenEntryForm.js +8 -4
- package/esm/ExternalTokenModel/configSchema.d.ts +1 -4
- package/esm/ExternalTokenModel/configSchema.js +1 -10
- package/esm/ExternalTokenModel/model.d.ts +3 -3
- package/esm/ExternalTokenModel/model.js +1 -1
- package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +1 -1
- package/esm/GoogleDriveOAuthModel/GoogleDriveIcon.d.ts +1 -1
- package/esm/GoogleDriveOAuthModel/configSchema.d.ts +1 -13
- package/esm/GoogleDriveOAuthModel/configSchema.js +1 -19
- package/esm/GoogleDriveOAuthModel/model.d.ts +3 -28
- package/esm/GoogleDriveOAuthModel/model.js +2 -27
- package/esm/GoogleDriveOAuthModel/util.js +0 -1
- package/esm/HTTPBasicModel/HTTPBasicLoginForm.js +12 -6
- package/esm/HTTPBasicModel/configSchema.d.ts +1 -7
- package/esm/HTTPBasicModel/configSchema.js +1 -13
- package/esm/HTTPBasicModel/model.d.ts +3 -21
- package/esm/HTTPBasicModel/model.js +1 -19
- package/esm/OAuthModel/configSchema.d.ts +1 -25
- package/esm/OAuthModel/configSchema.js +1 -31
- package/esm/OAuthModel/model.d.ts +3 -89
- package/esm/OAuthModel/model.js +1 -96
- package/esm/OAuthModel/util.js +0 -2
- package/esm/index.d.ts +1 -1
- package/esm/index.js +3 -3
- package/package.json +2 -2
|
@@ -1,35 +1,20 @@
|
|
|
1
1
|
import { ConfigurationReference, getConf } from '@jbrowse/core/configuration';
|
|
2
2
|
import { InternetAccount } from '@jbrowse/core/pluggableElementTypes/models';
|
|
3
|
-
import {
|
|
3
|
+
import { getRoot, types } from 'mobx-state-tree';
|
|
4
4
|
import { HTTPBasicLoginForm } from './HTTPBasicLoginForm';
|
|
5
5
|
import { getResponseError } from '../util';
|
|
6
|
-
/**
|
|
7
|
-
* #stateModel HTTPBasicInternetAccount
|
|
8
|
-
*/
|
|
9
6
|
const stateModelFactory = (configSchema) => {
|
|
10
7
|
return InternetAccount.named('HTTPBasicInternetAccount')
|
|
11
8
|
.props({
|
|
12
|
-
/**
|
|
13
|
-
* #property
|
|
14
|
-
*/
|
|
15
9
|
type: types.literal('HTTPBasicInternetAccount'),
|
|
16
|
-
/**
|
|
17
|
-
* #property
|
|
18
|
-
*/
|
|
19
10
|
configuration: ConfigurationReference(configSchema),
|
|
20
11
|
})
|
|
21
12
|
.views(self => ({
|
|
22
|
-
/**
|
|
23
|
-
* #getter
|
|
24
|
-
*/
|
|
25
13
|
get validateWithHEAD() {
|
|
26
14
|
return getConf(self, 'validateWithHEAD');
|
|
27
15
|
},
|
|
28
16
|
}))
|
|
29
17
|
.actions(self => ({
|
|
30
|
-
/**
|
|
31
|
-
* #action
|
|
32
|
-
*/
|
|
33
18
|
getTokenFromUser(resolve, reject) {
|
|
34
19
|
const { session } = getRoot(self);
|
|
35
20
|
session.queueDialog((doneCallback) => [
|
|
@@ -48,9 +33,6 @@ const stateModelFactory = (configSchema) => {
|
|
|
48
33
|
},
|
|
49
34
|
]);
|
|
50
35
|
},
|
|
51
|
-
/**
|
|
52
|
-
* #action
|
|
53
|
-
*/
|
|
54
36
|
async validateToken(token, location) {
|
|
55
37
|
if (!self.validateWithHEAD) {
|
|
56
38
|
return token;
|
|
@@ -1,64 +1,40 @@
|
|
|
1
|
-
import { Instance } from 'mobx-state-tree';
|
|
1
|
+
import type { Instance } from 'mobx-state-tree';
|
|
2
2
|
declare const OAuthConfigSchema: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
|
|
3
|
-
/**
|
|
4
|
-
* #slot
|
|
5
|
-
*/
|
|
6
3
|
tokenType: {
|
|
7
4
|
description: string;
|
|
8
5
|
type: string;
|
|
9
6
|
defaultValue: string;
|
|
10
7
|
};
|
|
11
|
-
/**
|
|
12
|
-
* #slot
|
|
13
|
-
*/
|
|
14
8
|
authEndpoint: {
|
|
15
9
|
description: string;
|
|
16
10
|
type: string;
|
|
17
11
|
defaultValue: string;
|
|
18
12
|
};
|
|
19
|
-
/**
|
|
20
|
-
* #slot
|
|
21
|
-
*/
|
|
22
13
|
tokenEndpoint: {
|
|
23
14
|
description: string;
|
|
24
15
|
type: string;
|
|
25
16
|
defaultValue: string;
|
|
26
17
|
};
|
|
27
|
-
/**
|
|
28
|
-
* #slot
|
|
29
|
-
*/
|
|
30
18
|
needsPKCE: {
|
|
31
19
|
description: string;
|
|
32
20
|
type: string;
|
|
33
21
|
defaultValue: boolean;
|
|
34
22
|
};
|
|
35
|
-
/**
|
|
36
|
-
* #slot
|
|
37
|
-
*/
|
|
38
23
|
clientId: {
|
|
39
24
|
description: string;
|
|
40
25
|
type: string;
|
|
41
26
|
defaultValue: string;
|
|
42
27
|
};
|
|
43
|
-
/**
|
|
44
|
-
* #slot
|
|
45
|
-
*/
|
|
46
28
|
scopes: {
|
|
47
29
|
description: string;
|
|
48
30
|
type: string;
|
|
49
31
|
defaultValue: string;
|
|
50
32
|
};
|
|
51
|
-
/**
|
|
52
|
-
* #slot
|
|
53
|
-
*/
|
|
54
33
|
state: {
|
|
55
34
|
description: string;
|
|
56
35
|
type: string;
|
|
57
36
|
defaultValue: string;
|
|
58
37
|
};
|
|
59
|
-
/**
|
|
60
|
-
* #slot
|
|
61
|
-
*/
|
|
62
38
|
responseType: {
|
|
63
39
|
description: string;
|
|
64
40
|
type: string;
|
|
@@ -1,78 +1,48 @@
|
|
|
1
1
|
import { ConfigurationSchema } from '@jbrowse/core/configuration';
|
|
2
2
|
import { BaseInternetAccountConfig } from '@jbrowse/core/pluggableElementTypes/models';
|
|
3
|
-
|
|
4
|
-
* #config OAuthInternetAccount
|
|
5
|
-
*/
|
|
6
|
-
function x() { } // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
3
|
+
function x() { }
|
|
7
4
|
const OAuthConfigSchema = ConfigurationSchema('OAuthInternetAccount', {
|
|
8
|
-
/**
|
|
9
|
-
* #slot
|
|
10
|
-
*/
|
|
11
5
|
tokenType: {
|
|
12
6
|
description: 'a custom name for a token to include in the header',
|
|
13
7
|
type: 'string',
|
|
14
8
|
defaultValue: 'Bearer',
|
|
15
9
|
},
|
|
16
|
-
/**
|
|
17
|
-
* #slot
|
|
18
|
-
*/
|
|
19
10
|
authEndpoint: {
|
|
20
11
|
description: 'the authorization code endpoint of the internet account',
|
|
21
12
|
type: 'string',
|
|
22
13
|
defaultValue: '',
|
|
23
14
|
},
|
|
24
|
-
/**
|
|
25
|
-
* #slot
|
|
26
|
-
*/
|
|
27
15
|
tokenEndpoint: {
|
|
28
16
|
description: 'the token endpoint of the internet account',
|
|
29
17
|
type: 'string',
|
|
30
18
|
defaultValue: '',
|
|
31
19
|
},
|
|
32
|
-
/**
|
|
33
|
-
* #slot
|
|
34
|
-
*/
|
|
35
20
|
needsPKCE: {
|
|
36
21
|
description: 'boolean to indicate if the endpoint needs a PKCE code',
|
|
37
22
|
type: 'boolean',
|
|
38
23
|
defaultValue: false,
|
|
39
24
|
},
|
|
40
|
-
/**
|
|
41
|
-
* #slot
|
|
42
|
-
*/
|
|
43
25
|
clientId: {
|
|
44
26
|
description: 'id for the OAuth application',
|
|
45
27
|
type: 'string',
|
|
46
28
|
defaultValue: '',
|
|
47
29
|
},
|
|
48
|
-
/**
|
|
49
|
-
* #slot
|
|
50
|
-
*/
|
|
51
30
|
scopes: {
|
|
52
31
|
description: 'optional scopes for the authorization call',
|
|
53
32
|
type: 'string',
|
|
54
33
|
defaultValue: '',
|
|
55
34
|
},
|
|
56
|
-
/**
|
|
57
|
-
* #slot
|
|
58
|
-
*/
|
|
59
35
|
state: {
|
|
60
36
|
description: 'optional state for the authorization call',
|
|
61
37
|
type: 'string',
|
|
62
38
|
defaultValue: '',
|
|
63
39
|
},
|
|
64
|
-
/**
|
|
65
|
-
* #slot
|
|
66
|
-
*/
|
|
67
40
|
responseType: {
|
|
68
41
|
description: "the type of response from the authorization endpoint. can be 'token' or 'code'",
|
|
69
42
|
type: 'string',
|
|
70
43
|
defaultValue: 'code',
|
|
71
44
|
},
|
|
72
45
|
}, {
|
|
73
|
-
/**
|
|
74
|
-
* #baseConfiguration
|
|
75
|
-
*/
|
|
76
46
|
baseConfiguration: BaseInternetAccountConfig,
|
|
77
47
|
explicitlyTyped: true,
|
|
78
48
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
/**
|
|
5
|
-
* #stateModel OAuthInternetAccount
|
|
6
|
-
*/
|
|
1
|
+
import type { OAuthInternetAccountConfigModel } from './configSchema';
|
|
2
|
+
import type { UriLocation } from '@jbrowse/core/util';
|
|
3
|
+
import type { Instance } from 'mobx-state-tree';
|
|
7
4
|
declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel) => import("mobx-state-tree").IModelType<{
|
|
8
5
|
id: import("mobx-state-tree").IOptionalIType<import("mobx-state-tree").ISimpleType<string>, [undefined]>;
|
|
9
6
|
type: import("mobx-state-tree").ISimpleType<string>;
|
|
@@ -35,13 +32,7 @@ declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel)
|
|
|
35
32
|
};
|
|
36
33
|
}, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>;
|
|
37
34
|
} & {
|
|
38
|
-
/**
|
|
39
|
-
* #property
|
|
40
|
-
*/
|
|
41
35
|
type: import("mobx-state-tree").ISimpleType<"OAuthInternetAccount">;
|
|
42
|
-
/**
|
|
43
|
-
* #property
|
|
44
|
-
*/
|
|
45
36
|
configuration: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
|
|
46
37
|
tokenType: {
|
|
47
38
|
description: string;
|
|
@@ -160,107 +151,30 @@ declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel)
|
|
|
160
151
|
} & {
|
|
161
152
|
openLocation(location: UriLocation): import("@jbrowse/core/util/io").RemoteFileWithRangeCache;
|
|
162
153
|
} & {
|
|
163
|
-
/**
|
|
164
|
-
* #getter
|
|
165
|
-
*/
|
|
166
154
|
readonly codeVerifierPKCE: string;
|
|
167
155
|
} & {
|
|
168
|
-
/**
|
|
169
|
-
* #getter
|
|
170
|
-
*/
|
|
171
156
|
readonly authEndpoint: string;
|
|
172
|
-
/**
|
|
173
|
-
* #getter
|
|
174
|
-
*/
|
|
175
157
|
readonly tokenEndpoint: string;
|
|
176
|
-
/**
|
|
177
|
-
* #getter
|
|
178
|
-
*/
|
|
179
158
|
readonly needsPKCE: boolean;
|
|
180
|
-
/**
|
|
181
|
-
* #getter
|
|
182
|
-
*/
|
|
183
159
|
readonly clientId: string;
|
|
184
|
-
/**
|
|
185
|
-
* #getter
|
|
186
|
-
*/
|
|
187
160
|
readonly scopes: string;
|
|
188
|
-
/**
|
|
189
|
-
* #method
|
|
190
|
-
* OAuth state parameter:
|
|
191
|
-
* https://www.rfc-editor.org/rfc/rfc6749#section-4.1.1
|
|
192
|
-
*
|
|
193
|
-
* Can override or extend if dynamic state is needed.
|
|
194
|
-
*/
|
|
195
161
|
state(): string | undefined;
|
|
196
|
-
/**
|
|
197
|
-
* #getter
|
|
198
|
-
*/
|
|
199
162
|
readonly responseType: "code" | "token";
|
|
200
|
-
/**
|
|
201
|
-
* #getter
|
|
202
|
-
*/
|
|
203
163
|
readonly refreshTokenKey: string;
|
|
204
164
|
} & {
|
|
205
|
-
/**
|
|
206
|
-
* #action
|
|
207
|
-
*/
|
|
208
165
|
storeRefreshToken(refreshToken: string): void;
|
|
209
|
-
/**
|
|
210
|
-
* #action
|
|
211
|
-
*/
|
|
212
166
|
removeRefreshToken(): void;
|
|
213
|
-
/**
|
|
214
|
-
* #method
|
|
215
|
-
*/
|
|
216
167
|
retrieveRefreshToken(): string | null;
|
|
217
|
-
/**
|
|
218
|
-
* #action
|
|
219
|
-
*/
|
|
220
168
|
exchangeAuthorizationForAccessToken(token: string, redirectUri: string): Promise<string>;
|
|
221
|
-
/**
|
|
222
|
-
* #action
|
|
223
|
-
*/
|
|
224
169
|
exchangeRefreshForAccessToken(refreshToken: string): Promise<string>;
|
|
225
170
|
} & {
|
|
226
|
-
/**
|
|
227
|
-
* #action
|
|
228
|
-
* used to listen to child window for auth code/token
|
|
229
|
-
*/
|
|
230
171
|
addMessageChannel(resolve: (token: string) => void, reject: (error: Error) => void): void;
|
|
231
|
-
/**
|
|
232
|
-
* #action
|
|
233
|
-
*/
|
|
234
172
|
deleteMessageChannel(): void;
|
|
235
|
-
/**
|
|
236
|
-
* #action
|
|
237
|
-
*/
|
|
238
173
|
finishOAuthWindow(event: MessageEvent, resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
|
|
239
|
-
/**
|
|
240
|
-
* #action
|
|
241
|
-
* opens external OAuth flow, popup for web and new browser window for
|
|
242
|
-
* desktop
|
|
243
|
-
*/
|
|
244
174
|
useEndpointForAuthorization(resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
|
|
245
|
-
/**
|
|
246
|
-
* #action
|
|
247
|
-
*/
|
|
248
175
|
getTokenFromUser(resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
|
|
249
|
-
/**
|
|
250
|
-
* #action
|
|
251
|
-
*/
|
|
252
176
|
validateToken(token: string, location: UriLocation): Promise<string>;
|
|
253
177
|
} & {
|
|
254
|
-
/**
|
|
255
|
-
* #action
|
|
256
|
-
* Get a fetch method that will add any needed authentication headers
|
|
257
|
-
* to the request before sending it. If location is provided, it will
|
|
258
|
-
* be checked to see if it includes a token in it's pre-auth
|
|
259
|
-
* information.
|
|
260
|
-
*
|
|
261
|
-
* @param loc - UriLocation of the resource
|
|
262
|
-
* @returns A function that can be used to fetch
|
|
263
|
-
*/
|
|
264
178
|
getFetcher(loc?: UriLocation): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
265
179
|
}, import("mobx-state-tree")._NotCustomized, import("mobx-state-tree")._NotCustomized>;
|
|
266
180
|
export default stateModelFactory;
|
package/esm/OAuthModel/model.js
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
1
2
|
import { ConfigurationReference, getConf } from '@jbrowse/core/configuration';
|
|
2
3
|
import { InternetAccount } from '@jbrowse/core/pluggableElementTypes/models';
|
|
3
4
|
import { isElectron } from '@jbrowse/core/util';
|
|
4
5
|
import { types } from 'mobx-state-tree';
|
|
5
|
-
import { Buffer } from 'buffer';
|
|
6
6
|
import { fixup, generateChallenge, processError, processTokenResponse, } from './util';
|
|
7
7
|
import { getResponseError } from '../util';
|
|
8
|
-
/**
|
|
9
|
-
* #stateModel OAuthInternetAccount
|
|
10
|
-
*/
|
|
11
8
|
const stateModelFactory = (configSchema) => {
|
|
12
9
|
return InternetAccount.named('OAuthInternetAccount')
|
|
13
10
|
.props({
|
|
14
|
-
/**
|
|
15
|
-
* #property
|
|
16
|
-
*/
|
|
17
11
|
type: types.literal('OAuthInternetAccount'),
|
|
18
|
-
/**
|
|
19
|
-
* #property
|
|
20
|
-
*/
|
|
21
12
|
configuration: ConfigurationReference(configSchema),
|
|
22
13
|
})
|
|
23
14
|
.views(() => {
|
|
24
15
|
let codeVerifier = undefined;
|
|
25
16
|
return {
|
|
26
|
-
/**
|
|
27
|
-
* #getter
|
|
28
|
-
*/
|
|
29
17
|
get codeVerifierPKCE() {
|
|
30
18
|
if (codeVerifier) {
|
|
31
19
|
return codeVerifier;
|
|
@@ -38,81 +26,41 @@ const stateModelFactory = (configSchema) => {
|
|
|
38
26
|
};
|
|
39
27
|
})
|
|
40
28
|
.views(self => ({
|
|
41
|
-
/**
|
|
42
|
-
* #getter
|
|
43
|
-
*/
|
|
44
29
|
get authEndpoint() {
|
|
45
30
|
return getConf(self, 'authEndpoint');
|
|
46
31
|
},
|
|
47
|
-
/**
|
|
48
|
-
* #getter
|
|
49
|
-
*/
|
|
50
32
|
get tokenEndpoint() {
|
|
51
33
|
return getConf(self, 'tokenEndpoint');
|
|
52
34
|
},
|
|
53
|
-
/**
|
|
54
|
-
* #getter
|
|
55
|
-
*/
|
|
56
35
|
get needsPKCE() {
|
|
57
36
|
return getConf(self, 'needsPKCE');
|
|
58
37
|
},
|
|
59
|
-
/**
|
|
60
|
-
* #getter
|
|
61
|
-
*/
|
|
62
38
|
get clientId() {
|
|
63
39
|
return getConf(self, 'clientId');
|
|
64
40
|
},
|
|
65
|
-
/**
|
|
66
|
-
* #getter
|
|
67
|
-
*/
|
|
68
41
|
get scopes() {
|
|
69
42
|
return getConf(self, 'scopes');
|
|
70
43
|
},
|
|
71
|
-
/**
|
|
72
|
-
* #method
|
|
73
|
-
* OAuth state parameter:
|
|
74
|
-
* https://www.rfc-editor.org/rfc/rfc6749#section-4.1.1
|
|
75
|
-
*
|
|
76
|
-
* Can override or extend if dynamic state is needed.
|
|
77
|
-
*/
|
|
78
44
|
state() {
|
|
79
45
|
return getConf(self, 'state');
|
|
80
46
|
},
|
|
81
|
-
/**
|
|
82
|
-
* #getter
|
|
83
|
-
*/
|
|
84
47
|
get responseType() {
|
|
85
48
|
return getConf(self, 'responseType');
|
|
86
49
|
},
|
|
87
|
-
/**
|
|
88
|
-
* #getter
|
|
89
|
-
*/
|
|
90
50
|
get refreshTokenKey() {
|
|
91
51
|
return `${self.internetAccountId}-refreshToken`;
|
|
92
52
|
},
|
|
93
53
|
}))
|
|
94
54
|
.actions(self => ({
|
|
95
|
-
/**
|
|
96
|
-
* #action
|
|
97
|
-
*/
|
|
98
55
|
storeRefreshToken(refreshToken) {
|
|
99
56
|
localStorage.setItem(self.refreshTokenKey, refreshToken);
|
|
100
57
|
},
|
|
101
|
-
/**
|
|
102
|
-
* #action
|
|
103
|
-
*/
|
|
104
58
|
removeRefreshToken() {
|
|
105
59
|
localStorage.removeItem(self.refreshTokenKey);
|
|
106
60
|
},
|
|
107
|
-
/**
|
|
108
|
-
* #method
|
|
109
|
-
*/
|
|
110
61
|
retrieveRefreshToken() {
|
|
111
62
|
return localStorage.getItem(self.refreshTokenKey);
|
|
112
63
|
},
|
|
113
|
-
/**
|
|
114
|
-
* #action
|
|
115
|
-
*/
|
|
116
64
|
async exchangeAuthorizationForAccessToken(token, redirectUri) {
|
|
117
65
|
const params = new URLSearchParams(Object.entries({
|
|
118
66
|
code: token,
|
|
@@ -137,9 +85,6 @@ const stateModelFactory = (configSchema) => {
|
|
|
137
85
|
this.storeRefreshToken(token);
|
|
138
86
|
});
|
|
139
87
|
},
|
|
140
|
-
/**
|
|
141
|
-
* #action
|
|
142
|
-
*/
|
|
143
88
|
async exchangeRefreshForAccessToken(refreshToken) {
|
|
144
89
|
const response = await fetch(self.tokenEndpoint, {
|
|
145
90
|
method: 'POST',
|
|
@@ -170,27 +115,15 @@ const stateModelFactory = (configSchema) => {
|
|
|
170
115
|
let listener;
|
|
171
116
|
let exchangedTokenPromise = undefined;
|
|
172
117
|
return {
|
|
173
|
-
/**
|
|
174
|
-
* #action
|
|
175
|
-
* used to listen to child window for auth code/token
|
|
176
|
-
*/
|
|
177
118
|
addMessageChannel(resolve, reject) {
|
|
178
119
|
listener = event => {
|
|
179
|
-
// this should probably get better handling, but ignored for now
|
|
180
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
181
120
|
this.finishOAuthWindow(event, resolve, reject);
|
|
182
121
|
};
|
|
183
122
|
window.addEventListener('message', listener);
|
|
184
123
|
},
|
|
185
|
-
/**
|
|
186
|
-
* #action
|
|
187
|
-
*/
|
|
188
124
|
deleteMessageChannel() {
|
|
189
125
|
window.removeEventListener('message', listener);
|
|
190
126
|
},
|
|
191
|
-
/**
|
|
192
|
-
* #action
|
|
193
|
-
*/
|
|
194
127
|
async finishOAuthWindow(event, resolve, reject) {
|
|
195
128
|
if (event.data.name !== `JBrowseAuthWindow-${self.internetAccountId}`) {
|
|
196
129
|
this.deleteMessageChannel();
|
|
@@ -243,11 +176,6 @@ const stateModelFactory = (configSchema) => {
|
|
|
243
176
|
}
|
|
244
177
|
this.deleteMessageChannel();
|
|
245
178
|
},
|
|
246
|
-
/**
|
|
247
|
-
* #action
|
|
248
|
-
* opens external OAuth flow, popup for web and new browser window for
|
|
249
|
-
* desktop
|
|
250
|
-
*/
|
|
251
179
|
async useEndpointForAuthorization(resolve, reject) {
|
|
252
180
|
const redirectUri = isElectron
|
|
253
181
|
? 'http://localhost/auth'
|
|
@@ -282,22 +210,15 @@ const stateModelFactory = (configSchema) => {
|
|
|
282
210
|
const eventFromDesktop = new MessageEvent('message', {
|
|
283
211
|
data: { name: eventName, redirectUri: redirectUri },
|
|
284
212
|
});
|
|
285
|
-
// may want to improve handling
|
|
286
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
287
213
|
this.finishOAuthWindow(eventFromDesktop, resolve, reject);
|
|
288
214
|
}
|
|
289
215
|
else {
|
|
290
216
|
window.open(url, eventName, 'width=500,height=600,left=0,top=0');
|
|
291
217
|
}
|
|
292
218
|
},
|
|
293
|
-
/**
|
|
294
|
-
* #action
|
|
295
|
-
*/
|
|
296
219
|
async getTokenFromUser(resolve, reject) {
|
|
297
220
|
const refreshToken = self.retrieveRefreshToken();
|
|
298
221
|
let doUserFlow = true;
|
|
299
|
-
// if there is a refresh token, then try it out, and only if that
|
|
300
|
-
// refresh token succeeds, set doUserFlow to false
|
|
301
222
|
if (refreshToken) {
|
|
302
223
|
try {
|
|
303
224
|
const token = await self.exchangeRefreshForAccessToken(refreshToken);
|
|
@@ -311,14 +232,9 @@ const stateModelFactory = (configSchema) => {
|
|
|
311
232
|
}
|
|
312
233
|
if (doUserFlow) {
|
|
313
234
|
this.addMessageChannel(resolve, reject);
|
|
314
|
-
// may want to improve handling
|
|
315
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
316
235
|
this.useEndpointForAuthorization(resolve, reject);
|
|
317
236
|
}
|
|
318
237
|
},
|
|
319
|
-
/**
|
|
320
|
-
* #action
|
|
321
|
-
*/
|
|
322
238
|
async validateToken(token, location) {
|
|
323
239
|
const newInit = self.addAuthHeaderToInit({ method: 'HEAD' }, token);
|
|
324
240
|
const response = await fetch(location.uri, newInit);
|
|
@@ -337,7 +253,6 @@ const stateModelFactory = (configSchema) => {
|
|
|
337
253
|
}
|
|
338
254
|
catch (err) {
|
|
339
255
|
console.error('Token could not be refreshed', err);
|
|
340
|
-
// let original error be thrown
|
|
341
256
|
}
|
|
342
257
|
}
|
|
343
258
|
throw new Error(await getResponseError({
|
|
@@ -352,16 +267,6 @@ const stateModelFactory = (configSchema) => {
|
|
|
352
267
|
.actions(self => {
|
|
353
268
|
const superGetFetcher = self.getFetcher;
|
|
354
269
|
return {
|
|
355
|
-
/**
|
|
356
|
-
* #action
|
|
357
|
-
* Get a fetch method that will add any needed authentication headers
|
|
358
|
-
* to the request before sending it. If location is provided, it will
|
|
359
|
-
* be checked to see if it includes a token in it's pre-auth
|
|
360
|
-
* information.
|
|
361
|
-
*
|
|
362
|
-
* @param loc - UriLocation of the resource
|
|
363
|
-
* @returns A function that can be used to fetch
|
|
364
|
-
*/
|
|
365
270
|
getFetcher(loc) {
|
|
366
271
|
const fetcher = superGetFetcher(loc);
|
|
367
272
|
return async (input, init) => {
|
package/esm/OAuthModel/util.js
CHANGED
|
@@ -6,7 +6,6 @@ export async function generateChallenge(val) {
|
|
|
6
6
|
const Base64 = await import('crypto-js/enc-base64');
|
|
7
7
|
return fixup(Base64.stringify(sha256(val)));
|
|
8
8
|
}
|
|
9
|
-
// if response is JSON, checks if it needs to remove tokens in error, or just plain throw
|
|
10
9
|
export function processError(text, invalidErrorCb) {
|
|
11
10
|
var _a;
|
|
12
11
|
try {
|
|
@@ -17,7 +16,6 @@ export function processError(text, invalidErrorCb) {
|
|
|
17
16
|
return (_a = obj === null || obj === void 0 ? void 0 : obj.error_description) !== null && _a !== void 0 ? _a : text;
|
|
18
17
|
}
|
|
19
18
|
catch (e) {
|
|
20
|
-
/* response text is not json, just use original text as error */
|
|
21
19
|
}
|
|
22
20
|
return text;
|
|
23
21
|
}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Plugin from '@jbrowse/core/Plugin';
|
|
2
|
-
import PluginManager from '@jbrowse/core/PluginManager';
|
|
3
2
|
import { modelFactory as GoogleDriveOAuthInternetAccountModelFactory } from './GoogleDriveOAuthModel';
|
|
3
|
+
import type PluginManager from '@jbrowse/core/PluginManager';
|
|
4
4
|
export default class AuthenticationPlugin extends Plugin {
|
|
5
5
|
name: string;
|
|
6
6
|
exports: {
|
package/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Plugin from '@jbrowse/core/Plugin';
|
|
2
2
|
import InternetAccountType from '@jbrowse/core/pluggableElementTypes/InternetAccountType';
|
|
3
|
-
import { configSchema as OAuthConfigSchema, modelFactory as OAuthInternetAccountModelFactory, } from './OAuthModel';
|
|
4
|
-
import { configSchema as ExternalTokenConfigSchema, modelFactory as ExternalTokenInternetAccountModelFactory, } from './ExternalTokenModel';
|
|
5
|
-
import { configSchema as HTTPBasicConfigSchema, modelFactory as HTTPBasicInternetAccountModelFactory, } from './HTTPBasicModel';
|
|
6
3
|
import { configSchema as DropboxOAuthConfigSchema, modelFactory as DropboxOAuthInternetAccountModelFactory, } from './DropboxOAuthModel';
|
|
4
|
+
import { configSchema as ExternalTokenConfigSchema, modelFactory as ExternalTokenInternetAccountModelFactory, } from './ExternalTokenModel';
|
|
7
5
|
import { configSchema as GoogleDriveOAuthConfigSchema, modelFactory as GoogleDriveOAuthInternetAccountModelFactory, } from './GoogleDriveOAuthModel';
|
|
6
|
+
import { configSchema as HTTPBasicConfigSchema, modelFactory as HTTPBasicInternetAccountModelFactory, } from './HTTPBasicModel';
|
|
7
|
+
import { configSchema as OAuthConfigSchema, modelFactory as OAuthInternetAccountModelFactory, } from './OAuthModel';
|
|
8
8
|
export default class AuthenticationPlugin extends Plugin {
|
|
9
9
|
constructor() {
|
|
10
10
|
super(...arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jbrowse/plugin-authentication",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"description": "JBrowse 2 Authentication",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jbrowse",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"distModule": "esm/index.js",
|
|
56
56
|
"srcModule": "src/index.ts",
|
|
57
57
|
"module": "esm/index.js",
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "c344ea60099cb7e460b77f15808946b24a7eee74"
|
|
59
59
|
}
|