-
Notifications
You must be signed in to change notification settings - Fork 678
Expand file tree
/
Copy pathauthadapter.js
More file actions
32 lines (31 loc) · 1.07 KB
/
authadapter.js
File metadata and controls
32 lines (31 loc) · 1.07 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
import axios from 'axios';
import dotenv from 'dotenv';
dotenv.config();
const ssoApiUrl = process.env.SSO_API_URL || 'https://sso.opensignlabs.com/api'; //'https://osl-jacksonv2.vercel.app/api';
export const SSOAuth = {
// Returns a promise that fulfills if this user mail is valid.
validateAuthData: async authData => {
try {
const response = await axios.get(ssoApiUrl + '/oauth/userinfo', {
headers: {
Authorization: `Bearer ${authData.access_token}`,
},
});
if (
response.data &&
response.data.id &&
response.data.email?.toLowerCase()?.replace(/\s/g, '') === authData.id
) {
return;
}
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'SSO auth is invalid for this user.');
} catch (error) {
console.log('error in sso adapter', error?.response);
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'SSO auth is invalid for this user.');
}
},
// Returns a promise that fulfills if this app id is valid.
validateAppId: () => {
return Promise.resolve();
},
};