forked from djluck/azure-active-directory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure_ad_client.js
executable file
·50 lines (45 loc) · 1.81 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
// 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 baseUrl = "https://login.windows.net/common/oauth2/authorize?";
var loginUrl = baseUrl +
'api-version=1.0&' +
'&response_type=code' +
prompt +
'&client_id=' + config.clientId +
'&state=' + OAuth._stateParam(loginStyle, credentialToken) +
'&redirect_uri=' + OAuth._redirectUri('azureAd', config);
OAuth.launchLogin({
loginService: "azureAd",
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken,
popupOptions: { height: 600 }
});
};