@jbrowse/plugin-authentication 2.5.0 → 2.6.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.
Files changed (96) hide show
  1. package/dist/DropboxOAuthModel/configSchema.d.ts +3 -14
  2. package/dist/DropboxOAuthModel/configSchema.js +0 -8
  3. package/dist/DropboxOAuthModel/configSchema.js.map +1 -1
  4. package/dist/DropboxOAuthModel/model.d.ts +35 -33
  5. package/dist/DropboxOAuthModel/model.js +26 -35
  6. package/dist/DropboxOAuthModel/model.js.map +1 -1
  7. package/dist/DropboxOAuthModel/util.d.ts +1 -0
  8. package/dist/DropboxOAuthModel/util.js +28 -0
  9. package/dist/DropboxOAuthModel/util.js.map +1 -0
  10. package/dist/ExternalTokenModel/ExternalTokenEntryForm.d.ts +2 -1
  11. package/dist/ExternalTokenModel/ExternalTokenEntryForm.js +10 -11
  12. package/dist/ExternalTokenModel/ExternalTokenEntryForm.js.map +1 -1
  13. package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +15 -0
  14. package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +20 -0
  15. package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.js.map +1 -0
  16. package/dist/GoogleDriveOAuthModel/configSchema.d.ts +0 -5
  17. package/dist/GoogleDriveOAuthModel/model.d.ts +36 -121
  18. package/dist/GoogleDriveOAuthModel/model.js +38 -51
  19. package/dist/GoogleDriveOAuthModel/model.js.map +1 -1
  20. package/dist/GoogleDriveOAuthModel/util.d.ts +1 -0
  21. package/dist/GoogleDriveOAuthModel/util.js +17 -0
  22. package/dist/GoogleDriveOAuthModel/util.js.map +1 -0
  23. package/dist/HTTPBasicModel/HTTPBasicLoginForm.d.ts +2 -1
  24. package/dist/HTTPBasicModel/HTTPBasicLoginForm.js +17 -21
  25. package/dist/HTTPBasicModel/HTTPBasicLoginForm.js.map +1 -1
  26. package/dist/HTTPBasicModel/model.d.ts +36 -4
  27. package/dist/HTTPBasicModel/model.js +24 -9
  28. package/dist/HTTPBasicModel/model.js.map +1 -1
  29. package/dist/OAuthModel/configSchema.d.ts +0 -8
  30. package/dist/OAuthModel/configSchema.js +1 -9
  31. package/dist/OAuthModel/configSchema.js.map +1 -1
  32. package/dist/OAuthModel/model.d.ts +103 -18
  33. package/dist/OAuthModel/model.js +165 -113
  34. package/dist/OAuthModel/model.js.map +1 -1
  35. package/dist/OAuthModel/util.d.ts +7 -0
  36. package/dist/OAuthModel/util.js +60 -0
  37. package/dist/OAuthModel/util.js.map +1 -0
  38. package/dist/index.d.ts +7 -433
  39. package/dist/util.d.ts +6 -0
  40. package/dist/util.js +23 -0
  41. package/dist/util.js.map +1 -0
  42. package/esm/DropboxOAuthModel/configSchema.d.ts +3 -14
  43. package/esm/DropboxOAuthModel/configSchema.js +0 -8
  44. package/esm/DropboxOAuthModel/configSchema.js.map +1 -1
  45. package/esm/DropboxOAuthModel/model.d.ts +35 -33
  46. package/esm/DropboxOAuthModel/model.js +26 -35
  47. package/esm/DropboxOAuthModel/model.js.map +1 -1
  48. package/esm/DropboxOAuthModel/util.d.ts +1 -0
  49. package/esm/DropboxOAuthModel/util.js +24 -0
  50. package/esm/DropboxOAuthModel/util.js.map +1 -0
  51. package/esm/ExternalTokenModel/ExternalTokenEntryForm.d.ts +2 -1
  52. package/esm/ExternalTokenModel/ExternalTokenEntryForm.js +10 -11
  53. package/esm/ExternalTokenModel/ExternalTokenEntryForm.js.map +1 -1
  54. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +15 -0
  55. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +16 -0
  56. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.js.map +1 -0
  57. package/esm/GoogleDriveOAuthModel/configSchema.d.ts +0 -5
  58. package/esm/GoogleDriveOAuthModel/model.d.ts +36 -121
  59. package/esm/GoogleDriveOAuthModel/model.js +37 -49
  60. package/esm/GoogleDriveOAuthModel/model.js.map +1 -1
  61. package/esm/GoogleDriveOAuthModel/util.d.ts +1 -0
  62. package/esm/GoogleDriveOAuthModel/util.js +13 -0
  63. package/esm/GoogleDriveOAuthModel/util.js.map +1 -0
  64. package/esm/HTTPBasicModel/HTTPBasicLoginForm.d.ts +2 -1
  65. package/esm/HTTPBasicModel/HTTPBasicLoginForm.js +18 -22
  66. package/esm/HTTPBasicModel/HTTPBasicLoginForm.js.map +1 -1
  67. package/esm/HTTPBasicModel/model.d.ts +36 -4
  68. package/esm/HTTPBasicModel/model.js +24 -9
  69. package/esm/HTTPBasicModel/model.js.map +1 -1
  70. package/esm/OAuthModel/configSchema.d.ts +0 -8
  71. package/esm/OAuthModel/configSchema.js +1 -9
  72. package/esm/OAuthModel/configSchema.js.map +1 -1
  73. package/esm/OAuthModel/model.d.ts +103 -18
  74. package/esm/OAuthModel/model.js +164 -86
  75. package/esm/OAuthModel/model.js.map +1 -1
  76. package/esm/OAuthModel/util.d.ts +7 -0
  77. package/esm/OAuthModel/util.js +30 -0
  78. package/esm/OAuthModel/util.js.map +1 -0
  79. package/esm/index.d.ts +7 -433
  80. package/esm/util.d.ts +6 -0
  81. package/esm/util.js +18 -0
  82. package/esm/util.js.map +1 -0
  83. package/package.json +3 -4
  84. package/src/DropboxOAuthModel/configSchema.ts +0 -8
  85. package/src/DropboxOAuthModel/model.tsx +35 -54
  86. package/src/DropboxOAuthModel/util.ts +36 -0
  87. package/src/ExternalTokenModel/ExternalTokenEntryForm.tsx +39 -41
  88. package/src/GoogleDriveOAuthModel/GoogleDriveFilehandle.ts +38 -0
  89. package/src/GoogleDriveOAuthModel/model.tsx +54 -104
  90. package/src/GoogleDriveOAuthModel/util.ts +29 -0
  91. package/src/HTTPBasicModel/HTTPBasicLoginForm.tsx +53 -56
  92. package/src/HTTPBasicModel/model.tsx +26 -11
  93. package/src/OAuthModel/configSchema.ts +2 -9
  94. package/src/OAuthModel/model.tsx +190 -108
  95. package/src/OAuthModel/util.ts +33 -0
  96. package/src/util.ts +25 -0
@@ -1,12 +1,6 @@
1
1
  import React, { useState } from 'react'
2
- import {
3
- Button,
4
- Dialog,
5
- DialogContent,
6
- DialogTitle,
7
- DialogActions,
8
- TextField,
9
- } from '@mui/material'
2
+ import { Button, DialogContent, DialogActions, TextField } from '@mui/material'
3
+ import { Dialog } from '@jbrowse/core/ui'
10
4
 
11
5
  export const HTTPBasicLoginForm = ({
12
6
  internetAccountId,
@@ -18,54 +12,57 @@ export const HTTPBasicLoginForm = ({
18
12
  const [username, setUsername] = useState('')
19
13
  const [password, setPassword] = useState('')
20
14
 
21
- function onSubmit(event: React.FormEvent<HTMLFormElement>) {
22
- if (username && password) {
23
- handleClose(btoa(`${username}:${password}`))
24
- } else {
25
- handleClose()
26
- }
27
- event.preventDefault()
28
- }
29
-
30
15
  return (
31
- <>
32
- <Dialog open maxWidth="xl" data-testid="login-httpbasic">
33
- <DialogTitle>Log In for {internetAccountId}</DialogTitle>
34
- <form onSubmit={onSubmit}>
35
- <DialogContent style={{ display: 'flex', flexDirection: 'column' }}>
36
- <TextField
37
- required
38
- label="Username"
39
- variant="outlined"
40
- inputProps={{ 'data-testid': 'login-httpbasic-username' }}
41
- onChange={event => setUsername(event.target.value)}
42
- margin="dense"
43
- />
44
- <TextField
45
- required
46
- label="Password"
47
- type="password"
48
- autoComplete="current-password"
49
- variant="outlined"
50
- inputProps={{ 'data-testid': 'login-httpbasic-password' }}
51
- onChange={event => setPassword(event.target.value)}
52
- margin="dense"
53
- />
54
- </DialogContent>
55
- <DialogActions>
56
- <Button variant="contained" color="primary" type="submit">
57
- Submit
58
- </Button>
59
- <Button
60
- variant="contained"
61
- type="submit"
62
- onClick={() => handleClose()}
63
- >
64
- Cancel
65
- </Button>
66
- </DialogActions>
67
- </form>
68
- </Dialog>
69
- </>
16
+ <Dialog
17
+ open
18
+ maxWidth="xl"
19
+ data-testid="login-httpbasic"
20
+ title={`Log In for ${internetAccountId}`}
21
+ >
22
+ <form
23
+ onSubmit={event => {
24
+ if (username && password) {
25
+ handleClose(btoa(`${username}:${password}`))
26
+ } else {
27
+ handleClose()
28
+ }
29
+ event.preventDefault()
30
+ }}
31
+ >
32
+ <DialogContent style={{ display: 'flex', flexDirection: 'column' }}>
33
+ <TextField
34
+ required
35
+ label="Username"
36
+ variant="outlined"
37
+ inputProps={{ 'data-testid': 'login-httpbasic-username' }}
38
+ onChange={event => setUsername(event.target.value)}
39
+ margin="dense"
40
+ />
41
+ <TextField
42
+ required
43
+ label="Password"
44
+ type="password"
45
+ autoComplete="current-password"
46
+ variant="outlined"
47
+ inputProps={{ 'data-testid': 'login-httpbasic-password' }}
48
+ onChange={event => setPassword(event.target.value)}
49
+ margin="dense"
50
+ />
51
+ </DialogContent>
52
+ <DialogActions>
53
+ <Button variant="contained" color="primary" type="submit">
54
+ Submit
55
+ </Button>
56
+ <Button
57
+ variant="contained"
58
+ color="secondary"
59
+ type="submit"
60
+ onClick={() => handleClose()}
61
+ >
62
+ Cancel
63
+ </Button>
64
+ </DialogActions>
65
+ </form>
66
+ </Dialog>
70
67
  )
71
68
  }
@@ -1,25 +1,42 @@
1
1
  import { ConfigurationReference, getConf } from '@jbrowse/core/configuration'
2
2
  import { InternetAccount } from '@jbrowse/core/pluggableElementTypes/models'
3
3
  import { UriLocation } from '@jbrowse/core/util/types'
4
- import { HTTPBasicInternetAccountConfigModel } from './configSchema'
5
4
  import { Instance, types, getRoot } from 'mobx-state-tree'
6
5
 
6
+ // locals
7
+ import { HTTPBasicInternetAccountConfigModel } from './configSchema'
7
8
  import { HTTPBasicLoginForm } from './HTTPBasicLoginForm'
9
+ import { getResponseError } from '../util'
8
10
 
11
+ /**
12
+ * #stateModel HTTPBasicInternetAccount
13
+ */
9
14
  const stateModelFactory = (
10
15
  configSchema: HTTPBasicInternetAccountConfigModel,
11
16
  ) => {
12
17
  return InternetAccount.named('HTTPBasicInternetAccount')
13
18
  .props({
19
+ /**
20
+ * #property
21
+ */
14
22
  type: types.literal('HTTPBasicInternetAccount'),
23
+ /**
24
+ * #property
25
+ */
15
26
  configuration: ConfigurationReference(configSchema),
16
27
  })
17
28
  .views(self => ({
29
+ /**
30
+ * #getter
31
+ */
18
32
  get validateWithHEAD(): boolean {
19
33
  return getConf(self, 'validateWithHEAD')
20
34
  },
21
35
  }))
22
36
  .actions(self => ({
37
+ /**
38
+ * #action
39
+ */
23
40
  getTokenFromUser(
24
41
  resolve: (token: string) => void,
25
42
  reject: (error: Error) => void,
@@ -34,13 +51,16 @@ const stateModelFactory = (
34
51
  if (token) {
35
52
  resolve(token)
36
53
  } else {
37
- reject(new Error('user cancelled entry'))
54
+ reject(new Error('User cancelled entry'))
38
55
  }
39
56
  doneCallback()
40
57
  },
41
58
  },
42
59
  ])
43
60
  },
61
+ /**
62
+ * #action
63
+ */
44
64
  async validateToken(token: string, location: UriLocation) {
45
65
  if (!self.validateWithHEAD) {
46
66
  return token
@@ -48,16 +68,11 @@ const stateModelFactory = (
48
68
  const newInit = self.addAuthHeaderToInit({ method: 'HEAD' }, token)
49
69
  const response = await fetch(location.uri, newInit)
50
70
  if (!response.ok) {
51
- let errorMessage
52
- try {
53
- errorMessage = await response.text()
54
- } catch (error) {
55
- errorMessage = ''
56
- }
57
71
  throw new Error(
58
- `Error validating token — ${response.status} (${
59
- response.statusText
60
- })${errorMessage ? ` (${errorMessage})` : ''}`,
72
+ await getResponseError({
73
+ response,
74
+ reason: 'Error validating token',
75
+ }),
61
76
  )
62
77
  }
63
78
  return token
@@ -70,18 +70,11 @@ const OAuthConfigSchema = ConfigurationSchema(
70
70
  * #slot
71
71
  */
72
72
  responseType: {
73
- description: 'the type of response from the authorization endpoint',
73
+ description:
74
+ "the type of response from the authorization endpoint. can be 'token' or 'code'",
74
75
  type: 'string',
75
76
  defaultValue: 'code',
76
77
  },
77
- /**
78
- * #slot
79
- */
80
- hasRefreshToken: {
81
- description: 'true if the endpoint can supply a refresh token',
82
- type: 'boolean',
83
- defaultValue: false,
84
- },
85
78
  },
86
79
  {
87
80
  /**