@@ -32,6 +32,8 @@ export function main() {
3232 if ( checkBrowser ( null , null ) ) {
3333 initWindowManager ( ) ;
3434
35+ __oauthInit ( ) ;
36+
3537 // Radio is a string container
3638 tools . radio . clickValue ( "expire-radio" , tools . storage . get ( "login.expire" , 0 ) ) ;
3739 tools . radio . setOnClick ( "expire-radio" , function ( ) {
@@ -51,6 +53,71 @@ export function main() {
5153 }
5254}
5355
56+ function __oauthInit ( ) {
57+ // tools.httpRequest("GET", "/api/auth/flow/oauth/check", null, function(http) {
58+ // if (http.status === 200) {
59+ // // add overall plugin health check (perhaps flesh out the /check endpoint itself first)
60+ // }}
61+ // })
62+
63+ tools . httpRequest ( "GET" , "/api/auth/flow/oauth/providers" , null , function ( http ) {
64+ if ( http . status === 200 ) {
65+ let oauthInfo = JSON . parse ( http . responseText ) . result ;
66+ if ( ! oauthInfo . enabled ) {
67+ return ;
68+ }
69+ if ( Object . entries ( oauthInfo . providers ) . length === 0 ) {
70+ // perhaps also draw a "fake button" (inactive + greyed-out) to indicate we have no providers available
71+ return ;
72+ }
73+
74+ let buttons = ( `
75+ <tr>
76+ <td colspan="2">
77+ <hr>
78+ </td>
79+ </tr>
80+ ` ) ;
81+ const buttonIds = [ ] ;
82+
83+ for ( const [ shortName , longName ] of Object . entries ( oauthInfo . providers ) ) {
84+ const { html, buttonId } = __oauthButton ( shortName , longName ) ;
85+ // if (oauthInfo.default === shortName) {
86+ // $(buttonId).classList.add("default");
87+ // } else {
88+ // $(buttonId).classList.add("secondary");
89+ // }
90+ buttons += html ;
91+ buttonIds . push ( { shortName, buttonId } ) ;
92+ }
93+ $ ( "oauth-tbody" ) . innerHTML = buttons ;
94+ for ( const { shortName, buttonId } of buttonIds ) {
95+ tools . el . setOnClick ( $ ( buttonId ) , ( ) => __oauthLogin ( shortName ) ) ;
96+ }
97+ }
98+ // else {
99+ // // add error handling, draw an error "fake button" (like inactive + red-tinted) in place of the oauth buttons
100+ // }
101+ } )
102+ }
103+
104+ function __oauthButton ( shortName , longName ) {
105+ const html = ( `
106+ <tr>
107+ <td></td>
108+ <td>
109+ <button class="key login-button-secondary" id="oauth-button-${ shortName } ">Login with ${ longName } </button>
110+ </td>
111+ </tr>
112+ ` ) ;
113+ const buttonId = `oauth-button-${ shortName } ` ;
114+ return { html, buttonId } ;
115+ }
116+
117+ function __oauthLogin ( shortName ) {
118+ tools . currentOpen ( `/api/auth/flow/oauth/login/${ shortName } ` ) ;
119+ }
120+
54121function __login ( ) {
55122 let e_user = encodeURIComponent ( $ ( "user-input" ) . value ) ;
56123 if ( e_user . length === 0 ) {
0 commit comments