Logging improvements
Rather than logging directly via console.log we do it via the Logger library provided by oidc-client which allows to use logging levels
This commit is contained in:
parent
dbf5797107
commit
54464c0498
|
|
@ -28,9 +28,8 @@
|
|||
if (oauth.enable) {
|
||||
oauth_is_logged_in().then( status => {
|
||||
if (status.loggedIn && !has_auth_cookie_value()) {
|
||||
console.log("Session has expired");
|
||||
oauth.logged_in = false;
|
||||
oauth_initiateLogout();
|
||||
oauth_initiateLogout();
|
||||
}else {
|
||||
if (!status.loggedIn) {
|
||||
replace_content('outer', format('login_oauth', {}));
|
||||
|
|
@ -38,7 +37,9 @@
|
|||
oauth.logged_in = true
|
||||
oauth.access_token = status.user.access_token
|
||||
oauth.expiryDate = new Date(status.user.expires_at * 1000) // it is epoch in seconds
|
||||
console.log("token expires at : " + oauth.expiryDate);
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
|
||||
//import {UserManager} from "./scripts/oidc-client-ts/oidc-client-ts.js"
|
||||
// import {axios} from "./scripts/axios/axios.min.js"
|
||||
|
||||
|
||||
var mgr;
|
||||
var _management_logger;
|
||||
|
||||
function oauth_initialize_if_required() {
|
||||
rabbit_port = window.location.port ? ":" + window.location.port : ""
|
||||
|
|
@ -69,7 +66,6 @@ function oauth_initialize(authSettings) {
|
|||
redirect_uri: rabbit_base_uri + "/js/oidc-oauth/login-callback.html",
|
||||
post_logout_redirect_uri: rabbit_base_uri ,
|
||||
|
||||
filterProtocolClaims: true,
|
||||
automaticSilentRenew: true,
|
||||
revokeAccessTokenOnSignout: true,
|
||||
extraQueryParams: {
|
||||
|
|
@ -85,25 +81,24 @@ function oauth_initialize(authSettings) {
|
|||
end_session_endpoint: authSettings.oauth_provider_url + '/logout.do'
|
||||
}
|
||||
}
|
||||
oidc.Log.setLevel(oidc.Log.DEBUG);
|
||||
oidc.Log.setLogger(console);
|
||||
|
||||
mgr = new oidc.UserManager(oidcSettings);
|
||||
oauth.readiness_url = mgr.settings.metadataUrl
|
||||
|
||||
oidc.Log.setLogger(console);
|
||||
oidc.Log.setLevel(oidc.Log.INFO);
|
||||
_management_logger = new oidc.Logger("Management");
|
||||
|
||||
mgr.events.addAccessTokenExpiring(function() {
|
||||
console.log("token expiring...");
|
||||
_management_logger.info("token expiring...");
|
||||
});
|
||||
mgr.events.addAccessTokenExpired(function() {
|
||||
console.log("token expired !!");
|
||||
_management_logger.info("token expired!!");
|
||||
});
|
||||
mgr.events.addSilentRenewError(function(err) {
|
||||
console.log("token expiring failed due to " + err);
|
||||
_management_logger.error("token expiring failed due to ", err);
|
||||
});
|
||||
mgr.events.addUserLoaded(function(user) {
|
||||
let expiryDate = new Date(user.expires_at * 1000) // it is epoch in seconds
|
||||
console.log("user loaded with token which expires at " + expiryDate);
|
||||
oauth.access_token = user.access_token;
|
||||
});
|
||||
|
||||
|
|
@ -121,31 +116,9 @@ function log() {
|
|||
}
|
||||
message += msg
|
||||
});
|
||||
console.log(message)
|
||||
_management_logger.info(message)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function oauth_registerCallbacks() {
|
||||
mgr.events.addUserLoaded(function (user) {
|
||||
console.log("addUserLoaded=> ", user);
|
||||
mgr.getUser().then(function() {
|
||||
console.log("getUser loaded user after userLoaded event fired");
|
||||
});
|
||||
});
|
||||
mgr.events.addUserUnloaded(function (e) {
|
||||
console.log("addUserUnloaded=> ", e);
|
||||
});
|
||||
|
||||
mgr.events.addUserSignedIn(function (e) {
|
||||
log("addUserSignedIn=> " , e);
|
||||
});
|
||||
mgr.events.addUserSignedOut(function (e) {
|
||||
log("addUserSignedOut=> ", e);
|
||||
});
|
||||
|
||||
}
|
||||
function oauth_is_logged_in() {
|
||||
return mgr.getUser().then(user => {
|
||||
if (!user) {
|
||||
|
|
@ -154,14 +127,11 @@ function oauth_is_logged_in() {
|
|||
return { "user": user, "loggedIn": !user.expired };
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function oauth_initiateLogin() {
|
||||
mgr.signinRedirect({ state: { } /*, useReplaceToNavigate: true*/ }).then(function() {
|
||||
log("signinRedirect done");
|
||||
mgr.signinRedirect({ state: { } }).then(function() {
|
||||
_management_logger.debug("signinRedirect done");
|
||||
}).catch(function(err) {
|
||||
console.error(err);
|
||||
log(err);
|
||||
_management_logger.error(err);
|
||||
});
|
||||
}
|
||||
function oauth_redirectToHome(oauth) {
|
||||
|
|
@ -176,8 +146,7 @@ function oauth_redirectToLogin(error) {
|
|||
}
|
||||
function oauth_completeLogin() {
|
||||
mgr.signinRedirectCallback().then(user => oauth_redirectToHome(user)).catch(function(err) {
|
||||
console.error(err);
|
||||
log(err);
|
||||
_management_logger.error(err);
|
||||
oauth_redirectToLogin(err)
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,6 @@ cd test/oauth/with-uaa
|
|||
|
||||
Start UAA:
|
||||
```
|
||||
cd test/oauth/with-uaa
|
||||
make start-uaa
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,13 @@ help:
|
|||
start-rabbitmq: ## Start RabbitMQ
|
||||
@(docker kill rabbitmq >/dev/null 2>&1 && docker rm rabbitmq)
|
||||
@(gmake --directory=${RABBITMQ_SERVER_ROOT} run-broker \
|
||||
RABBITMQ_ENABLED_PLUGINS_FILE=deps/rabbitmq_management/selenium/test/oauth/with-uaa/enabled_plugins \
|
||||
RABBITMQ_ENABLED_PLUGINS="rabbitmq_auth_backend_oauth2,rabbitmq_management" \
|
||||
RABBITMQ_CONFIG_FILE=deps/rabbitmq_management/selenium/test/oauth/with-uaa/rabbitmq.config)
|
||||
start-uaa: ## Deploy UAA
|
||||
@(./start-uaa.sh)
|
||||
|
||||
run-test: ## Run tests interactively
|
||||
start-uaa: ## Start UAA
|
||||
@(./start-uaa.sh)
|
||||
stop-uaa: ## Stop UAA
|
||||
@(./stop-uaa.sh)
|
||||
|
||||
run-test: ## Run tests interactively e.g. make run-test [TEST=landing.js]
|
||||
@(RABBITMQ_URL=http://localhost:15672 RUN_LOCAL=true SCREENSHOTS_DIR=${PWD}/screens npm test $(PWD)/$(TEST))
|
||||
|
|
|
|||
Loading…
Reference in New Issue