-
Notifications
You must be signed in to change notification settings - Fork 10
/
auth0_client.js
53 lines (40 loc) · 1.58 KB
/
auth0_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
Auth0 = {};
// Request 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.
Auth0.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config = ServiceConfiguration.configurations.findOne({ service: 'auth0' });
if (!config) {
credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError('Service not configured.'));
return;
}
options = options || {};
options.response_type = options.response_type || 'code';
options.client_id = config.clientId;
options.redirect_uri = (function(baseUrl) {
var suffix = '_oauth/auth0?close';
if (baseUrl) {
var separator = baseUrl.slice(-1) === '/' ? '' : '/';
return baseUrl + separator + suffix;
} else {
return Meteor.absoluteUrl(suffix);
}
})(config.baseUrl);
options.state = Random.id();
var loginUrl = 'https://' + config.domain + '/authorize?';
for (var k in options) {
loginUrl += '&' + k + '=' + options[k];
}
options.popupOptions = options.popupOptions || {};
var popupOptions = {
width: options.popupOptions.width || 320,
height: options.popupOptions.height || 450
};
Oauth.initiateLogin(options.state, loginUrl, credentialRequestCompleteCallback, popupOptions);
};