Adds validation for id_token and access_token (#2878)
* ADds validation for id_token and access_token * nit
This commit is contained in:
@@ -2,11 +2,10 @@
|
|||||||
var https = require('https');
|
var https = require('https');
|
||||||
var Parse = require('parse/node').Parse;
|
var Parse = require('parse/node').Parse;
|
||||||
|
|
||||||
// Returns a promise that fulfills iff this user id is valid.
|
function validateIdToken(id, token) {
|
||||||
function validateAuthData(authData) {
|
return request("tokeninfo?id_token="+token)
|
||||||
return request("tokeninfo?id_token="+authData.access_token)
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response && response.sub == authData.id) {
|
if (response && response.sub == id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Parse.Error(
|
throw new Parse.Error(
|
||||||
@@ -15,7 +14,34 @@ function validateAuthData(authData) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a promise that fulfills iff this app id is valid.
|
function validateAuthToken(id, token) {
|
||||||
|
return request("tokeninfo?access_token="+token)
|
||||||
|
.then((response) => {
|
||||||
|
if (response && response.user_id == id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new Parse.Error(
|
||||||
|
Parse.Error.OBJECT_NOT_FOUND,
|
||||||
|
'Google auth is invalid for this user.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a promise that fulfills if this user id is valid.
|
||||||
|
function validateAuthData(authData) {
|
||||||
|
if (authData.id_token) {
|
||||||
|
return validateIdToken(authData.id, authData.id_token);
|
||||||
|
} else {
|
||||||
|
return validateAuthToken(authData.id, authData.access_token).then(() => {
|
||||||
|
// Validation with auth token worked
|
||||||
|
return;
|
||||||
|
}, () => {
|
||||||
|
// Try with the id_token param
|
||||||
|
return validateIdToken(authData.id, authData.access_token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a promise that fulfills if this app id is valid.
|
||||||
function validateAppId() {
|
function validateAppId() {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user