Microsoft Graph Authentication (#6051)

* add microsoft graph auth

* change mail to id

* add graph user id and email

* add microsoft graph auth test case

* remove validating auth data using mail

* add test case to AuthenticationAdapters

* fix indentation

* fix httpsRequest and fakeClaim not found

* add newline eof last

* fix test in auth adapter

* fix unhandled promise rejection
This commit is contained in:
Alann Maulana
2019-09-27 01:23:18 +07:00
committed by Diamond Lewis
parent dd08786a53
commit 38e0ff9d76
4 changed files with 76 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ const wechat = require('./wechat');
const weibo = require('./weibo');
const oauth2 = require('./oauth2');
const phantauth = require('./phantauth');
const microsoft = require('./microsoft');
const anonymous = {
validateAuthData: () => {
@@ -51,6 +52,7 @@ const providers = {
wechat,
weibo,
phantauth,
microsoft,
};
function authDataValidator(adapter, appIds, options) {

View File

@@ -0,0 +1,39 @@
// Helper functions for accessing the microsoft graph API.
var Parse = require('parse/node').Parse;
const httpsRequest = require('./httpsRequest');
// Returns a promise that fulfills if this user mail is valid.
function validateAuthData(authData) {
return request('me', authData.access_token).then(
response => {
if (response && response.id && response.id == authData.id) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Microsoft Graph auth is invalid for this user.'
);
}
);
}
// Returns a promise that fulfills if this app id is valid.
function validateAppId() {
return Promise.resolve();
}
// A promisey wrapper for api requests
function request(path, access_token) {
return httpsRequest.get({
host: 'graph.microsoft.com',
path: '/v1.0/' + path,
headers: {
Authorization: 'Bearer ' + access_token,
},
});
}
module.exports = {
validateAppId: validateAppId,
validateAuthData: validateAuthData,
};