@@ -12,7 +12,12 @@ window.fetch = async (...args) => {
1212 window . fetch = originalFetch ;
1313
1414 const responseBody = await response . clone ( ) . json ( ) ;
15- console . log ( 'Response from /auth/login_flow:' , responseBody ) ;
15+
16+ if ( responseBody . block_login ) {
17+ console . info ( 'Home Assistant login methods are blocked by hass-openid. Redirecting to OpenID login.' ) ;
18+ redirect_openid_login ( ) ;
19+ return response ;
20+ }
1621
1722 const authFlow = document . getElementsByClassName ( 'card-content' ) [ 0 ] ;
1823
@@ -21,15 +26,7 @@ window.fetch = async (...args) => {
2126 listItemNode . setAttribute ( 'hasmeta' , '' ) ;
2227 listItemNode . setAttribute ( 'mwc-list-item' , '' ) ;
2328 listItemNode . innerHTML = 'OpenID / OAuth2 Authentication <ha-icon-next slot="meta"></ha-icon-next>' ;
24- listItemNode . onclick = ( ) => {
25- const urlParams = new URLSearchParams ( window . location . search ) ;
26- const clientId = encodeURIComponent ( urlParams . get ( 'client_id' ) ) ;
27- const redirectUri = encodeURIComponent ( urlParams . get ( 'redirect_uri' ) ) ;
28- const baseUrl = window . location . origin ;
29-
30- const encodedUrl = encodeURIComponent ( `/auth/openid/authorize?client_id=${ clientId } &redirect_uri=${ redirectUri } &base_url=${ baseUrl } ` ) ;
31- window . location . href = decodeURIComponent ( encodedUrl ) ;
32- } ;
29+ listItemNode . onclick = redirect_openid_login ;
3330
3431 listNode . appendChild ( listItemNode ) ;
3532 authFlow . append ( listNode ) ;
@@ -48,3 +45,13 @@ window.fetch = async (...args) => {
4845
4946 return response ;
5047} ;
48+
49+ function redirect_openid_login ( ) {
50+ const urlParams = new URLSearchParams ( window . location . search ) ;
51+ const clientId = encodeURIComponent ( urlParams . get ( 'client_id' ) ) ;
52+ const redirectUri = encodeURIComponent ( urlParams . get ( 'redirect_uri' ) ) ;
53+ const baseUrl = window . location . origin ;
54+
55+ const encodedUrl = encodeURIComponent ( `/auth/openid/authorize?client_id=${ clientId } &redirect_uri=${ redirectUri } &base_url=${ baseUrl } ` ) ;
56+ window . location . href = decodeURIComponent ( encodedUrl ) ;
57+ }
0 commit comments