@@ -14,6 +14,10 @@ const LOGGED_IN = 'loggedIn'
1414const LOGIN_SESSION_TIMEOUT = "login_session_timeout"
1515const AUTH_RESOURCE = 'auth_resource'
1616
17+ const BASIC_AUTH_SCHEME = "Basic"
18+ const BEARER_AUTH_SCHEME = "Bearer"
19+
20+
1721function set_auth_resource ( resource ) {
1822 store_local_pref ( AUTH_RESOURCE , resource )
1923}
@@ -24,9 +28,11 @@ function get_auth_resource() {
2428 return get_local_pref ( AUTH_RESOURCE )
2529}
2630
27- function has_auth_credentials ( ) {
28- return get_local_pref ( CREDENTIALS ) != undefined && get_local_pref ( AUTH_SCHEME ) != undefined &&
29- get_cookie_value ( LOGGED_IN ) != undefined
31+ function has_auth_credentials ( auth_scheme ) {
32+ let authenticated = get_local_pref ( CREDENTIALS ) != undefined && get_local_pref ( AUTH_SCHEME ) != undefined &&
33+ get_cookie_value ( LOGGED_IN ) != undefined ;
34+ return authenticated && ( auth_scheme == undefined
35+ || auth_scheme == get_auth_scheme ( ) ) ;
3036}
3137function get_auth_credentials ( ) {
3238 return get_local_pref ( CREDENTIALS )
@@ -54,6 +60,7 @@ function set_auth(auth_scheme, credentials, validUntil) {
5460 store_local_pref ( AUTH_SCHEME , auth_scheme )
5561 store_cookie_value_with_expiration ( LOGGED_IN , "true" , validUntil ) // session marker
5662}
63+
5764function authorization_header ( ) {
5865 if ( has_auth_credentials ( ) ) {
5966 return get_auth_scheme ( ) + ' ' + get_auth_credentials ( ) ;
0 commit comments