Skip authData validation if it hasn't changed. (#3783)

* Adds test for the new feature

* Re-validate authData only if mutated

- In case of short-lived tokens (like facebook) this will allow clients to be lax with asking users to re-login
This commit is contained in:
Florent Vilmart
2017-05-07 12:55:30 -04:00
committed by GitHub
parent 4f903952bf
commit 45a9d50110
3 changed files with 64 additions and 10 deletions

View File

@@ -277,9 +277,7 @@ RestWrite.prototype.findUsersWithAuthData = function(authData) {
RestWrite.prototype.handleAuthData = function(authData) {
let results;
return this.handleAuthDataValidation(authData).then(() => {
return this.findUsersWithAuthData(authData);
}).then((r) => {
return this.findUsersWithAuthData(authData).then((r) => {
results = r;
if (results.length > 1) {
// More than 1 user with the passed id's
@@ -307,16 +305,20 @@ RestWrite.prototype.handleAuthData = function(authData) {
mutatedAuthData[provider] = providerData;
}
});
this.response = {
response: userResult,
location: this.location()
};
// If we didn't change the auth data, just keep going
if (Object.keys(mutatedAuthData).length === 0) {
return;
}
// We have authData that is updated on login
// that can happen when token are refreshed,
// We should update the token and let the user in
if (Object.keys(mutatedAuthData).length > 0) {
// We should only check the mutated keys
return this.handleAuthDataValidation(mutatedAuthData).then(() => {
// Assign the new authData in the response
Object.keys(mutatedAuthData).forEach((provider) => {
this.response.response.authData[provider] = mutatedAuthData[provider];
@@ -324,9 +326,7 @@ RestWrite.prototype.handleAuthData = function(authData) {
// Run the DB update directly, as 'master'
// Just update the authData part
return this.config.database.update(this.className, {objectId: this.data.objectId}, {authData: mutatedAuthData}, {});
}
return;
});
} else if (this.query && this.query.objectId) {
// Trying to update auth data but users
// are different
@@ -336,7 +336,7 @@ RestWrite.prototype.handleAuthData = function(authData) {
}
}
}
return;
return this.handleAuthDataValidation(authData);
});
}