@authorizerdev/authorizer-js 1.1.5 → 1.2.0-beta.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/README.md +25 -21
- package/{lib/cjs/types.d.ts → dist/index.d.ts} +83 -53
- package/dist/index.global.js +19 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +14 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -12
- package/lib/authorizer.min.js +0 -2
- package/lib/authorizer.min.js.map +0 -1
- package/lib/cjs/constants.d.ts +0 -3
- package/lib/cjs/index.d.ts +0 -29
- package/lib/cjs/index.js +0 -519
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/utils.d.ts +0 -13
- package/lib/constants.d.ts +0 -3
- package/lib/esm/constants.d.ts +0 -3
- package/lib/esm/index.d.ts +0 -29
- package/lib/esm/index.js +0 -511
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/types.d.ts +0 -185
- package/lib/esm/utils.d.ts +0 -13
- package/lib/index.d.ts +0 -29
- package/lib/types.d.ts +0 -185
- package/lib/utils.d.ts +0 -13
- package/src/constants.ts +0 -3
- package/src/index.ts +0 -493
- package/src/types.ts +0 -203
- package/src/utils.ts +0 -157
package/src/index.ts
DELETED
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
// Note: write gql query in single line to reduce bundle size
|
|
2
|
-
import crossFetch from 'cross-fetch';
|
|
3
|
-
import { DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS } from './constants';
|
|
4
|
-
import * as Types from './types';
|
|
5
|
-
import {
|
|
6
|
-
trimURL,
|
|
7
|
-
hasWindow,
|
|
8
|
-
encode,
|
|
9
|
-
createRandomString,
|
|
10
|
-
sha256,
|
|
11
|
-
bufferToBase64UrlEncoded,
|
|
12
|
-
createQueryParams,
|
|
13
|
-
executeIframe,
|
|
14
|
-
} from './utils';
|
|
15
|
-
|
|
16
|
-
// re-usable gql response fragment
|
|
17
|
-
const userFragment = `id email email_verified given_name family_name middle_name nickname preferred_username picture signup_methods gender birthdate phone_number phone_number_verified roles created_at updated_at is_multi_factor_auth_enabled `;
|
|
18
|
-
const authTokenFragment = `message access_token expires_in refresh_token id_token should_show_otp_screen user { ${userFragment} }`;
|
|
19
|
-
|
|
20
|
-
// set fetch based on window object. Cross fetch have issues with umd build
|
|
21
|
-
const getFetcher = () => (hasWindow() ? window.fetch : crossFetch);
|
|
22
|
-
|
|
23
|
-
export * from './types';
|
|
24
|
-
export class Authorizer {
|
|
25
|
-
// class variable
|
|
26
|
-
config: Types.ConfigType;
|
|
27
|
-
codeVerifier: string;
|
|
28
|
-
|
|
29
|
-
// constructor
|
|
30
|
-
constructor(config: Types.ConfigType) {
|
|
31
|
-
if (!config) {
|
|
32
|
-
throw new Error(`Configuration is required`);
|
|
33
|
-
}
|
|
34
|
-
this.config = config;
|
|
35
|
-
if (!config.authorizerURL && !config.authorizerURL.trim()) {
|
|
36
|
-
throw new Error(`Invalid authorizerURL`);
|
|
37
|
-
}
|
|
38
|
-
if (config.authorizerURL) {
|
|
39
|
-
this.config.authorizerURL = trimURL(config.authorizerURL);
|
|
40
|
-
}
|
|
41
|
-
if (!config.redirectURL && !config.redirectURL.trim()) {
|
|
42
|
-
throw new Error(`Invalid redirectURL`);
|
|
43
|
-
} else {
|
|
44
|
-
this.config.redirectURL = trimURL(config.redirectURL);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this.config.extraHeaders = {
|
|
48
|
-
...(config.extraHeaders || {}),
|
|
49
|
-
'x-authorizer-url': this.config.authorizerURL,
|
|
50
|
-
'Content-Type': 'application/json',
|
|
51
|
-
};
|
|
52
|
-
this.config.clientID = config.clientID.trim();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
authorize = async (data: Types.AuthorizeInput) => {
|
|
56
|
-
if (!hasWindow()) {
|
|
57
|
-
throw new Error(`this feature is only supported in browser`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const scopes = ['openid', 'profile', 'email'];
|
|
61
|
-
if (data.use_refresh_token) {
|
|
62
|
-
scopes.push('offline_access');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const requestData: Record<string, string> = {
|
|
66
|
-
redirect_uri: this.config.redirectURL,
|
|
67
|
-
response_mode: data.response_mode || 'web_message',
|
|
68
|
-
state: encode(createRandomString()),
|
|
69
|
-
nonce: encode(createRandomString()),
|
|
70
|
-
response_type: data.response_type,
|
|
71
|
-
scope: scopes.join(' '),
|
|
72
|
-
client_id: this.config.clientID,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
if (data.response_type === Types.ResponseTypes.Code) {
|
|
76
|
-
this.codeVerifier = createRandomString();
|
|
77
|
-
const sha = await sha256(this.codeVerifier);
|
|
78
|
-
const codeChallenge = bufferToBase64UrlEncoded(sha);
|
|
79
|
-
requestData.code_challenge = codeChallenge;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const authorizeURL = `${
|
|
83
|
-
this.config.authorizerURL
|
|
84
|
-
}/authorize?${createQueryParams(requestData)}`;
|
|
85
|
-
|
|
86
|
-
if (requestData.response_mode !== 'web_message') {
|
|
87
|
-
window.location.replace(authorizeURL);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
const iframeRes = await executeIframe(
|
|
93
|
-
authorizeURL,
|
|
94
|
-
this.config.authorizerURL,
|
|
95
|
-
DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (data.response_type === Types.ResponseTypes.Code) {
|
|
99
|
-
// get token and return it
|
|
100
|
-
const token = await this.getToken({ code: iframeRes.code });
|
|
101
|
-
return token;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// this includes access_token, id_token & refresh_token(optionally)
|
|
105
|
-
return iframeRes;
|
|
106
|
-
} catch (err) {
|
|
107
|
-
if (err.error) {
|
|
108
|
-
window.location.replace(
|
|
109
|
-
`${this.config.authorizerURL}/app?state=${encode(
|
|
110
|
-
JSON.stringify(this.config),
|
|
111
|
-
)}&redirect_uri=${this.config.redirectURL}`,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
throw err;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
browserLogin = async (): Promise<Types.AuthToken | void> => {
|
|
120
|
-
try {
|
|
121
|
-
const token = await this.getSession();
|
|
122
|
-
return token;
|
|
123
|
-
} catch (err) {
|
|
124
|
-
if (!hasWindow()) {
|
|
125
|
-
throw new Error(`browserLogin is only supported for browsers`);
|
|
126
|
-
}
|
|
127
|
-
window.location.replace(
|
|
128
|
-
`${this.config.authorizerURL}/app?state=${encode(
|
|
129
|
-
JSON.stringify(this.config),
|
|
130
|
-
)}&redirect_uri=${this.config.redirectURL}`,
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
forgotPassword = async (
|
|
136
|
-
data: Types.ForgotPasswordInput,
|
|
137
|
-
): Promise<Types.Response | void> => {
|
|
138
|
-
if (!data.state) {
|
|
139
|
-
data.state = encode(createRandomString());
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!data.redirect_uri) {
|
|
143
|
-
data.redirect_uri = this.config.redirectURL;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
try {
|
|
147
|
-
const forgotPasswordRes = await this.graphqlQuery({
|
|
148
|
-
query: `mutation forgotPassword($data: ForgotPasswordInput!) { forgot_password(params: $data) { message } }`,
|
|
149
|
-
variables: {
|
|
150
|
-
data,
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
return forgotPasswordRes.forgot_password;
|
|
155
|
-
} catch (error) {
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
getMetaData = async (): Promise<Types.MetaData | void> => {
|
|
161
|
-
try {
|
|
162
|
-
const res = await this.graphqlQuery({
|
|
163
|
-
query: `query { meta { version is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_linkedin_login_enabled is_apple_login_enabled is_twitter_login_enabled is_microsoft_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled } }`,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
return res.meta;
|
|
167
|
-
} catch (err) {
|
|
168
|
-
throw err;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
getProfile = async (headers?: Types.Headers): Promise<Types.User | void> => {
|
|
173
|
-
try {
|
|
174
|
-
const profileRes = await this.graphqlQuery({
|
|
175
|
-
query: `query { profile { ${userFragment} } }`,
|
|
176
|
-
headers,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
return profileRes.profile;
|
|
180
|
-
} catch (error) {
|
|
181
|
-
throw error;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// this is used to verify / get session using cookie by default. If using nodejs pass authorization header
|
|
186
|
-
getSession = async (
|
|
187
|
-
headers?: Types.Headers,
|
|
188
|
-
params?: Types.SessionQueryInput,
|
|
189
|
-
): Promise<Types.AuthToken> => {
|
|
190
|
-
try {
|
|
191
|
-
const res = await this.graphqlQuery({
|
|
192
|
-
query: `query getSession($params: SessionQueryInput){session(params: $params) { ${authTokenFragment} } }`,
|
|
193
|
-
headers,
|
|
194
|
-
variables: {
|
|
195
|
-
params,
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
return res.session;
|
|
199
|
-
} catch (err) {
|
|
200
|
-
throw err;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
getToken = async (
|
|
205
|
-
data: Types.GetTokenInput,
|
|
206
|
-
): Promise<Types.GetTokenResponse> => {
|
|
207
|
-
if (!data.grant_type) {
|
|
208
|
-
data.grant_type = 'authorization_code';
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (data.grant_type === 'refresh_token' && !data.refresh_token) {
|
|
212
|
-
throw new Error(`Invalid refresh_token`);
|
|
213
|
-
}
|
|
214
|
-
if (data.grant_type === 'authorization_code' && !this.codeVerifier) {
|
|
215
|
-
throw new Error(`Invalid code verifier`);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const requestData = {
|
|
219
|
-
client_id: this.config.clientID,
|
|
220
|
-
code: data.code || '',
|
|
221
|
-
code_verifier: this.codeVerifier || '',
|
|
222
|
-
grant_type: data.grant_type || '',
|
|
223
|
-
refresh_token: data.refresh_token || '',
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
try {
|
|
227
|
-
const fetcher = getFetcher();
|
|
228
|
-
const res = await fetcher(`${this.config.authorizerURL}/oauth/token`, {
|
|
229
|
-
method: 'POST',
|
|
230
|
-
body: JSON.stringify(requestData),
|
|
231
|
-
headers: {
|
|
232
|
-
...this.config.extraHeaders,
|
|
233
|
-
},
|
|
234
|
-
credentials: 'include',
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
const json = await res.json();
|
|
238
|
-
if (res.status >= 400) {
|
|
239
|
-
throw new Error(json);
|
|
240
|
-
}
|
|
241
|
-
return json;
|
|
242
|
-
} catch (err) {
|
|
243
|
-
throw err;
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
// helper to execute graphql queries
|
|
248
|
-
// takes in any query or mutation string as input
|
|
249
|
-
graphqlQuery = async (data: Types.GraphqlQueryInput) => {
|
|
250
|
-
const fetcher = getFetcher();
|
|
251
|
-
const res = await fetcher(this.config.authorizerURL + '/graphql', {
|
|
252
|
-
method: 'POST',
|
|
253
|
-
body: JSON.stringify({
|
|
254
|
-
query: data.query,
|
|
255
|
-
variables: data.variables || {},
|
|
256
|
-
}),
|
|
257
|
-
headers: {
|
|
258
|
-
...this.config.extraHeaders,
|
|
259
|
-
...(data.headers || {}),
|
|
260
|
-
},
|
|
261
|
-
credentials: 'include',
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
const json = await res.json();
|
|
265
|
-
|
|
266
|
-
if (json.errors && json.errors.length) {
|
|
267
|
-
console.error(json.errors);
|
|
268
|
-
throw new Error(json.errors[0].message);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return json.data;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
login = async (data: Types.LoginInput): Promise<Types.AuthToken | void> => {
|
|
275
|
-
try {
|
|
276
|
-
const res = await this.graphqlQuery({
|
|
277
|
-
query: `
|
|
278
|
-
mutation login($data: LoginInput!) { login(params: $data) { ${authTokenFragment}}}
|
|
279
|
-
`,
|
|
280
|
-
variables: { data },
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
return res.login;
|
|
284
|
-
} catch (err) {
|
|
285
|
-
throw err;
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
logout = async (headers?: Types.Headers): Promise<Types.Response | void> => {
|
|
290
|
-
try {
|
|
291
|
-
const res = await this.graphqlQuery({
|
|
292
|
-
query: ` mutation { logout { message } } `,
|
|
293
|
-
headers,
|
|
294
|
-
});
|
|
295
|
-
return res.logout;
|
|
296
|
-
} catch (err) {
|
|
297
|
-
console.error(err);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
magicLinkLogin = async (
|
|
302
|
-
data: Types.MagicLinkLoginInput,
|
|
303
|
-
): Promise<Types.Response> => {
|
|
304
|
-
try {
|
|
305
|
-
if (!data.state) {
|
|
306
|
-
data.state = encode(createRandomString());
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (!data.redirect_uri) {
|
|
310
|
-
data.redirect_uri = this.config.redirectURL;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const res = await this.graphqlQuery({
|
|
314
|
-
query: `
|
|
315
|
-
mutation magicLinkLogin($data: MagicLinkLoginInput!) { magic_link_login(params: $data) { message }}
|
|
316
|
-
`,
|
|
317
|
-
variables: { data },
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
return res.magic_link_login;
|
|
321
|
-
} catch (err) {
|
|
322
|
-
throw err;
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
oauthLogin = async (
|
|
327
|
-
oauthProvider: string,
|
|
328
|
-
roles?: string[],
|
|
329
|
-
redirect_uri?: string,
|
|
330
|
-
state?: string,
|
|
331
|
-
): Promise<void> => {
|
|
332
|
-
let urlState = state;
|
|
333
|
-
if (!urlState) {
|
|
334
|
-
urlState = encode(createRandomString());
|
|
335
|
-
}
|
|
336
|
-
// @ts-ignore
|
|
337
|
-
if (!Object.values(Types.OAuthProviders).includes(oauthProvider)) {
|
|
338
|
-
throw new Error(
|
|
339
|
-
`only following oauth providers are supported: ${Object.values(
|
|
340
|
-
oauthProvider,
|
|
341
|
-
).toString()}`,
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
if (!hasWindow()) {
|
|
345
|
-
throw new Error(`oauthLogin is only supported for browsers`);
|
|
346
|
-
}
|
|
347
|
-
window.location.replace(
|
|
348
|
-
`${this.config.authorizerURL}/oauth_login/${oauthProvider}?redirect_uri=${
|
|
349
|
-
redirect_uri || this.config.redirectURL
|
|
350
|
-
}&state=${urlState}${
|
|
351
|
-
roles && roles.length ? `&roles=${roles.join(',')}` : ``
|
|
352
|
-
}`,
|
|
353
|
-
);
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
resendOtp = async (
|
|
357
|
-
data: Types.ResendOtpInput,
|
|
358
|
-
): Promise<Types.Response | void> => {
|
|
359
|
-
try {
|
|
360
|
-
const res = await this.graphqlQuery({
|
|
361
|
-
query: `
|
|
362
|
-
mutation resendOtp($data: ResendOTPRequest!) { resend_otp(params: $data) { message }}
|
|
363
|
-
`,
|
|
364
|
-
variables: { data },
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
return res.resend_otp;
|
|
368
|
-
} catch (err) {
|
|
369
|
-
throw err;
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
resetPassword = async (
|
|
374
|
-
data: Types.ResetPasswordInput,
|
|
375
|
-
): Promise<Types.Response | void> => {
|
|
376
|
-
try {
|
|
377
|
-
const resetPasswordRes = await this.graphqlQuery({
|
|
378
|
-
query: `mutation resetPassword($data: ResetPasswordInput!) { reset_password(params: $data) { message } }`,
|
|
379
|
-
variables: {
|
|
380
|
-
data,
|
|
381
|
-
},
|
|
382
|
-
});
|
|
383
|
-
return resetPasswordRes.reset_password;
|
|
384
|
-
} catch (error) {
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
revokeToken = async (data: { refresh_token: string }) => {
|
|
390
|
-
if (!data.refresh_token && !data.refresh_token.trim()) {
|
|
391
|
-
throw new Error(`Invalid refresh_token`);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const fetcher = getFetcher();
|
|
395
|
-
const res = await fetcher(this.config.authorizerURL + '/oauth/revoke', {
|
|
396
|
-
method: 'POST',
|
|
397
|
-
headers: {
|
|
398
|
-
...this.config.extraHeaders,
|
|
399
|
-
},
|
|
400
|
-
body: JSON.stringify({
|
|
401
|
-
refresh_token: data.refresh_token,
|
|
402
|
-
client_id: this.config.clientID,
|
|
403
|
-
}),
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
return await res.json();
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
signup = async (data: Types.SignupInput): Promise<Types.AuthToken | void> => {
|
|
410
|
-
try {
|
|
411
|
-
const res = await this.graphqlQuery({
|
|
412
|
-
query: `
|
|
413
|
-
mutation signup($data: SignUpInput!) { signup(params: $data) { ${authTokenFragment}}}
|
|
414
|
-
`,
|
|
415
|
-
variables: { data },
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
return res.signup;
|
|
419
|
-
} catch (err) {
|
|
420
|
-
throw err;
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
updateProfile = async (
|
|
425
|
-
data: Types.UpdateProfileInput,
|
|
426
|
-
headers?: Types.Headers,
|
|
427
|
-
): Promise<Types.Response | void> => {
|
|
428
|
-
try {
|
|
429
|
-
const updateProfileRes = await this.graphqlQuery({
|
|
430
|
-
query: `mutation updateProfile($data: UpdateProfileInput!) { update_profile(params: $data) { message } }`,
|
|
431
|
-
headers,
|
|
432
|
-
variables: {
|
|
433
|
-
data,
|
|
434
|
-
},
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
return updateProfileRes.update_profile;
|
|
438
|
-
} catch (error) {
|
|
439
|
-
throw error;
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
validateJWTToken = async (
|
|
444
|
-
params?: Types.ValidateJWTTokenInput,
|
|
445
|
-
): Promise<Types.ValidateJWTTokenResponse> => {
|
|
446
|
-
try {
|
|
447
|
-
const res = await this.graphqlQuery({
|
|
448
|
-
query: `query validateJWTToken($params: ValidateJWTTokenInput!){validate_jwt_token(params: $params) { is_valid claims } }`,
|
|
449
|
-
variables: {
|
|
450
|
-
params,
|
|
451
|
-
},
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
return res.validate_jwt_token;
|
|
455
|
-
} catch (error) {
|
|
456
|
-
throw error;
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
verifyEmail = async (
|
|
461
|
-
data: Types.VerifyEmailInput,
|
|
462
|
-
): Promise<Types.AuthToken | void> => {
|
|
463
|
-
try {
|
|
464
|
-
const res = await this.graphqlQuery({
|
|
465
|
-
query: `
|
|
466
|
-
mutation verifyEmail($data: VerifyEmailInput!) { verify_email(params: $data) { ${authTokenFragment}}}
|
|
467
|
-
`,
|
|
468
|
-
variables: { data },
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
return res.verify_email;
|
|
472
|
-
} catch (err) {
|
|
473
|
-
throw err;
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
verifyOtp = async (
|
|
478
|
-
data: Types.VerifyOtpInput,
|
|
479
|
-
): Promise<Types.AuthToken | void> => {
|
|
480
|
-
try {
|
|
481
|
-
const res = await this.graphqlQuery({
|
|
482
|
-
query: `
|
|
483
|
-
mutation verifyOtp($data: VerifyOTPRequest!) { verify_otp(params: $data) { ${authTokenFragment}}}
|
|
484
|
-
`,
|
|
485
|
-
variables: { data },
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
return res.verify_otp;
|
|
489
|
-
} catch (err) {
|
|
490
|
-
throw err;
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
export type ConfigType = {
|
|
2
|
-
authorizerURL: string;
|
|
3
|
-
redirectURL: string;
|
|
4
|
-
clientID: string;
|
|
5
|
-
extraHeaders?: Record<string, string>;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type User = {
|
|
9
|
-
id: string;
|
|
10
|
-
email: string;
|
|
11
|
-
preferred_username: string;
|
|
12
|
-
email_verified: boolean;
|
|
13
|
-
signup_methods: string;
|
|
14
|
-
given_name?: string | null;
|
|
15
|
-
family_name?: string | null;
|
|
16
|
-
middle_name?: string | null;
|
|
17
|
-
nickname?: string | null;
|
|
18
|
-
picture?: string | null;
|
|
19
|
-
gender?: string | null;
|
|
20
|
-
birthdate?: string | null;
|
|
21
|
-
phone_number?: string | null;
|
|
22
|
-
phone_number_verified?: boolean | null;
|
|
23
|
-
roles?: string[];
|
|
24
|
-
created_at: number;
|
|
25
|
-
updated_at: number;
|
|
26
|
-
is_multi_factor_auth_enabled?: boolean;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type AuthToken = {
|
|
30
|
-
message?: string;
|
|
31
|
-
access_token: string;
|
|
32
|
-
expires_in: number;
|
|
33
|
-
id_token: string;
|
|
34
|
-
refresh_token?: string;
|
|
35
|
-
user?: User;
|
|
36
|
-
should_show_otp_screen?: boolean;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type Response = {
|
|
40
|
-
message: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type Headers = Record<string, string>;
|
|
44
|
-
|
|
45
|
-
export type LoginInput = {
|
|
46
|
-
email: string;
|
|
47
|
-
password: string;
|
|
48
|
-
roles?: string[];
|
|
49
|
-
scope?: string[];
|
|
50
|
-
state?: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type SignupInput = {
|
|
54
|
-
email: string;
|
|
55
|
-
password: string;
|
|
56
|
-
confirm_password: string;
|
|
57
|
-
given_name?: string;
|
|
58
|
-
family_name?: string;
|
|
59
|
-
middle_name?: string;
|
|
60
|
-
nickname?: string;
|
|
61
|
-
picture?: string;
|
|
62
|
-
gender?: string;
|
|
63
|
-
birthdate?: string;
|
|
64
|
-
phone_number?: string;
|
|
65
|
-
roles?: string[];
|
|
66
|
-
scope?: string[];
|
|
67
|
-
redirect_uri?: string;
|
|
68
|
-
is_multi_factor_auth_enabled?: boolean;
|
|
69
|
-
state?: string;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export type MagicLinkLoginInput = {
|
|
73
|
-
email: string;
|
|
74
|
-
roles?: string[];
|
|
75
|
-
scopes?: string[];
|
|
76
|
-
state?: string;
|
|
77
|
-
redirect_uri?: string;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export type VerifyEmailInput = { token: string; state?: string };
|
|
81
|
-
|
|
82
|
-
export type VerifyOtpInput = { email: string; otp: string; state?: string };
|
|
83
|
-
|
|
84
|
-
export type ResendOtpInput = { email: string };
|
|
85
|
-
|
|
86
|
-
export type GraphqlQueryInput = {
|
|
87
|
-
query: string;
|
|
88
|
-
variables?: Record<string, any>;
|
|
89
|
-
headers?: Headers;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export type MetaData = {
|
|
93
|
-
version: string;
|
|
94
|
-
client_id: string;
|
|
95
|
-
is_google_login_enabled: boolean;
|
|
96
|
-
is_facebook_login_enabled: boolean;
|
|
97
|
-
is_github_login_enabled: boolean;
|
|
98
|
-
is_linkedin_login_enabled: boolean;
|
|
99
|
-
is_apple_login_enabled: boolean;
|
|
100
|
-
is_twitter_login_enabled: boolean;
|
|
101
|
-
is_microsoft_login_enabled: boolean;
|
|
102
|
-
is_email_verification_enabled: boolean;
|
|
103
|
-
is_basic_authentication_enabled: boolean;
|
|
104
|
-
is_magic_link_login_enabled: boolean;
|
|
105
|
-
is_sign_up_enabled: boolean;
|
|
106
|
-
is_strong_password_enabled: boolean;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export type UpdateProfileInput = {
|
|
110
|
-
old_password?: string;
|
|
111
|
-
new_password?: string;
|
|
112
|
-
confirm_new_password?: string;
|
|
113
|
-
email?: string;
|
|
114
|
-
given_name?: string;
|
|
115
|
-
family_name?: string;
|
|
116
|
-
middle_name?: string;
|
|
117
|
-
nickname?: string;
|
|
118
|
-
gender?: string;
|
|
119
|
-
birthdate?: string;
|
|
120
|
-
phone_number?: string;
|
|
121
|
-
picture?: string;
|
|
122
|
-
is_multi_factor_auth_enabled?: boolean;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export type ForgotPasswordInput = {
|
|
126
|
-
email: string;
|
|
127
|
-
state?: string;
|
|
128
|
-
redirect_uri?: string;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export type ResetPasswordInput = {
|
|
132
|
-
token: string;
|
|
133
|
-
password: string;
|
|
134
|
-
confirm_password: string;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export type SessionQueryInput = {
|
|
138
|
-
roles?: string[];
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export type IsValidJWTQueryInput = {
|
|
142
|
-
jwt: string;
|
|
143
|
-
roles?: string[];
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export type ValidJWTResponse = {
|
|
147
|
-
valid: string;
|
|
148
|
-
message: string;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export enum OAuthProviders {
|
|
152
|
-
Apple = 'apple',
|
|
153
|
-
Github = 'github',
|
|
154
|
-
Google = 'google',
|
|
155
|
-
Facebook = 'facebook',
|
|
156
|
-
LinkedIn = 'linkedin',
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export enum ResponseTypes {
|
|
160
|
-
Code = 'code',
|
|
161
|
-
Token = 'token',
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export type AuthorizeInput = {
|
|
165
|
-
response_type: ResponseTypes;
|
|
166
|
-
use_refresh_token?: boolean;
|
|
167
|
-
response_mode?: string;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export type AuthorizeResponse = {
|
|
171
|
-
state: string;
|
|
172
|
-
code?: string;
|
|
173
|
-
error?: string;
|
|
174
|
-
error_description?: string;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export type RevokeTokenInput = {
|
|
178
|
-
refresh_token: string;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export type GetTokenInput = {
|
|
182
|
-
code?: string;
|
|
183
|
-
grant_type?: string;
|
|
184
|
-
refresh_token?: string;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export type GetTokenResponse = {
|
|
188
|
-
access_token: string;
|
|
189
|
-
expires_in: number;
|
|
190
|
-
id_token: string;
|
|
191
|
-
refresh_token?: string;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
export type ValidateJWTTokenInput = {
|
|
195
|
-
token_type: 'access_token' | 'id_token' | 'refresh_token';
|
|
196
|
-
token: string;
|
|
197
|
-
roles?: string[];
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
export type ValidateJWTTokenResponse = {
|
|
201
|
-
is_valid: boolean;
|
|
202
|
-
claims: Record<string, any>;
|
|
203
|
-
};
|