mirror of
https://github.com/parse-community/parse-server
synced 2026-08-09 13:03:18 +00:00
fix: Parse.Query.select('authData') for _User class doesn't return auth data (#10055)
This commit is contained in:
@@ -1395,6 +1395,19 @@ describe('Parse.User testing', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return authData when select authData with masterKey', async () => {
|
||||
const provider = getMockFacebookProvider();
|
||||
Parse.User._registerAuthenticationProvider(provider);
|
||||
const user = await Parse.User._logInWith('facebook');
|
||||
const query = new Parse.Query(Parse.User);
|
||||
query.select('authData');
|
||||
const result = await query.get(user.id, { useMasterKey: true });
|
||||
expect(result.get('authData')).toBeDefined();
|
||||
expect(result.get('authData').facebook).toBeDefined();
|
||||
expect(result.get('authData').facebook.id).toBe('8675309');
|
||||
expect(result.get('authData').facebook.access_token).toBe('jenny');
|
||||
});
|
||||
|
||||
it('only creates a single session for an installation / user pair (#2885)', async done => {
|
||||
Parse.Object.disableSingleInstance();
|
||||
const provider = getMockFacebookProvider();
|
||||
|
||||
@@ -254,8 +254,25 @@ module.exports = function (authOptions = {}, enableAnonymousUsers = true) {
|
||||
);
|
||||
};
|
||||
|
||||
// Returns the list of auth provider names that have a valid adapter configured.
|
||||
// This includes both built-in providers and custom providers from authOptions.
|
||||
const getProviders = function () {
|
||||
const allProviders = new Set([...Object.keys(providers), ...Object.keys(authOptions)]);
|
||||
if (!_enableAnonymousUsers) {
|
||||
allProviders.delete('anonymous');
|
||||
}
|
||||
return [...allProviders].filter(provider => {
|
||||
try {
|
||||
return !!loadAuthAdapter(provider, authOptions);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Object.freeze({
|
||||
getValidatorForProvider,
|
||||
getProviders,
|
||||
setEnableAnonymousUsers,
|
||||
runAfterFind,
|
||||
});
|
||||
|
||||
@@ -751,6 +751,26 @@ _UnsafeRestQuery.prototype.runFind = async function (options = {}) {
|
||||
findOptions.keys = this.keys.map(key => {
|
||||
return key.split('.')[0];
|
||||
});
|
||||
// When selecting `authData` on `_User`, also add the internal auth data fields
|
||||
// (e.g. `_auth_data_facebook`) for each configured auth provider. In MongoDB,
|
||||
// `authData` is stored as individual `_auth_data_<provider>` fields, so the
|
||||
// projection for `authData` alone won't match them. Adding both ensures it
|
||||
// works across all database adapters: Mongo uses `_auth_data_*` fields,
|
||||
// Postgres uses the `authData` column directly.
|
||||
//
|
||||
// Note: When selecting `authData`, only auth data of currently configured
|
||||
// providers is returned. Auth data entries of providers that are no longer
|
||||
// configured won't be included. To return all auth data regardless of the
|
||||
// provider configuration, do not use `authData` as a selected key.
|
||||
if (this.className === '_User' && findOptions.keys.includes('authData')) {
|
||||
const providers = this.config.authDataManager.getProviders();
|
||||
for (const provider of providers) {
|
||||
const key = `_auth_data_${provider}`;
|
||||
if (!findOptions.keys.includes(key)) {
|
||||
findOptions.keys.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options.op) {
|
||||
findOptions.op = options.op;
|
||||
|
||||
Reference in New Issue
Block a user