mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-12-04 01:33:08 +01:00
Merge pull request #2830 from nxglabs/staging Co-authored-by: nxglabs <nxglabs@users.noreply.github.com>
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import axios from 'axios';
|
|
import dotenv from 'dotenv';
|
|
dotenv.config({ quiet: true });
|
|
const getSsoApiUrl = () => {
|
|
return process.env.SSO_API_URL || 'https://sso.opensignlabs.com/api';
|
|
};
|
|
export const SSOAuth = {
|
|
// Returns a promise that fulfills if this user mail is valid.
|
|
validateAuthData: async authData => {
|
|
try {
|
|
const ssoApiUrl = getSsoApiUrl();
|
|
if (!ssoApiUrl) {
|
|
throw new Error('SSO is disabled for this deployment.');
|
|
}
|
|
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();
|
|
},
|
|
};
|