@jbrowse/plugin-authentication 4.3.0 → 5.0.0-beta.2

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 (50) hide show
  1. package/esm/DropboxOAuthModel/DropboxIcon.d.ts +1 -1
  2. package/esm/DropboxOAuthModel/configSchema.d.ts +110 -82
  3. package/esm/DropboxOAuthModel/configSchema.js +32 -2
  4. package/esm/DropboxOAuthModel/index.js +2 -2
  5. package/esm/DropboxOAuthModel/model.d.ts +235 -201
  6. package/esm/DropboxOAuthModel/model.js +46 -21
  7. package/esm/DropboxOAuthModel/util.d.ts +1 -1
  8. package/esm/DropboxOAuthModel/util.js +9 -12
  9. package/esm/ExternalTokenModel/ExternalTokenEntryForm.d.ts +1 -1
  10. package/esm/ExternalTokenModel/ExternalTokenEntryForm.js +11 -15
  11. package/esm/ExternalTokenModel/configSchema.d.ts +43 -24
  12. package/esm/ExternalTokenModel/configSchema.js +22 -1
  13. package/esm/ExternalTokenModel/index.js +2 -2
  14. package/esm/ExternalTokenModel/model.d.ts +47 -71
  15. package/esm/ExternalTokenModel/model.js +11 -54
  16. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +2 -9
  17. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +27 -6
  18. package/esm/GoogleDriveOAuthModel/GoogleDriveIcon.d.ts +1 -1
  19. package/esm/GoogleDriveOAuthModel/configSchema.d.ts +109 -82
  20. package/esm/GoogleDriveOAuthModel/configSchema.js +32 -3
  21. package/esm/GoogleDriveOAuthModel/index.js +2 -2
  22. package/esm/GoogleDriveOAuthModel/model.d.ts +230 -202
  23. package/esm/GoogleDriveOAuthModel/model.js +45 -22
  24. package/esm/GoogleDriveOAuthModel/util.d.ts +1 -1
  25. package/esm/GoogleDriveOAuthModel/util.js +2 -11
  26. package/esm/HTTPBasicModel/HTTPBasicLoginForm.d.ts +1 -1
  27. package/esm/HTTPBasicModel/HTTPBasicLoginForm.js +17 -22
  28. package/esm/HTTPBasicModel/configSchema.d.ts +51 -28
  29. package/esm/HTTPBasicModel/configSchema.js +26 -1
  30. package/esm/HTTPBasicModel/index.js +2 -2
  31. package/esm/HTTPBasicModel/model.d.ts +55 -76
  32. package/esm/HTTPBasicModel/model.js +21 -51
  33. package/esm/OAuthModel/OAuthLoginPrompt.d.ts +4 -0
  34. package/esm/OAuthModel/OAuthLoginPrompt.js +12 -0
  35. package/esm/OAuthModel/configSchema.d.ts +79 -52
  36. package/esm/OAuthModel/configSchema.js +30 -1
  37. package/esm/OAuthModel/index.js +2 -2
  38. package/esm/OAuthModel/model.d.ts +218 -114
  39. package/esm/OAuthModel/model.js +361 -217
  40. package/esm/OAuthModel/util.d.ts +46 -7
  41. package/esm/OAuthModel/util.js +159 -16
  42. package/esm/index.d.ts +295 -981
  43. package/esm/index.js +29 -45
  44. package/esm/lazyLoginForms.d.ts +18 -0
  45. package/esm/lazyLoginForms.js +25 -0
  46. package/esm/tokenEntryModelFactory.d.ts +125 -0
  47. package/esm/tokenEntryModelFactory.js +85 -0
  48. package/esm/util.d.ts +10 -0
  49. package/esm/util.js +24 -2
  50. package/package.json +10 -13
@@ -1,48 +1,77 @@
1
1
  import { ConfigurationSchema } from '@jbrowse/core/configuration';
2
2
  import { BaseInternetAccountConfig } from '@jbrowse/core/pluggableElementTypes/models';
3
- function x() { }
3
+ /**
4
+ * #config OAuthInternetAccount
5
+ */
4
6
  const OAuthConfigSchema = ConfigurationSchema('OAuthInternetAccount', {
7
+ /**
8
+ * #slot
9
+ */
5
10
  tokenType: {
6
11
  description: 'a custom name for a token to include in the header',
7
12
  type: 'string',
8
13
  defaultValue: 'Bearer',
9
14
  },
15
+ /**
16
+ * #slot
17
+ */
10
18
  authEndpoint: {
11
19
  description: 'the authorization code endpoint of the internet account',
12
20
  type: 'string',
13
21
  defaultValue: '',
14
22
  },
23
+ /**
24
+ * #slot
25
+ */
15
26
  tokenEndpoint: {
16
27
  description: 'the token endpoint of the internet account',
17
28
  type: 'string',
18
29
  defaultValue: '',
19
30
  },
31
+ /**
32
+ * #slot
33
+ */
20
34
  needsPKCE: {
21
35
  description: 'boolean to indicate if the endpoint needs a PKCE code',
22
36
  type: 'boolean',
23
37
  defaultValue: false,
24
38
  },
39
+ /**
40
+ * #slot
41
+ */
25
42
  clientId: {
26
43
  description: 'id for the OAuth application',
27
44
  type: 'string',
28
45
  defaultValue: '',
29
46
  },
47
+ /**
48
+ * #slot
49
+ */
30
50
  scopes: {
31
51
  description: 'optional scopes for the authorization call',
32
52
  type: 'string',
33
53
  defaultValue: '',
34
54
  },
55
+ /**
56
+ * #slot
57
+ */
35
58
  state: {
36
59
  description: 'optional state for the authorization call',
37
60
  type: 'string',
38
61
  defaultValue: '',
39
62
  },
63
+ /**
64
+ * #slot
65
+ */
40
66
  responseType: {
41
67
  description: "the type of response from the authorization endpoint. can be 'token' or 'code'",
42
68
  type: 'string',
43
69
  defaultValue: 'code',
44
70
  },
45
71
  }, {
72
+ /**
73
+ * #baseConfiguration
74
+ */
46
75
  baseConfiguration: BaseInternetAccountConfig,
47
76
  explicitlyTyped: true,
48
77
  });
@@ -1,2 +1,2 @@
1
- export { default as configSchema } from "./configSchema.js";
2
- export { default as modelFactory } from "./model.js";
1
+ export { default as configSchema } from './configSchema.js';
2
+ export { default as modelFactory } from './model.js';
@@ -1,106 +1,115 @@
1
- import type { OAuthInternetAccountConfigModel } from './configSchema.ts';
1
+ import type { OAuthInternetAccountConfig, OAuthInternetAccountConfigModel } from './configSchema.ts';
2
2
  import type { UriLocation } from '@jbrowse/core/util';
3
3
  import type { Instance } from '@jbrowse/mobx-state-tree';
4
- declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel) => import("@jbrowse/mobx-state-tree").IModelType<{
4
+ /**
5
+ * #stateModel OAuthInternetAccount
6
+ */
7
+ declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel) => import("@jbrowse/mobx-state-tree").IModelType<Omit<{
5
8
  id: import("@jbrowse/mobx-state-tree").IOptionalIType<import("@jbrowse/mobx-state-tree").ISimpleType<string>, [undefined]>;
6
9
  type: import("@jbrowse/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("@jbrowse/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;
10
+ configuration: import("@jbrowse/core/configuration/configurationSchema").IConfigurationReference<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
11
+ readonly name: {
12
+ readonly description: "descriptive name of the internet account";
13
+ readonly type: "string";
14
+ readonly defaultValue: "";
15
+ };
16
+ readonly description: {
17
+ readonly description: "a description of the internet account";
18
+ readonly type: "string";
19
+ readonly defaultValue: "";
20
+ };
21
+ readonly authHeader: {
22
+ readonly description: "request header for credentials";
23
+ readonly type: "string";
24
+ readonly defaultValue: "Authorization";
25
+ };
26
+ readonly tokenType: {
27
+ readonly description: "a custom name for a token to include in the header";
28
+ readonly type: "string";
29
+ readonly defaultValue: "";
30
+ };
31
+ readonly domains: {
32
+ readonly description: "array of valid domains the url can contain to use this account";
33
+ readonly type: "stringArray";
34
+ readonly defaultValue: readonly [];
35
+ };
36
+ }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>>;
37
+ }, "configuration" | "type"> & {
38
+ /**
39
+ * #property
40
+ */
41
+ type: import("@jbrowse/mobx-state-tree").ILiteralType<"OAuthInternetAccount">;
42
+ /**
43
+ * #property
44
+ */
45
+ configuration: import("@jbrowse/core/configuration/configurationSchema").IConfigurationReference<import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
46
+ readonly tokenType: {
47
+ readonly description: "a custom name for a token to include in the header";
48
+ readonly type: "string";
49
+ readonly defaultValue: "Bearer";
50
+ };
51
+ readonly authEndpoint: {
52
+ readonly description: "the authorization code endpoint of the internet account";
53
+ readonly type: "string";
54
+ readonly defaultValue: "";
55
+ };
56
+ readonly tokenEndpoint: {
57
+ readonly description: "the token endpoint of the internet account";
58
+ readonly type: "string";
59
+ readonly defaultValue: "";
60
+ };
61
+ readonly needsPKCE: {
62
+ readonly description: "boolean to indicate if the endpoint needs a PKCE code";
63
+ readonly type: "boolean";
64
+ readonly defaultValue: false;
65
+ };
66
+ readonly clientId: {
67
+ readonly description: "id for the OAuth application";
68
+ readonly type: "string";
69
+ readonly defaultValue: "";
70
+ };
71
+ readonly scopes: {
72
+ readonly description: "optional scopes for the authorization call";
73
+ readonly type: "string";
74
+ readonly defaultValue: "";
75
+ };
76
+ readonly state: {
77
+ readonly description: "optional state for the authorization call";
78
+ readonly type: "string";
79
+ readonly defaultValue: "";
80
+ };
81
+ readonly responseType: {
82
+ readonly description: "the type of response from the authorization endpoint. can be 'token' or 'code'";
83
+ readonly type: "string";
84
+ readonly defaultValue: "code";
76
85
  };
77
86
  }, 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>>;
87
+ readonly name: {
88
+ readonly description: "descriptive name of the internet account";
89
+ readonly type: "string";
90
+ readonly defaultValue: "";
91
+ };
92
+ readonly description: {
93
+ readonly description: "a description of the internet account";
94
+ readonly type: "string";
95
+ readonly defaultValue: "";
96
+ };
97
+ readonly authHeader: {
98
+ readonly description: "request header for credentials";
99
+ readonly type: "string";
100
+ readonly defaultValue: "Authorization";
101
+ };
102
+ readonly tokenType: {
103
+ readonly description: "a custom name for a token to include in the header";
104
+ readonly type: "string";
105
+ readonly defaultValue: "";
106
+ };
107
+ readonly domains: {
108
+ readonly description: "array of valid domains the url can contain to use this account";
109
+ readonly type: "stringArray";
110
+ readonly defaultValue: readonly [];
111
+ };
112
+ }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, "internetAccountId">>, undefined>>>;
104
113
  }, {
105
114
  readonly name: string;
106
115
  readonly description: string;
@@ -109,22 +118,21 @@ declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel)
109
118
  readonly tokenType: string;
110
119
  readonly domains: string[];
111
120
  readonly toggleContents: React.ReactNode;
112
- readonly SelectorComponent: import("@jbrowse/core/util").AnyReactComponentType | undefined;
113
121
  readonly selectorLabel: string | undefined;
122
+ readonly showInFileSelector: boolean;
114
123
  } & {
115
124
  handlesLocation(location: UriLocation): boolean;
116
125
  readonly tokenKey: string;
117
126
  } & {
118
127
  getTokenFromUser(_resolve: (token: string) => void, _reject: (error: Error) => void): void;
119
128
  storeToken(token: string): void;
120
- removeToken(): void;
121
- retrieveToken(): string | null;
129
+ retrieveToken(): string | undefined;
122
130
  validateToken(token: string, _loc: UriLocation): Promise<string>;
123
131
  } & {
132
+ removeToken(): void;
124
133
  getToken(location?: UriLocation): Promise<string>;
125
134
  } & {
126
135
  addAuthHeaderToInit(init?: RequestInit, token?: string): {
127
- headers: Headers;
128
136
  body?: BodyInit | null;
129
137
  cache?: RequestCache;
130
138
  credentials?: RequestCredentials;
@@ -138,44 +146,140 @@ declare const stateModelFactory: (configSchema: OAuthInternetAccountConfigModel)
138
146
  referrerPolicy?: ReferrerPolicy;
139
147
  signal?: AbortSignal | null;
140
148
  window?: null;
149
+ headers: Headers;
141
150
  };
151
+ fetchWithToken(loc: UriLocation | undefined, run: (token: string) => Promise<Response>): Promise<Response>;
142
152
  getPreAuthorizationInformation(location: UriLocation): Promise<{
143
153
  internetAccountType: string;
144
154
  authInfo: {
145
155
  token: string;
146
- configuration: any;
156
+ configuration: import("@jbrowse/mobx-state-tree").ModelSnapshotType<Record<string, any>>;
147
157
  };
148
158
  }>;
149
159
  } & {
150
160
  getFetcher(loc?: UriLocation): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
151
161
  } & {
152
- openLocation(location: UriLocation): import("@jbrowse/core/util/io").RemoteFileWithRangeCache;
162
+ openLocation(location: UriLocation): import("@gmod/range-cache-filehandle").RemoteFileWithRangeCache;
153
163
  } & {
154
- readonly codeVerifierPKCE: string;
164
+ /**
165
+ * #getter
166
+ * The config typed off the concrete schema. `ConfigurationReference`
167
+ * erases `self.configuration` to `any` (the reference's MST instance brand
168
+ * doesn't carry the schema's slot definitions), so reads go through this
169
+ * getter to recover per-slot types and slot-name validation.
170
+ */
171
+ readonly conf: OAuthInternetAccountConfig;
155
172
  } & {
173
+ /**
174
+ * #getter
175
+ */
156
176
  readonly authEndpoint: string;
177
+ /**
178
+ * #getter
179
+ */
157
180
  readonly tokenEndpoint: string;
181
+ /**
182
+ * #getter
183
+ */
158
184
  readonly needsPKCE: boolean;
185
+ /**
186
+ * #getter
187
+ */
159
188
  readonly clientId: string;
189
+ /**
190
+ * #getter
191
+ */
160
192
  readonly scopes: string;
161
- state(): string | undefined;
162
- readonly responseType: "token" | "code";
193
+ /**
194
+ * #getter
195
+ * OAuth state parameter:
196
+ * https://www.rfc-editor.org/rfc/rfc6749#section-4.1.1
197
+ *
198
+ * Can override or extend if dynamic state is needed.
199
+ */
200
+ readonly state: string;
201
+ /**
202
+ * #getter
203
+ */
204
+ readonly responseType: 'token' | 'code';
205
+ /**
206
+ * #getter
207
+ */
163
208
  readonly refreshTokenKey: string;
209
+ /**
210
+ * #getter
211
+ * Extra parameters to add to the authorization request. Empty here;
212
+ * a provider that needs one of its own overrides this.
213
+ */
214
+ readonly authFlowParams: Record<string, string>;
164
215
  } & {
216
+ /**
217
+ * #action
218
+ */
165
219
  storeRefreshToken(refreshToken: string): void;
220
+ /**
221
+ * #action
222
+ */
166
223
  removeRefreshToken(): void;
167
- retrieveRefreshToken(): string | null;
168
- exchangeAuthorizationForAccessToken(token: string, redirectUri: string): Promise<string>;
224
+ /**
225
+ * #method
226
+ */
227
+ retrieveRefreshToken(): string | undefined;
228
+ } & {
229
+ /**
230
+ * #action
231
+ * POST a grant to the token endpoint and read the access token out of the
232
+ * answer. Both grants this account makes — trading the authorization code
233
+ * on the way in, trading the refresh token when the access token expires
234
+ * — are the same form-encoded request to the same endpoint answered by
235
+ * the same body, and OAuth 2 says so (RFC 6749 §4.1.3, §6). They differ
236
+ * in the grant's own parameters and in what a failure means, which is
237
+ * what stays at the call sites.
238
+ *
239
+ * @param grant - the grant-specific parameters; `client_id` is added
240
+ * @param describeError - turns a failed exchange into a message, and is
241
+ * where a grant does whatever invalidating its failure implies
242
+ */
243
+ postTokenGrant(grant: Record<string, string>, describeError: (response: Response) => Promise<string>): Promise<string>;
244
+ } & {
245
+ /**
246
+ * #action
247
+ */
248
+ exchangeAuthorizationForAccessToken(code: string, redirectUri: string, codeVerifier: string | undefined): Promise<string>;
249
+ /**
250
+ * #action
251
+ */
169
252
  exchangeRefreshForAccessToken(refreshToken: string): Promise<string>;
170
253
  } & {
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>;
254
+ /**
255
+ * #action
256
+ * Prove a token against the resource and, if that fails, refresh it once
257
+ * and prove the new one. Returns whichever token worked; throws if
258
+ * neither does. Every OAuth account validates this way and they differ
259
+ * only in what a probe is — a HEAD of the resource here, a metadata call
260
+ * for Dropbox and Google Drive.
261
+ *
262
+ * @param token - the token to prove
263
+ * @param probe - issues a request that succeeds iff the token is good
264
+ * @param describeError - turns a failed probe into a message
265
+ */
266
+ validateTokenWithProbe(token: string, probe: (token: string) => Promise<Response>, describeError: (response: Response, reason?: string) => Promise<string>): Promise<string>;
267
+ /**
268
+ * #action
269
+ * Opens the provider's auth page and returns a promise for the resulting
270
+ * token. For Electron, drives the flow directly via IPC; for web, opens a
271
+ * popup and waits for the redirect message.
272
+ */
273
+ getTokenViaAuthFlow(): Promise<string>;
274
+ } & {
275
+ /**
276
+ * #action
277
+ */
175
278
  getTokenFromUser(resolve: (token: string) => void, reject: (error: Error) => void): Promise<void>;
279
+ /**
280
+ * #action
281
+ */
176
282
  validateToken(token: string, location: UriLocation): Promise<string>;
177
- } & {
178
- getFetcher(loc?: UriLocation): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
179
283
  }, import("@jbrowse/mobx-state-tree")._NotCustomized, import("@jbrowse/mobx-state-tree")._NotCustomized>;
180
284
  export default stateModelFactory;
181
285
  export type OAuthStateModel = ReturnType<typeof stateModelFactory>;