MCPcopy Index your code
hub / github.com/parse-community/parse-server / authDataValidator

Function authDataValidator

src/Adapters/Auth/index.js:76–143  ·  view source on GitHub ↗
(provider, adapter, appIds, options)

Source from the content-addressed store, hash-verified

74};
75
76function authDataValidator(provider, adapter, appIds, options) {
77 return async function (authData, req, user, requestObject) {
78 if (appIds && typeof adapter.validateAppId === 'function') {
79 await Promise.resolve(adapter.validateAppId(appIds, authData, options, requestObject));
80 }
81 if (
82 adapter.policy &&
83 !authAdapterPolicies[adapter.policy] &&
84 typeof adapter.policy !== 'function'
85 ) {
86 throw new Parse.Error(
87 Parse.Error.OTHER_CAUSE,
88 'AuthAdapter policy is not configured correctly. The value must be either "solo", "additional", "default" or undefined (will be handled as "default")'
89 );
90 }
91 if (typeof adapter.validateAuthData === 'function') {
92 return adapter.validateAuthData(authData, options, requestObject);
93 }
94 if (
95 typeof adapter.validateSetUp !== 'function' ||
96 typeof adapter.validateLogin !== 'function' ||
97 typeof adapter.validateUpdate !== 'function'
98 ) {
99 throw new Parse.Error(
100 Parse.Error.OTHER_CAUSE,
101 'Adapter is not configured. Implement either validateAuthData or all of the following: validateSetUp, validateLogin and validateUpdate'
102 );
103 }
104 // When masterKey is detected, we should trigger a logged in user
105 const isLoggedIn =
106 (req.auth.user && user && req.auth.user.id === user.id) || (user && req.auth.isMaster);
107 let hasAuthDataConfigured = false;
108
109 if (user && user.get('authData') && user.get('authData')[provider]) {
110 hasAuthDataConfigured = true;
111 }
112
113 if (isLoggedIn) {
114 // User is updating their authData
115 if (hasAuthDataConfigured) {
116 return {
117 method: 'validateUpdate',
118 validator: () => adapter.validateUpdate(authData, options, requestObject),
119 };
120 }
121 // Set up if the user does not have the provider configured
122 return {
123 method: 'validateSetUp',
124 validator: () => adapter.validateSetUp(authData, options, requestObject),
125 };
126 }
127
128 // Not logged in and authData is configured on the user
129 if (hasAuthDataConfigured) {
130 return {
131 method: 'validateLogin',
132 validator: () => adapter.validateLogin(authData, options, requestObject),
133 };

Callers 1

getValidatorForProviderFunction · 0.85

Calls 6

validateAppIdMethod · 0.45
validateAuthDataMethod · 0.45
getMethod · 0.45
validateUpdateMethod · 0.45
validateSetUpMethod · 0.45
validateLoginMethod · 0.45

Tested by

no test coverage detected