forked from lindoelio/meteor-office365-oauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
office365_client.js
36 lines (27 loc) · 1.39 KB
/
office365_client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*globals Office365, OAuth */
Office365 = {};
Office365.requestCredential = function(options, credentialRequestCompleteCallback) {
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
const config = ServiceConfiguration.configurations.findOne({service: 'office365'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError());
return;
}
const credentialToken = Random.secret();
const scope = (options && options.requestPermissions) || ['offline_access', 'user.read'];
const flatScope = _.map(scope, encodeURIComponent).join('+');
const loginStyle = OAuth._loginStyle('office365', config, options);
// The Microsoft Office 365 Application not allow the parameter "close" at redirect URLs
const redirectUri = OAuth._redirectUri('office365', config).replace('?close', '');
const loginUrl = `https://login.microsoftonline.com/${ config.tenant || 'common' }/oauth2/v2.0/authorize?client_id=${ config.clientId }&response_type=code&redirect_uri=${ redirectUri }&response_mode=query&scope=${ flatScope }&state=${ OAuth._stateParam(loginStyle, credentialToken, redirectUri) }`;
OAuth.launchLogin({
loginService: 'office365',
loginStyle,
loginUrl,
credentialRequestCompleteCallback,
credentialToken
});
};