cidaas-javascript-sdk 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/main/authentication/index.js +170 -146
- package/src/main/web-auth/webauth.js +5 -1
package/README.md
CHANGED
|
@@ -16,9 +16,9 @@ This cidaas Javascript SDK library is built on the top of [OIDC client javascrip
|
|
|
16
16
|
From CDN
|
|
17
17
|
|
|
18
18
|
```html
|
|
19
|
-
<!-- Release version 2.0.
|
|
19
|
+
<!-- Release version 2.0.7 -->
|
|
20
20
|
<!-- Minified version -->
|
|
21
|
-
<script src="https://cdn.cidaas.de/javascript/oidc/2.0.
|
|
21
|
+
<script src="https://cdn.cidaas.de/javascript/oidc/2.0.7/cidaas-javascript-sdk.min.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
From npm
|
package/package.json
CHANGED
|
@@ -4,186 +4,210 @@ function Authentication() {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// redirect sign in
|
|
7
|
-
Authentication.prototype.redirectSignIn = function
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
Authentication.prototype.redirectSignIn = function(view_type) {
|
|
8
|
+
try {
|
|
9
|
+
if (window.usermanager) {
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
if (window.webAuthSettings) {
|
|
12
|
+
if (!window.webAuthSettings.extraQueryParams) {
|
|
13
|
+
window.webAuthSettings.extraQueryParams = {};
|
|
14
|
+
}
|
|
15
|
+
window.webAuthSettings.extraQueryParams.view_type = view_type;
|
|
16
|
+
if (window.webAuthSettings.scope) {
|
|
17
|
+
if (window.webAuthSettings.response_type.indexOf("id_token") == -1 && window.webAuthSettings.scope.indexOf("openid") != -1 && !window.webAuthSettings.extraQueryParams.nonce) {
|
|
18
|
+
window.webAuthSettings.extraQueryParams.nonce = new Date().getTime().toString();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
window.webAuthSettings = {};
|
|
23
|
+
}
|
|
24
|
+
window.usermanager.signinRedirect({
|
|
25
|
+
extraQueryParams: window.webAuthSettings.extraQueryParams,
|
|
26
|
+
data: window.webAuthSettings
|
|
27
|
+
}).then(function() {
|
|
28
|
+
console.log("Redirect logged in using cidaas sdk");
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
throw "user manager is nil";
|
|
20
32
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
window.usermanager.signinRedirect({
|
|
25
|
-
extraQueryParams: window.webAuthSettings.extraQueryParams,
|
|
26
|
-
data: window.webAuthSettings
|
|
27
|
-
}).then(function () {
|
|
28
|
-
console.log("Redirect logged in using cidaas sdk");
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
throw "user manager is nil";
|
|
33
|
+
} catch (ex) {
|
|
34
|
+
console.log("user manager instance is empty : " + ex);
|
|
32
35
|
}
|
|
33
|
-
} catch (ex) {
|
|
34
|
-
console.log("user manager instance is empty : " + ex);
|
|
35
|
-
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
// redirect sign in callback
|
|
39
|
-
Authentication.prototype.redirectSignInCallback = function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
39
|
+
Authentication.prototype.redirectSignInCallback = function() {
|
|
40
|
+
return new Promise(function(resolve, reject) {
|
|
41
|
+
try {
|
|
42
|
+
if (window.usermanager) {
|
|
43
|
+
window.usermanager.signinRedirectCallback({
|
|
44
|
+
data: window.webAuthSettings
|
|
45
|
+
}).then(function(user) {
|
|
46
|
+
if (user) {
|
|
47
|
+
resolve(user);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolve(undefined);
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
throw "user manager is nil";
|
|
54
|
+
}
|
|
55
|
+
} catch (ex) {
|
|
56
|
+
reject(ex);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
// redirect sign out
|
|
62
|
-
Authentication.prototype.redirectSignOut = function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
Authentication.prototype.redirectSignOut = function() {
|
|
63
|
+
return new Promise(function(resolve, reject) {
|
|
64
|
+
try {
|
|
65
|
+
if (window.usermanager && window.webAuthSettings) {
|
|
66
|
+
window.usermanager.signoutRedirect({
|
|
67
|
+
state: window.webAuthSettings
|
|
68
|
+
}).then(function(resp) {
|
|
69
|
+
console.log('signed out', resp);
|
|
70
|
+
window.authentication.redirectSignOutCallback().then(function(resp) {
|
|
71
|
+
resolve(resp);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
throw "user manager or settings is nil";
|
|
76
|
+
}
|
|
77
|
+
} catch (ex) {
|
|
78
|
+
reject(ex);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
// redirect sign out callback
|
|
84
|
-
Authentication.prototype.redirectSignOutCallback = function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
Authentication.prototype.redirectSignOutCallback = function() {
|
|
85
|
+
return new Promise(function(resolve, reject) {
|
|
86
|
+
try {
|
|
87
|
+
if (window.usermanager) {
|
|
88
|
+
window.usermanager.signoutRedirectCallback().then(function(resp) {
|
|
89
|
+
console.log("Signed out");
|
|
90
|
+
resolve(resp);
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
resolve(undefined);
|
|
94
|
+
throw "user manager is nil";
|
|
95
|
+
}
|
|
96
|
+
} catch (ex) {}
|
|
97
|
+
});
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
// pop up sign in
|
|
101
|
-
Authentication.prototype.popupSignIn = function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
101
|
+
Authentication.prototype.popupSignIn = function() {
|
|
102
|
+
try {
|
|
103
|
+
if (window.usermanager && window.webAuthSettings) {
|
|
104
|
+
window.usermanager.signinPopup({
|
|
105
|
+
data: window.webAuthSettings
|
|
106
|
+
}).then(function() {
|
|
107
|
+
console.log("signed in");
|
|
108
|
+
// window.location = "/";
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
throw "user manager or settings is nil";
|
|
112
|
+
}
|
|
113
|
+
} catch (ex) {}
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
// pop up sign in callback
|
|
117
|
-
Authentication.prototype.popupSignInCallback = function
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
Authentication.prototype.popupSignInCallback = function() {
|
|
118
|
+
try {
|
|
119
|
+
if (window.usermanager) {
|
|
120
|
+
window.usermanager.signinPopupCallback();
|
|
121
|
+
}
|
|
122
|
+
} catch (ex) {}
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
// pop up sign out
|
|
126
|
-
Authentication.prototype.popupSignOut = function
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
126
|
+
Authentication.prototype.popupSignOut = function() {
|
|
127
|
+
try {
|
|
128
|
+
if (window.usermanager && window.webAuthSettings) {
|
|
129
|
+
window.usermanager.signoutPopup({
|
|
130
|
+
state: window.webAuthSettings
|
|
131
|
+
}).then(function(resp) {
|
|
132
|
+
console.log('signed out', resp);
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
throw "user manager or settings is nil";
|
|
136
|
+
}
|
|
137
|
+
} catch (ex) {}
|
|
138
138
|
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
// pop up sign out callback
|
|
142
|
-
Authentication.prototype.popupSignOutCallback = function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
Authentication.prototype.popupSignOutCallback = function() {
|
|
143
|
+
try {
|
|
144
|
+
if (window.usermanager) {
|
|
145
|
+
window.usermanager.signoutPopupCallback(true);
|
|
146
|
+
} else {
|
|
147
|
+
throw "user manager is nil";
|
|
148
|
+
}
|
|
149
|
+
} catch (ex) {}
|
|
150
150
|
};
|
|
151
151
|
|
|
152
152
|
// silent sign in
|
|
153
|
-
Authentication.prototype.silentSignIn = function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
153
|
+
Authentication.prototype.silentSignIn = function() {
|
|
154
|
+
try {
|
|
155
|
+
if (window.usermanager && window.webAuthSettings) {
|
|
156
|
+
window.usermanager.signinSilent({
|
|
157
|
+
state: window.webAuthSettings
|
|
158
|
+
}).then(function(user) {
|
|
159
|
+
console.log("signed in : " + user.access_token);
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
throw "user manager is nil";
|
|
163
|
+
}
|
|
164
|
+
} catch (ex) {}
|
|
165
165
|
};
|
|
166
166
|
|
|
167
167
|
// silent sign in callback
|
|
168
|
-
Authentication.prototype.silentSignInCallback = function
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
Authentication.prototype.silentSignInCallback = function() {
|
|
169
|
+
try {
|
|
170
|
+
if (window.usermanager) {
|
|
171
|
+
window.usermanager.signinSilentCallback();
|
|
172
|
+
} else {
|
|
173
|
+
throw "user manager is nil";
|
|
174
|
+
}
|
|
175
|
+
} catch (ex) {}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// silent sign in callback v2
|
|
179
|
+
Authentication.prototype.silentSignInCallbackV2 = function() {
|
|
180
|
+
return new Promise(function(resolve, reject) {
|
|
181
|
+
try {
|
|
182
|
+
if (window.usermanager) {
|
|
183
|
+
window.usermanager.signinSilentCallback({
|
|
184
|
+
data: window.webAuthSettings
|
|
185
|
+
}).then(function(user) {
|
|
186
|
+
if (user) {
|
|
187
|
+
resolve(user);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
resolve(undefined);
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
throw "user manager is nil";
|
|
194
|
+
}
|
|
195
|
+
} catch (ex) {
|
|
196
|
+
reject(ex);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
176
200
|
};
|
|
177
201
|
|
|
178
202
|
// silent sign out callback
|
|
179
|
-
Authentication.prototype.popupSignOutCallback = function
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
203
|
+
Authentication.prototype.popupSignOutCallback = function() {
|
|
204
|
+
try {
|
|
205
|
+
if (window.usermanager) {
|
|
206
|
+
window.usermanager.signoutPopupCallback(true);
|
|
207
|
+
} else {
|
|
208
|
+
throw "user manager is nil";
|
|
209
|
+
}
|
|
210
|
+
} catch (ex) {}
|
|
187
211
|
};
|
|
188
212
|
|
|
189
213
|
module.exports = Authentication;
|
|
@@ -83,7 +83,11 @@ WebAuth.prototype.loginCallback = function () {
|
|
|
83
83
|
} else if (window.webAuthSettings.mode == 'window') {
|
|
84
84
|
window.authentication.popupSignInCallback();
|
|
85
85
|
} else if (window.webAuthSettings.mode == 'silent') {
|
|
86
|
-
window.authentication.
|
|
86
|
+
window.authentication.silentSignInCallbackV2().then(function(data){
|
|
87
|
+
resolve(data);
|
|
88
|
+
}).catch(function(error){
|
|
89
|
+
reject(error);
|
|
90
|
+
})
|
|
87
91
|
}
|
|
88
92
|
} catch (ex) {
|
|
89
93
|
console.log(ex);
|