forked from emgee3/meteor-ad-sso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadsso-client.js
52 lines (42 loc) · 1.09 KB
/
adsso-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
SSO = {};
var authId = Meteor.uuid();
var timesRefreshed = new ReactiveVar();
Template.adsso.helpers ({
authQueryString : function () {
// Build the URL for the iframe
var env = __meteor_runtime_config__.ROOT_URL;
var isProd = env.indexOf('localhost') === -1 && env.indexOf('127.0') === -1;
return (isProd ? SSO.authUrl + SSO.authApp : SSO.devAuthUrl + SSO.devAuthApp)
+ "/" + authId;
}
});
Template.adsso.rendered = function () {
timesRefreshed.set(0);
$("iframe").load(function(){
timesRefreshed.set(timesRefreshed.get() + 1);
});
};
Tracker.autorun(function () {
if (Meteor.user()) return;
if (timesRefreshed.get() > 0) {
SSO.login();
}
});
SSO.login = function () {
Accounts.callLoginMethod({
methodArguments: [
{ authId : authId }
],
userCallback : function (err, res) {
if (err) {
if (typeof SSO.onError === "function") {
SSO.onError(err);
} else {
console.error(err);
}
} else {
if (typeof SSO.onSuccess === "function") SSO.onSuccess(res);
}
}
});
}