@jbrowse/plugin-authentication 2.4.2 → 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 (102) hide show
  1. package/dist/DropboxOAuthModel/configSchema.d.ts +105 -1
  2. package/dist/DropboxOAuthModel/configSchema.js +0 -8
  3. package/dist/DropboxOAuthModel/configSchema.js.map +1 -1
  4. package/dist/DropboxOAuthModel/model.d.ts +304 -8
  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 -2
  11. package/dist/ExternalTokenModel/ExternalTokenEntryForm.js +10 -11
  12. package/dist/ExternalTokenModel/ExternalTokenEntryForm.js.map +1 -1
  13. package/dist/ExternalTokenModel/configSchema.d.ts +36 -1
  14. package/dist/ExternalTokenModel/model.d.ts +93 -3
  15. package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +15 -0
  16. package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +20 -0
  17. package/dist/GoogleDriveOAuthModel/GoogleDriveFilehandle.js.map +1 -0
  18. package/dist/GoogleDriveOAuthModel/configSchema.d.ts +105 -1
  19. package/dist/GoogleDriveOAuthModel/model.d.ts +219 -20
  20. package/dist/GoogleDriveOAuthModel/model.js +38 -51
  21. package/dist/GoogleDriveOAuthModel/model.js.map +1 -1
  22. package/dist/GoogleDriveOAuthModel/util.d.ts +1 -0
  23. package/dist/GoogleDriveOAuthModel/util.js +17 -0
  24. package/dist/GoogleDriveOAuthModel/util.js.map +1 -0
  25. package/dist/HTTPBasicModel/HTTPBasicLoginForm.d.ts +2 -2
  26. package/dist/HTTPBasicModel/HTTPBasicLoginForm.js +17 -21
  27. package/dist/HTTPBasicModel/HTTPBasicLoginForm.js.map +1 -1
  28. package/dist/HTTPBasicModel/configSchema.d.ts +44 -1
  29. package/dist/HTTPBasicModel/model.d.ts +135 -3
  30. package/dist/HTTPBasicModel/model.js +24 -9
  31. package/dist/HTTPBasicModel/model.js.map +1 -1
  32. package/dist/OAuthModel/configSchema.d.ts +94 -1
  33. package/dist/OAuthModel/configSchema.js +1 -9
  34. package/dist/OAuthModel/configSchema.js.map +1 -1
  35. package/dist/OAuthModel/model.d.ts +263 -8
  36. package/dist/OAuthModel/model.js +165 -113
  37. package/dist/OAuthModel/model.js.map +1 -1
  38. package/dist/OAuthModel/util.d.ts +7 -0
  39. package/dist/OAuthModel/util.js +60 -0
  40. package/dist/OAuthModel/util.js.map +1 -0
  41. package/dist/index.d.ts +954 -105
  42. package/dist/util.d.ts +6 -0
  43. package/dist/util.js +23 -0
  44. package/dist/util.js.map +1 -0
  45. package/esm/DropboxOAuthModel/configSchema.d.ts +105 -1
  46. package/esm/DropboxOAuthModel/configSchema.js +0 -8
  47. package/esm/DropboxOAuthModel/configSchema.js.map +1 -1
  48. package/esm/DropboxOAuthModel/model.d.ts +304 -8
  49. package/esm/DropboxOAuthModel/model.js +26 -35
  50. package/esm/DropboxOAuthModel/model.js.map +1 -1
  51. package/esm/DropboxOAuthModel/util.d.ts +1 -0
  52. package/esm/DropboxOAuthModel/util.js +24 -0
  53. package/esm/DropboxOAuthModel/util.js.map +1 -0
  54. package/esm/ExternalTokenModel/ExternalTokenEntryForm.d.ts +2 -2
  55. package/esm/ExternalTokenModel/ExternalTokenEntryForm.js +10 -11
  56. package/esm/ExternalTokenModel/ExternalTokenEntryForm.js.map +1 -1
  57. package/esm/ExternalTokenModel/configSchema.d.ts +36 -1
  58. package/esm/ExternalTokenModel/model.d.ts +93 -3
  59. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.d.ts +15 -0
  60. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.js +16 -0
  61. package/esm/GoogleDriveOAuthModel/GoogleDriveFilehandle.js.map +1 -0
  62. package/esm/GoogleDriveOAuthModel/configSchema.d.ts +105 -1
  63. package/esm/GoogleDriveOAuthModel/model.d.ts +219 -20
  64. package/esm/GoogleDriveOAuthModel/model.js +37 -49
  65. package/esm/GoogleDriveOAuthModel/model.js.map +1 -1
  66. package/esm/GoogleDriveOAuthModel/util.d.ts +1 -0
  67. package/esm/GoogleDriveOAuthModel/util.js +13 -0
  68. package/esm/GoogleDriveOAuthModel/util.js.map +1 -0
  69. package/esm/HTTPBasicModel/HTTPBasicLoginForm.d.ts +2 -2
  70. package/esm/HTTPBasicModel/HTTPBasicLoginForm.js +18 -22
  71. package/esm/HTTPBasicModel/HTTPBasicLoginForm.js.map +1 -1
  72. package/esm/HTTPBasicModel/configSchema.d.ts +44 -1
  73. package/esm/HTTPBasicModel/model.d.ts +135 -3
  74. package/esm/HTTPBasicModel/model.js +24 -9
  75. package/esm/HTTPBasicModel/model.js.map +1 -1
  76. package/esm/OAuthModel/configSchema.d.ts +94 -1
  77. package/esm/OAuthModel/configSchema.js +1 -9
  78. package/esm/OAuthModel/configSchema.js.map +1 -1
  79. package/esm/OAuthModel/model.d.ts +263 -8
  80. package/esm/OAuthModel/model.js +164 -86
  81. package/esm/OAuthModel/model.js.map +1 -1
  82. package/esm/OAuthModel/util.d.ts +7 -0
  83. package/esm/OAuthModel/util.js +30 -0
  84. package/esm/OAuthModel/util.js.map +1 -0
  85. package/esm/index.d.ts +954 -105
  86. package/esm/util.d.ts +6 -0
  87. package/esm/util.js +18 -0
  88. package/esm/util.js.map +1 -0
  89. package/package.json +3 -4
  90. package/src/DropboxOAuthModel/configSchema.ts +0 -8
  91. package/src/DropboxOAuthModel/model.tsx +35 -54
  92. package/src/DropboxOAuthModel/util.ts +36 -0
  93. package/src/ExternalTokenModel/ExternalTokenEntryForm.tsx +39 -41
  94. package/src/GoogleDriveOAuthModel/GoogleDriveFilehandle.ts +38 -0
  95. package/src/GoogleDriveOAuthModel/model.tsx +54 -104
  96. package/src/GoogleDriveOAuthModel/util.ts +29 -0
  97. package/src/HTTPBasicModel/HTTPBasicLoginForm.tsx +53 -56
  98. package/src/HTTPBasicModel/model.tsx +26 -11
  99. package/src/OAuthModel/configSchema.ts +2 -9
  100. package/src/OAuthModel/model.tsx +190 -108
  101. package/src/OAuthModel/util.ts +33 -0
  102. 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
  /**