@@ -49,19 +49,30 @@ function processResponse(c) {
49
49
* if no credential is provided).
50
50
*/
51
51
document . querySelector ( '#signin' ) . addEventListener ( 'click' , function ( ) {
52
+ var formHTML = '' +
53
+ '<button>Sign in via Federation.com</button>' +
54
+ '<hr>' +
55
+ '<label for="username">Username:</label>' +
56
+ '<input id="username" type="text" name="username" autocomplete="username"></input>' +
57
+ '<label for="password">Password:</label>' +
58
+ '<input id="password" type="password" name="password" autocomplete="new-password"></input>' +
59
+ '<input type="submit">' ;
60
+
52
61
console . log ( "Clicked 'sign in!'" ) ;
53
62
if ( navigator . credentials ) {
54
63
navigator . credentials . get ( {
55
64
password : true
56
65
} ) . then ( function ( c ) {
57
66
processResponse ( c ) ;
58
67
if ( ! c ) {
59
- document . querySelector ( 'form' ) . innerHTML = '<label for="username">Username:</label><input id="username" type="text" name="username" autocomplete="username"></input><label for="password">Password:</label><input id="password" type="password" name="password" autocomplete="new-password"></input><input type="submit">' ;
68
+ document . querySelector ( 'form' ) . innerHTML = formHTML ;
69
+ document . querySelector ( 'form button' ) . addEventListener ( 'click' , handleFederation ) ;
60
70
document . querySelector ( 'dialog' ) . showModal ( ) ;
61
71
}
62
72
} ) ;
63
73
} else {
64
- document . querySelector ( 'form' ) . innerHTML = '<label for="username">Username:</label><input id="username" type="text" name="username" autocomplete="username"></input><label for="password">Password:</label><input id="password" type="password" name="password" autocomplete="new-password"></input><input type="submit">' ;
74
+ document . querySelector ( 'form' ) . innerHTML = formHTML ;
75
+ document . querySelector ( 'form button' ) . addEventListener ( 'click' , handleFederation ) ;
65
76
document . querySelector ( 'dialog' ) . showModal ( ) ;
66
77
}
67
78
} ) ;
@@ -77,6 +88,31 @@ document.querySelector('#signout').addEventListener('click', function () {
77
88
document . body . classList . toggle ( 'signedout' ) ;
78
89
} ) ;
79
90
91
+ /*
92
+ * Wire up the 'sign in via' button.
93
+ */
94
+ function handleFederation ( e ) {
95
+ console . log ( "Signed in via a federation!" ) ;
96
+ e . preventDefault ( ) ;
97
+
98
+ if ( navigator . credentials ) {
99
+ var c = new FederatedCredential ( {
100
+
101
+ provider : 'https://accounts.federation.com/' ,
102
+ iconURL :
getFace ( '[email protected] ' )
103
+ } ) ;
104
+ navigator . credentials . store ( c ) . then ( function ( a ) { console . log ( a ) ; } ) . catch ( function ( e ) { console . log ( e ) ; } ) ;
105
+ }
106
+
107
+ // Sign the user in asynchronously using the relevant SDK for the chosen federation.
108
+
109
+ toggleState ( ) ;
110
+ document . querySelector ( 'var' ) . textContent = '[email protected] ' ;
111
+ document . querySelector ( 'dialog' ) . close ( ) ;
112
+
113
+ return false ;
114
+ }
115
+
80
116
/*
81
117
* Finally, we'll wire up the submit button on the form to call `store()` upon
82
118
* submission if the API is available.
0 commit comments