-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
dd08786
commit 38e0ff9
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const microsoft = require('../lib/Adapters/Auth/microsoft'); | ||
|
||
describe('Microsoft Auth', () => { | ||
it('should fail to validate Microsoft Graph auth with bad token', done => { | ||
const authData = { | ||
id: 'fake-id', | ||
mail: 'fake@mail.com', | ||
access_token: 'very.long.bad.token', | ||
}; | ||
microsoft.validateAuthData(authData).then(done.fail, err => { | ||
expect(err.code).toBe(101); | ||
expect(err.message).toBe( | ||
'Microsoft Graph auth is invalid for this user.' | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |