-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure_ad_client.js
59 lines (51 loc) · 1.82 KB
/
azure_ad_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Request AzureAd credentials for the user
// @param options {optional}
// @param credentialRequestCompleteCallback {Function} Callback function to call on
// completion. Takes one argument, credentialToken on success, or Error on
// error.
AzureAd.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
} else if (!options) {
options = {};
}
var config = AzureAd.getConfiguration(true);
if (!config) {
credentialRequestCompleteCallback &&
credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError());
return;
}
var prompt = '&prompt=login';
if (typeof options.loginPrompt === 'string') {
if (options.loginPrompt === '') prompt = '';
else prompt = '&prompt=' + options.loginPrompt;
}
var loginStyle = OAuth._loginStyle('azureAd', config, options);
var credentialToken = Random.secret();
var tenant = options.tenant || 'common';
var baseUrl = 'https://login.microsoftonline.com/' + tenant + '/oauth2/v2.0/authorize?';
var redirectUrl = encodeURIComponent(OAuth._redirectUri('azureAd', config, null, options));
var loginUrl =
baseUrl +
'response_type=code' +
prompt +
'&scope=' +
config.scope +
'&client_id=' +
config.clientId +
'&response_mode=query' +
'&state=' +
OAuth._stateParam(loginStyle, credentialToken, redirectUrl) +
'&redirect_uri=' +
redirectUrl;
OAuth.launchLogin({
loginService: 'azureAd',
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken,
popupOptions: { height: 600 },
});
};