-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwooidc_client.js
More file actions
124 lines (86 loc) · 4.19 KB
/
Copy pathwooidc_client.js
File metadata and controls
124 lines (86 loc) · 4.19 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Wooidc = {};
//var selectedWONode;
// Request Web Observatory (Southampton) 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.
Wooidc.requestCredential = function (options, wonode, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
} else if (!options){
options = {};
}
var config = ServiceConfiguration.configurations.findOne({ service: 'wooidc' });
if (!config) {
credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError(new ServiceConfiguration.ConfigError()));
return;
}
//console.log("WO Configured domains: ",config);
var configDomains = config.config;
//console.log("Configured Domains and credentials are as below: ", configDomains);
//Reading the array of configured WO domains and comparing with the clicked domain for login.
var nodesList = ServiceConfiguration.configurations;
configDomains.forEach(function(doc) {
console.log("Printing each configured domain: ",doc.domain);
if(doc.domain == wonode){
//Aggregating Meteor login accounts data to get separate WO configured nodes with their respective domain names and credential details
/*var nodesList = ServiceConfiguration.configurations;
var pipeline = [
{$match :{service: "wooidc"}}, {$unwind: "$config"}, {$project: {_id: "$_id", service: "$service", domain: "$doc.domain",clientId: "$doc.clientId",secret: "$doc.secret"}}
];
nodesList.aggregate(pipeline, function(err, result) {
if(err) console.log(err);
console.log("Clicked configuration after aggregation is: ", result);
});*/
//Creating config again based on clicked web observatory node.
console.log("Clicked domain is: ", doc.domain);
config.domain = doc.domain;
config.clientId = doc.clientId;
config.secret = doc.secret;
config.loginStyle = true;
config = {_id: config._id, service: config.service, domain: doc.domain, clientId: doc.clientId, secret: doc.secret, loginStyle: config.loginStyle};
}
});
//console.log("Selected wo node configuration: ", config);
var credentialToken = Random.secret();
var loginStyle = OAuth._loginStyle('wooidc', config, options);
options = options || {};
options.response_type = options.response_type || 'code';
options.client_id = config.clientId;
options.redirect_uri = OAuth._redirectUri('wooidc', config);
//Checking the redirect URL
console.log("Redirect URI is: ", options.redirect_uri);
options.state = OAuth._stateParam(loginStyle, credentialToken, options && options.redirectUrl);
var scope = config.requestPermissions || ['openid', 'email'];
options.scope = scope.join(' ');
if (config.loginStyle && config.loginStyle == 'popup') {
options.display = 'popup';
}
var loginUrl = 'https://' + config.domain + '/oauth/authorise/'+ '?';
for (var k in options) {
loginUrl += '&' + encodeURIComponent(k) + '=' + encodeURIComponent(options[k]);
}
options.popupOptions = options.popupOptions || {};
var popupOptions = {
width: options.popupOptions.width || 900,
height: options.popupOptions.height || 450
};
Oauth.launchLogin({
loginService: 'wooidc',
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken,
popupOptions: popupOptions
});
selectedWONode = Meteor.call('selectedWOnode',wonode);
console.log("WO Node to be logged into is: ", selectedWONode);
/* Exports */
//if (typeof Package === "undefined") Package = {};
Package.wooidc = {
selectedWONode: selectedWONode
};
};
Meteor.subscribe('wooidcSessionState');