@@ -5,6 +5,7 @@ document.getElementById('signin').addEventListener("click", signin, false);
55document . getElementById ( 'processSignin' ) . addEventListener ( "click" , processSigninResponse , false ) ;
66document . getElementById ( 'signout' ) . addEventListener ( "click" , signout , false ) ;
77document . 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///////////////////////////////
3132function 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;
4144function 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
5053function 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
5762function 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}
0 commit comments