forked from ToolJet/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOauth.jsx
More file actions
185 lines (171 loc) · 5.64 KB
/
Oauth.jsx
File metadata and controls
185 lines (171 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import React, { useEffect } from 'react';
import Input from '@/_ui/Input';
import Select from '@/_ui/Select';
import Headers from '@/_ui/HttpHeaders';
const Oauth = ({
access_token_url,
auth_url,
client_id,
client_secret,
client_auth,
custom_auth_params,
custom_query_params,
add_token_to,
header_prefix,
grant_type,
scopes,
authObject,
optionchanged,
access_token_custom_headers,
workspaceConstants,
}) => {
useEffect(() => {
if (authObject && authObject?.flows['authorizationCode']) {
const { flows, general_scopes } = authObject;
const { authorizationUrl, tokenUrl } = flows['authorizationCode'];
optionchanged('access_token_url', tokenUrl);
setTimeout(() => {
optionchanged('auth_url', authorizationUrl);
optionchanged('scopes', convertScopesToString(general_scopes));
}, 500);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [authObject, grant_type]);
const convertScopesToString = (scopes) => {
let scopes_str = '';
scopes.map((scope) => {
scopes_str += scope + ' ';
});
return scopes_str;
};
if (authObject && !authObject?.flows['authorizationCode']) return null;
return (
<div>
<div className="row mt-3">
<label className="form-label text-muted">Grant Type</label>
<Select
options={[{ name: 'Authorization Code', value: 'authorization_code' }]}
value={grant_type}
onChange={(value) => optionchanged('grant_type', value)}
width={'100%'}
useMenuPortal={false}
/>
<label className="form-label text-muted mt-3">Add Access Token To</label>
<Select
options={[{ name: 'Request Header', value: 'header' }]}
value={add_token_to}
onChange={(value) => optionchanged('add_token_to', value)}
width={'100%'}
useMenuPortal={false}
/>
{add_token_to === 'header' && (
<div className="col-md-12">
<label className="form-label text-muted mt-3">Header Prefix</label>
<Input
type="text"
className="form-control"
onChange={(e) => optionchanged('header_prefix', e.target.value)}
value={header_prefix}
/>
</div>
)}
</div>
<div className="col-md-12">
<label className="form-label text-muted mt-3">Access Token URL</label>
<Input
type="text"
placeholder="https://api.example.com/oauth/token"
className="form-control"
onChange={(e) => optionchanged('access_token_url', e.target.value)}
value={access_token_url}
/>
</div>
<div className="row mt-3">
<div className="col">
<label className="form-label pt-2">Access Token URL custom headers</label>
</div>
</div>
<Headers
getter={'access_token_custom_headers'}
options={access_token_custom_headers}
optionchanged={optionchanged}
/>
<div className="col-md-12">
<label className="form-label text-muted mt-3">Client ID</label>
<Input
type="text"
className="form-control"
onChange={(e) => optionchanged('client_id', e.target.value)}
value={client_id}
workspaceConstants={workspaceConstants}
/>
</div>
<div className="col-md-12">
<label className="form-label text-muted mt-3">Client Secret</label>
<Input
type="text"
className="form-control"
onChange={(e) => optionchanged('client_secret', e.target.value)}
value={client_secret}
/>
</div>
<div className="col-md-12">
<label className="form-label text-muted mt-3">Scope(s)</label>
<Input
type="text"
className="form-control"
onChange={(e) => optionchanged('scopes', e.target.value)}
value={scopes}
/>
</div>
<div className="row mt-3">
<div className="col">
<label className="form-label pt-2">Custom Query Parameters</label>
</div>
</div>
<Headers
getter={'custom_query_params'}
options={custom_query_params}
optionchanged={optionchanged}
workspaceConstants={workspaceConstants}
/>
{grant_type === 'authorization_code' && (
<div>
<div className="col-md-12">
<label className="form-label text-muted mt-3">Authorization URL</label>
<Input
type="text"
placeholder="https://api.example.com/oauth/authorize"
className="form-control"
onChange={(e) => optionchanged('auth_url', e.target.value)}
value={auth_url}
/>
</div>
<div className="row mt-3">
<div className="col">
<label className="form-label pt-2">Custom Authentication Parameters</label>
</div>
</div>
<Headers
getter={'custom_auth_params'}
options={custom_auth_params}
optionchanged={optionchanged}
workspaceConstants={workspaceConstants}
/>
<label className="form-label text-muted mt-3">Client Authentication</label>
<Select
options={[
{ name: 'Send as Basic Auth header', value: 'header' },
{ name: 'Send client credentials in body ', value: 'body' },
]}
value={client_auth}
onChange={(value) => optionchanged('client_auth', value)}
width={'100%'}
useMenuPortal={false}
/>
</div>
)}
</div>
);
};
export default Oauth;