-
Notifications
You must be signed in to change notification settings - Fork 12
/
bluemix_client.js
47 lines (41 loc) · 1.77 KB
/
bluemix_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
Bluemix = {};
// Request Bluemix 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.
Bluemix.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'bluemix'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(
new ServiceConfiguration.ConfigError());
return;
}
var credentialToken = Random.secret();
var scope = (options && options.requestPermissions) || ['openid'];
//var scope = (options && options.requestPermissions) || ['profile'];
var flatScope = _.map(scope, encodeURIComponent).join('+');
var loginStyle = OAuth._loginStyle('bluemix', config, options);
var redirectUri = config.redirectUri || OAuth._redirectUri('bluemix', config);
console.log('redirectUri',redirectUri)
var url = config.loginUrl || 'https://login.eu-gb.bluemix.net/UAALoginServerWAR/oauth/authorize';
var loginUrl = url +
'?client_id=' + config.clientId +
'&scope=' + flatScope +
'&redirect_uri=' + redirectUri +
'&response_type=code' +
'&state=' + OAuth._stateParam(loginStyle, credentialToken);
OAuth.launchLogin({
loginService: "bluemix",
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken,
popupOptions: {width: 900, height: 450}
});
};