2024-06-19 23:04:29 +08:00
|
|
|
import {oidc} from './oidc-client-ts.js';
|
2022-05-05 21:08:48 +08:00
|
|
|
|
|
|
|
var mgr;
|
2022-09-01 20:53:42 +08:00
|
|
|
var _management_logger;
|
2022-05-05 21:08:48 +08:00
|
|
|
|
2022-10-04 22:43:18 +08:00
|
|
|
|
2023-03-31 15:51:22 +08:00
|
|
|
function rabbit_base_uri() {
|
2023-05-18 23:17:11 +08:00
|
|
|
return window.location.protocol + "//" + window.location.hostname + rabbit_port() + rabbit_path_prefix()
|
|
|
|
}
|
|
|
|
function rabbit_path_prefix() {
|
|
|
|
return window.location.pathname.replace(/(\/js\/oidc-oauth\/.*$|\/+$)/, "");
|
|
|
|
}
|
|
|
|
function rabbit_port() {
|
|
|
|
return window.location.port ? ":" + window.location.port : "";
|
2023-03-31 15:51:22 +08:00
|
|
|
}
|
2024-01-03 16:28:36 +08:00
|
|
|
function readiness_url(resource_server) {
|
2024-01-18 22:16:26 +08:00
|
|
|
if (!resource_server.oauth_metadata_url) {
|
|
|
|
return resource_server.oauth_provider_url + "/.well-known/openid-configuration"
|
2024-01-03 16:28:36 +08:00
|
|
|
}else {
|
2024-01-18 22:16:26 +08:00
|
|
|
return resource_server.oauth_metadata_url
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
|
|
|
}
|
2022-05-10 22:22:04 +08:00
|
|
|
|
2024-01-03 16:28:36 +08:00
|
|
|
function auth_settings_apply_defaults(authSettings) {
|
|
|
|
if (authSettings.oauth_provider_url) {
|
|
|
|
if (!authSettings.oauth_response_type) {
|
|
|
|
authSettings.oauth_response_type = "code"; // although the default value in oidc client
|
|
|
|
}
|
|
|
|
if (!authSettings.oauth_scopes) {
|
|
|
|
authSettings.oauth_scopes = "openid profile";
|
|
|
|
}
|
|
|
|
if (!authSettings.oauth_initiated_logon_type) {
|
|
|
|
authSettings.oauth_initiated_logon_type = "sp_initiated"
|
|
|
|
}
|
2022-05-10 22:22:04 +08:00
|
|
|
}
|
2024-01-03 16:28:36 +08:00
|
|
|
authSettings.resource_servers = []
|
|
|
|
|
2024-01-23 00:53:01 +08:00
|
|
|
if (authSettings.oauth_resource_servers) {
|
2024-01-03 16:28:36 +08:00
|
|
|
|
|
|
|
for (const [resource_server_id, resource_server] of Object.entries(authSettings.oauth_resource_servers)) {
|
2024-01-18 22:16:26 +08:00
|
|
|
if (!resource_server.oauth_provider_url) {
|
|
|
|
resource_server.oauth_provider_url = authSettings.oauth_provider_url
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (!resource_server.oauth_provider_url) {
|
2024-01-03 16:28:36 +08:00
|
|
|
break
|
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (!resource_server.oauth_response_type) {
|
|
|
|
resource_server.oauth_response_type = authSettings.oauth_response_type
|
|
|
|
if (!resource_server.oauth_response_type) {
|
|
|
|
resource_server.oauth_response_type = "code"
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (!resource_server.oauth_scopes) {
|
|
|
|
resource_server.oauth_scopes = authSettings.oauth_scopes
|
|
|
|
if (!resource_server.oauth_scopes) {
|
|
|
|
resource_server.oauth_scopes = "openid profile"
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (!resource_server.oauth_client_id) {
|
|
|
|
resource_server.oauth_client_id = authSettings.oauth_client_id
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
2024-01-19 17:59:58 +08:00
|
|
|
if (!resource_server.oauth_client_secret && resource_server.oauth_client_id
|
|
|
|
&& authSettings.oauth_client_secret) {
|
2024-01-18 22:16:26 +08:00
|
|
|
resource_server.oauth_client_secret = authSettings.oauth_client_secret
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
2024-01-22 19:47:08 +08:00
|
|
|
if (!resource_server.oauth_initiated_logon_type) {
|
|
|
|
if (authSettings.oauth_initiated_logon_type) {
|
|
|
|
resource_server.oauth_initiated_logon_type = authSettings.oauth_initiated_logon_type
|
|
|
|
}else {
|
|
|
|
resource_server.oauth_initiated_logon_type = "sp_initiated"
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (resource_server.oauth_initiated_logon_type == "idp_initiated") {
|
2024-01-03 16:28:36 +08:00
|
|
|
resource_server.sp_initiated = false
|
|
|
|
} else {
|
|
|
|
resource_server.sp_initiated = true
|
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (!resource_server.oauth_metadata_url) {
|
|
|
|
resource_server.oauth_metadata_url = authSettings.metadata_url
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
|
|
|
resource_server.id = resource_server_id
|
|
|
|
authSettings.resource_servers.push(resource_server)
|
|
|
|
}
|
2022-05-10 22:22:04 +08:00
|
|
|
}
|
2022-05-05 21:08:48 +08:00
|
|
|
|
2022-05-10 22:22:04 +08:00
|
|
|
return authSettings;
|
|
|
|
}
|
|
|
|
|
2024-06-20 00:31:49 +08:00
|
|
|
var oauth_settings = { oauth_enabled : false}
|
|
|
|
|
|
|
|
export function set_oauth_settings(settings) {
|
|
|
|
oauth_settings = settings
|
|
|
|
}
|
|
|
|
function get_oauth_settings() {
|
|
|
|
return oauth_settings
|
|
|
|
}
|
|
|
|
|
|
|
|
export function oauth_initialize_if_required(state = "index") {
|
|
|
|
let oauth = oauth_initialize(get_oauth_settings())
|
|
|
|
if (!oauth.enabled) return oauth;
|
|
|
|
switch (state) {
|
|
|
|
case 'login-callback':
|
|
|
|
oauth_completeLogin(); break;
|
|
|
|
case 'logout-callback':
|
|
|
|
oauth_completeLogout(); break;
|
|
|
|
default:
|
|
|
|
oauth = oauth_initiate(oauth);
|
|
|
|
}
|
|
|
|
return oauth;
|
|
|
|
}
|
|
|
|
|
2024-06-19 23:04:29 +08:00
|
|
|
export function oauth_initiate(oauth) {
|
|
|
|
if (oauth.enabled) {
|
|
|
|
if (!oauth.sp_initiated) {
|
|
|
|
oauth.logged_in = has_auth_credentials();
|
|
|
|
} else {
|
|
|
|
oauth_is_logged_in().then( status => {
|
|
|
|
if (status.loggedIn && !has_auth_credentials()) {
|
|
|
|
oauth.logged_in = false;
|
|
|
|
oauth_initiateLogout();
|
|
|
|
} else {
|
|
|
|
if (!status.loggedIn) {
|
|
|
|
clear_auth();
|
|
|
|
} else {
|
|
|
|
oauth.logged_in = true;
|
|
|
|
oauth.expiryDate = new Date(status.user.expires_at * 1000); // it is epoch in seconds
|
|
|
|
let current = new Date();
|
|
|
|
_management_logger.debug('token expires in ', (oauth.expiryDate-current)/1000,
|
|
|
|
'secs at : ', oauth.expiryDate );
|
|
|
|
oauth.user_name = status.user.profile['user_name'];
|
|
|
|
if (!oauth.user_name || oauth.user_name == '') {
|
|
|
|
oauth.user_name = status.user.profile['sub'];
|
|
|
|
}
|
|
|
|
oauth.scopes = status.user.scope;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return oauth;
|
|
|
|
}
|
2024-01-03 16:28:36 +08:00
|
|
|
function oauth_initialize_user_manager(resource_server) {
|
2024-06-19 23:04:29 +08:00
|
|
|
let oidcSettings = {
|
2024-03-14 01:44:20 +08:00
|
|
|
userStore: new oidc.WebStorageStateStore({ store: window.localStorage }),
|
2024-01-18 22:16:26 +08:00
|
|
|
authority: resource_server.oauth_provider_url,
|
|
|
|
client_id: resource_server.oauth_client_id,
|
|
|
|
response_type: resource_server.oauth_response_type,
|
|
|
|
scope: resource_server.oauth_scopes,
|
2024-01-03 16:28:36 +08:00
|
|
|
resource: resource_server.id,
|
2023-03-31 15:51:22 +08:00
|
|
|
redirect_uri: rabbit_base_uri() + "/js/oidc-oauth/login-callback.html",
|
|
|
|
post_logout_redirect_uri: rabbit_base_uri() + "/",
|
2022-05-05 21:08:48 +08:00
|
|
|
|
2022-05-05 22:22:47 +08:00
|
|
|
automaticSilentRenew: true,
|
2022-05-05 21:08:48 +08:00
|
|
|
revokeAccessTokenOnSignout: true,
|
2022-05-31 21:08:32 +08:00
|
|
|
extraQueryParams: {
|
2024-01-03 16:28:36 +08:00
|
|
|
audience: resource_server.id, // required by oauth0
|
2022-05-31 21:08:32 +08:00
|
|
|
},
|
2022-05-05 21:08:48 +08:00
|
|
|
};
|
2024-05-24 22:44:21 +08:00
|
|
|
if (resource_server.end_session_endpoint != "") {
|
|
|
|
oidcSettings.metadataSeed = {
|
|
|
|
end_session_endpoint: resource_server.end_session_endpoint
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (resource_server.oauth_client_secret != "") {
|
|
|
|
oidcSettings.client_secret = resource_server.oauth_client_secret;
|
2022-11-08 16:41:47 +08:00
|
|
|
}
|
2024-01-18 22:16:26 +08:00
|
|
|
if (resource_server.oauth_metadata_url != "") {
|
|
|
|
oidcSettings.metadataUrl = resource_server.oauth_metadata_url;
|
2022-11-08 16:41:47 +08:00
|
|
|
}
|
2022-05-05 21:08:48 +08:00
|
|
|
|
2022-09-01 20:53:42 +08:00
|
|
|
oidc.Log.setLevel(oidc.Log.DEBUG);
|
|
|
|
oidc.Log.setLogger(console);
|
2022-05-05 21:08:48 +08:00
|
|
|
|
|
|
|
mgr = new oidc.UserManager(oidcSettings);
|
2024-06-19 23:04:29 +08:00
|
|
|
// oauth.readiness_url = mgr.settings.metadataUrl;
|
2022-05-05 21:08:48 +08:00
|
|
|
|
2022-09-01 20:53:42 +08:00
|
|
|
_management_logger = new oidc.Logger("Management");
|
2022-05-05 21:08:48 +08:00
|
|
|
|
2022-05-05 22:22:47 +08:00
|
|
|
mgr.events.addAccessTokenExpiring(function() {
|
2022-11-08 16:41:47 +08:00
|
|
|
_management_logger.info("token expiring...");
|
2022-05-05 22:22:47 +08:00
|
|
|
});
|
2022-07-07 17:10:03 +08:00
|
|
|
mgr.events.addAccessTokenExpired(function() {
|
2022-11-08 16:41:47 +08:00
|
|
|
_management_logger.info("token expired!!");
|
2022-07-07 17:10:03 +08:00
|
|
|
});
|
2022-05-05 22:22:47 +08:00
|
|
|
mgr.events.addSilentRenewError(function(err) {
|
2022-11-08 16:41:47 +08:00
|
|
|
_management_logger.error("token expiring failed due to ", err);
|
2022-05-05 22:22:47 +08:00
|
|
|
});
|
2022-07-07 17:10:03 +08:00
|
|
|
mgr.events.addUserLoaded(function(user) {
|
2024-06-19 23:04:29 +08:00
|
|
|
set_token_auth(user.access_token)
|
2022-11-08 16:41:47 +08:00
|
|
|
});
|
2022-05-05 22:22:47 +08:00
|
|
|
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
2024-06-19 23:04:29 +08:00
|
|
|
export function oauth_initialize(authSettings) {
|
2024-01-03 16:28:36 +08:00
|
|
|
authSettings = auth_settings_apply_defaults(authSettings);
|
2024-06-19 23:04:29 +08:00
|
|
|
let oauth = {
|
2024-01-03 16:28:36 +08:00
|
|
|
"logged_in": false,
|
|
|
|
"enabled" : authSettings.oauth_enabled,
|
|
|
|
"resource_servers" : authSettings.resource_servers,
|
|
|
|
"oauth_disable_basic_auth" : authSettings.oauth_disable_basic_auth
|
|
|
|
}
|
|
|
|
if (!oauth.enabled) return oauth;
|
|
|
|
|
2024-06-19 23:04:29 +08:00
|
|
|
let resource_server = null;
|
2024-01-03 16:28:36 +08:00
|
|
|
|
|
|
|
if (oauth.resource_servers.length == 1) {
|
|
|
|
resource_server = oauth.resource_servers[0]
|
|
|
|
} else if (has_auth_resource()) {
|
2024-06-19 23:04:29 +08:00
|
|
|
resource_server = lookup_resource_server(get_auth_resource(), oauth.resource_servers)
|
2024-01-03 16:28:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resource_server) {
|
|
|
|
oauth.sp_initiated = resource_server.sp_initiated
|
2024-01-18 22:16:26 +08:00
|
|
|
oauth.authority = resource_server.oauth_provider_url
|
2024-01-03 16:28:36 +08:00
|
|
|
if (!resource_server.sp_initiated) return oauth;
|
|
|
|
else oauth_initialize_user_manager(resource_server)
|
|
|
|
}
|
|
|
|
|
2022-05-05 21:08:48 +08:00
|
|
|
return oauth;
|
|
|
|
}
|
|
|
|
|
|
|
|
function log() {
|
|
|
|
message = ""
|
|
|
|
Array.prototype.forEach.call(arguments, function(msg) {
|
|
|
|
if (msg instanceof Error) {
|
|
|
|
msg = "Error: " + msg.message;
|
|
|
|
}
|
|
|
|
else if (typeof msg !== "string") {
|
|
|
|
msg = JSON.stringify(msg, null, 2);
|
|
|
|
}
|
|
|
|
message += msg
|
|
|
|
});
|
2022-09-01 20:53:42 +08:00
|
|
|
_management_logger.info(message)
|
2022-05-05 21:08:48 +08:00
|
|
|
}
|
|
|
|
|
2022-05-10 22:22:04 +08:00
|
|
|
function oauth_is_logged_in() {
|
2022-05-05 21:08:48 +08:00
|
|
|
return mgr.getUser().then(user => {
|
|
|
|
if (!user) {
|
|
|
|
return { "loggedIn": false };
|
|
|
|
}
|
|
|
|
return { "user": user, "loggedIn": !user.expired };
|
|
|
|
});
|
|
|
|
}
|
2024-06-19 23:04:29 +08:00
|
|
|
function lookup_resource_server(resource_server_id, resource_servers) {
|
2024-01-03 16:28:36 +08:00
|
|
|
let i = 0;
|
|
|
|
|
2024-06-19 23:04:29 +08:00
|
|
|
while (i < resource_servers.length && resource_servers[i].id != resource_server_id) {
|
2024-01-03 16:28:36 +08:00
|
|
|
i++;
|
|
|
|
}
|
2024-06-19 23:04:29 +08:00
|
|
|
if (i < resource_servers.length) return resource_servers[i]
|
2024-01-03 16:28:36 +08:00
|
|
|
else return null
|
|
|
|
}
|
|
|
|
|
2024-06-19 23:04:29 +08:00
|
|
|
export function oauth_initiateLogin(resource_server_id) {
|
|
|
|
let resource_server = lookup_resource_server(resource_server_id, oauth.resource_servers)
|
2024-01-03 16:28:36 +08:00
|
|
|
if (!resource_server) return;
|
|
|
|
set_auth_resource(resource_server_id)
|
|
|
|
|
|
|
|
oauth.sp_initiated = resource_server.sp_initiated
|
2024-01-18 22:16:26 +08:00
|
|
|
oauth.authority = resource_server.oauth_provider_url
|
2024-01-03 16:28:36 +08:00
|
|
|
|
|
|
|
if (resource_server.sp_initiated) {
|
|
|
|
if (!mgr) oauth_initialize_user_manager(resource_server)
|
|
|
|
|
2022-09-01 20:53:42 +08:00
|
|
|
mgr.signinRedirect({ state: { } }).then(function() {
|
2024-01-03 16:28:36 +08:00
|
|
|
_management_logger.debug("signinRedirect done")
|
2022-05-05 21:08:48 +08:00
|
|
|
}).catch(function(err) {
|
2024-01-03 16:28:36 +08:00
|
|
|
_management_logger.error(err)
|
2022-11-08 16:41:47 +08:00
|
|
|
})
|
|
|
|
} else {
|
2024-01-18 22:16:26 +08:00
|
|
|
location.href = resource_server.oauth_provider_url
|
2022-11-08 16:41:47 +08:00
|
|
|
}
|
2022-05-05 21:08:48 +08:00
|
|
|
}
|
2022-10-04 15:13:57 +08:00
|
|
|
|
2024-06-19 23:04:29 +08:00
|
|
|
function oauth_redirectToHome() {
|
|
|
|
let path = get_pref("oauth-return-to")
|
2023-10-27 04:19:07 +08:00
|
|
|
clear_pref("oauth-return-to")
|
2024-06-19 23:04:29 +08:00
|
|
|
go_to( !path ? "" : path)
|
2022-11-08 16:41:47 +08:00
|
|
|
}
|
2023-10-27 04:19:07 +08:00
|
|
|
function go_to(path) {
|
|
|
|
location.href = rabbit_path_prefix() + "/" + path
|
2022-05-05 21:08:48 +08:00
|
|
|
}
|
2024-06-19 23:04:29 +08:00
|
|
|
|
2022-11-08 16:41:47 +08:00
|
|
|
function go_to_authority() {
|
2022-12-13 21:09:18 +08:00
|
|
|
location.href = oauth.authority
|
2022-11-08 16:41:47 +08:00
|
|
|
}
|
2022-05-26 22:49:07 +08:00
|
|
|
function oauth_redirectToLogin(error) {
|
2023-05-18 23:17:11 +08:00
|
|
|
if (!error) location.href = rabbit_path_prefix() + "/"
|
2022-05-26 22:49:07 +08:00
|
|
|
else {
|
2023-05-18 23:17:11 +08:00
|
|
|
location.href = rabbit_path_prefix() + "/?error=" + error
|
2022-05-26 22:49:07 +08:00
|
|
|
}
|
2022-05-05 21:08:48 +08:00
|
|
|
}
|
2024-06-19 23:04:29 +08:00
|
|
|
export function oauth_completeLogin() {
|
|
|
|
mgr.signinRedirectCallback().then(function(user) {
|
|
|
|
set_token_auth(user.access_token);
|
|
|
|
oauth_redirectToHome();
|
|
|
|
}).catch(function(err) {
|
|
|
|
_management_logger.error(err)
|
|
|
|
oauth_redirectToLogin(err)
|
2022-05-05 21:08:48 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-19 23:04:29 +08:00
|
|
|
export function oauth_initiateLogout() {
|
2022-11-08 16:41:47 +08:00
|
|
|
if (oauth.sp_initiated) {
|
2024-04-23 18:06:34 +08:00
|
|
|
mgr.metadataService.getEndSessionEndpoint().then(endpoint => {
|
|
|
|
if (endpoint == undefined) {
|
2024-06-19 23:04:29 +08:00
|
|
|
// Logout only from management UI
|
2024-04-23 18:06:34 +08:00
|
|
|
mgr.removeUser().then(res => {
|
|
|
|
clear_auth()
|
|
|
|
oauth_redirectToLogin()
|
|
|
|
})
|
|
|
|
}else {
|
|
|
|
// OpenId Connect RP-Initiated Logout
|
|
|
|
mgr.signoutRedirect()
|
|
|
|
}
|
|
|
|
})
|
2022-11-08 16:41:47 +08:00
|
|
|
} else {
|
2022-12-13 21:09:18 +08:00
|
|
|
go_to_authority()
|
2022-11-08 16:41:47 +08:00
|
|
|
}
|
2022-05-05 21:08:48 +08:00
|
|
|
}
|
2024-04-23 18:06:34 +08:00
|
|
|
|
2024-06-19 23:04:29 +08:00
|
|
|
export function oauth_completeLogout() {
|
2022-12-13 21:09:18 +08:00
|
|
|
clear_auth()
|
|
|
|
mgr.signoutRedirectCallback().then(_ => oauth_redirectToLogin())
|
2022-05-05 21:08:48 +08:00
|
|
|
}
|
2024-01-03 16:28:36 +08:00
|
|
|
function validate_openid_configuration(payload) {
|
|
|
|
if (payload == null) {
|
|
|
|
throw new Error("Payload does not contain openid configuration")
|
|
|
|
}
|
|
|
|
if (typeof payload.authorization_endpoint != 'string') {
|
|
|
|
throw new Error("Missing authorization_endpoint")
|
|
|
|
}
|
|
|
|
if (typeof payload.token_endpoint != 'string') {
|
|
|
|
throw new Error("Missing token_endpoint")
|
|
|
|
}
|
|
|
|
if (typeof payload.jwks_uri != 'string') {
|
|
|
|
throw new Error("Missing jwks_uri")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-06-19 23:04:29 +08:00
|
|
|
|
|
|
|
function warningMessageOAuthResource(oauthResource, reason) {
|
|
|
|
return "OAuth resource [<b>" + (oauthResource["label"] != null ? oauthResource.label : oauthResource.id) +
|
|
|
|
"</b>] not available. OpenId Discovery endpoint " + readiness_url(oauthResource) + reason
|
|
|
|
}
|
|
|
|
function warningMessageOAuthResources(commonProviderURL, oauthResources, reason) {
|
|
|
|
return "OAuth resources [ <b>" + oauthResources.map(resource => resource["label"] != null ? resource.label : resource.id).join("</b>,<b>")
|
|
|
|
+ "</b>] not available. OpenId Discovery endpoint " + commonProviderURL + reason
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hasAnyResourceServerReady(oauth, onReadyCallback) {
|
|
|
|
// Find out how many distinct oauthServers are configured
|
|
|
|
let oauthServers = removeDuplicates(oauth.resource_servers.filter((resource) => resource.sp_initiated))
|
|
|
|
oauthServers.forEach(function(entry) { console.log(readiness_url(entry)) })
|
|
|
|
if (oauthServers.length > 0) { // some resources are sp_initiated but there could be idp_initiated too
|
|
|
|
Promise.allSettled(oauthServers.map(oauthServer => fetch(readiness_url(oauthServer)).then(res => res.json())))
|
|
|
|
.then(results => {
|
|
|
|
results.forEach(function(entry) { console.log(entry) })
|
|
|
|
let notReadyServers = []
|
|
|
|
let notCompliantServers = []
|
|
|
|
|
|
|
|
for (let i = 0; i < results.length; i++) {
|
|
|
|
switch (results[i].status) {
|
|
|
|
case "fulfilled":
|
|
|
|
try {
|
|
|
|
validate_openid_configuration(results[i].value)
|
|
|
|
}catch(e) {
|
|
|
|
console.log("Unable to connect to " + oauthServers[i].oauth_provider_url + ". " + e)
|
|
|
|
notCompliantServers.push(oauthServers[i].oauth_provider_url)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case "rejected":
|
|
|
|
notReadyServers.push(oauthServers[i].oauth_provider_url)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const spOauthServers = oauth.resource_servers.filter((resource) => resource.sp_initiated)
|
|
|
|
const groupByProviderURL = spOauthServers.reduce((group, oauthServer) => {
|
|
|
|
const { oauth_provider_url } = oauthServer;
|
|
|
|
group[oauth_provider_url] = group[oauth_provider_url] ?? [];
|
|
|
|
group[oauth_provider_url].push(oauthServer);
|
|
|
|
return group;
|
|
|
|
}, {})
|
|
|
|
let warnings = []
|
|
|
|
for(var url in groupByProviderURL){
|
|
|
|
console.log(url + ': ' + groupByProviderURL[url]);
|
|
|
|
const notReadyResources = groupByProviderURL[url].filter((oauthserver) => notReadyServers.includes(oauthserver.oauth_provider_url))
|
|
|
|
const notCompliantResources = groupByProviderURL[url].filter((oauthserver) => notCompliantServers.includes(oauthserver.oauth_provider_url))
|
|
|
|
if (notReadyResources.length == 1) {
|
|
|
|
warnings.push(warningMessageOAuthResource(notReadyResources[0], " not reachable"))
|
|
|
|
}else if (notReadyResources.length > 1) {
|
|
|
|
warnings.push(warningMessageOAuthResources(url, notReadyResources, " not reachable"))
|
|
|
|
}
|
|
|
|
if (notCompliantResources.length == 1) {
|
|
|
|
warnings.push(warningMessageOAuthResource(notCompliantResources[0], " not compliant"))
|
|
|
|
}else if (notCompliantResources.length > 1) {
|
|
|
|
warnings.push(warningMessageOAuthResources(url, notCompliantResources, " not compliant"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("warnings:" + warnings)
|
|
|
|
oauth.declared_resource_servers_count = oauth.resource_servers.length
|
|
|
|
oauth.resource_servers = oauth.resource_servers.filter((resource) =>
|
|
|
|
!notReadyServers.includes(resource.oauth_provider_url) && !notCompliantServers.includes(resource.oauth_provider_url))
|
|
|
|
|
|
|
|
onReadyCallback(oauth, warnings)
|
|
|
|
|
|
|
|
})
|
|
|
|
}else {
|
|
|
|
onReadyCallback(oauth, [])
|
|
|
|
}
|
|
|
|
}
|