Skip to content

Commit da7dc05

Browse files
committed
add checkbox to follow links
1 parent 82b2dd9 commit da7dc05

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

sample/public/app.js

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ document.getElementById('signin').addEventListener("click", signin, false);
55
document.getElementById('processSignin').addEventListener("click", processSigninResponse, false);
66
document.getElementById('signout').addEventListener("click", signout, false);
77
document.getElementById('processSignout').addEventListener("click", processSignoutResponse, false);
8+
document.getElementById('links').addEventListener('change', toggleLinks, false);
89

910
///////////////////////////////
1011
// OidcClient config
@@ -30,8 +31,10 @@ var oidcClient = new IdentityModel.OidcClient(settings);
3031
///////////////////////////////
3132
function signin() {
3233
oidcClient.createSigninRequest({data:{bar:15}}).then(function(req){
33-
log(req);
34-
window.location = req.url;
34+
log("signin request", req, "<a href='" + req.url + "'>go signin</a>");
35+
if (followLinks()){
36+
window.location = req.url;
37+
}
3538
}, function (err) {
3639
log(err);
3740
});
@@ -41,28 +44,59 @@ var signinResponse;
4144
function processSigninResponse() {
4245
oidcClient.processSigninResponse().then(function(response){
4346
signinResponse = response;
44-
log(signinResponse);
47+
log("signin response", signinResponse);
4548
}, function (err) {
4649
log(err.message);
4750
});
4851
}
4952

5053
function signout() {
5154
oidcClient.createSignoutRequest({id_token_hint:signinResponse && signinResponse.id_token, data:{foo:5}}).then(function(req){
52-
window.location = req.url;
53-
//log(req);
55+
log("signout request", req, "<a href='" + req.url + "'>go signout</a>");
56+
if (followLinks()){
57+
window.location = req.url;
58+
}
5459
});
5560
}
5661

5762
function processSignoutResponse() {
5863
oidcClient.processSignoutResponse().then(function(response){
5964
signinResponse = null;
60-
log(response);
65+
log("signout response", response);
6166
}, function (err) {
6267
log(err.message);
6368
});
6469
}
6570

71+
function toggleLinks(){
72+
var val = document.getElementById('links').checked;
73+
localStorage.setItem("follow", val);
74+
75+
var display = val ? 'none' : '';
76+
77+
document.getElementById('processSignin').style.display = display;
78+
document.getElementById('processSignout').style.display = display;
79+
}
80+
81+
function followLinks() {
82+
return localStorage.getItem("follow") === "true";
83+
}
84+
85+
var follow = followLinks();
86+
var display = follow ? 'none' : '';
87+
document.getElementById('links').checked = follow;
88+
document.getElementById('processSignin').style.display = display;
89+
document.getElementById('processSignout').style.display = display;
90+
91+
if (followLinks()){
92+
if (window.location.href.indexOf("#") >= 0){
93+
processSigninResponse();
94+
}
95+
else if (window.location.href.indexOf("?") >= 0){
96+
processSignoutResponse();
97+
}
98+
}
99+
66100
///////////////////////////////
67101
// debugging helpers
68102
///////////////////////////////
@@ -74,7 +108,7 @@ function log() {
74108
if (typeof msg !== 'string') {
75109
msg = JSON.stringify(msg, null, 2);
76110
}
77-
document.getElementById('out').innerText += msg + '\r\n';
111+
document.getElementById('out').innerHTML += msg + '\r\n';
78112

79113
});
80114
}

sample/public/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<body>
88
<div>
99
<a href='index.html'>clear url</a>
10+
<label>follow links
11+
<input type="checkbox" id='links'>
12+
</label>
1013
<button id='signin'>signin</button>
1114
<button id='processSignin'>process signin response</button>
1215
<button id='signout'>signout</button>

0 commit comments

Comments
 (0)