Skip to content

Commit

Permalink
Error message for invalid auth provider (SAP#528)
Browse files Browse the repository at this point in the history
* simplified auth check, added error message
  • Loading branch information
maxmarkus authored May 23, 2019
1 parent bf24801 commit 3bb7c1d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
6 changes: 3 additions & 3 deletions core/src/Authorization.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@
checkAuth(idpProviderSettings);
})
.catch(err => {
console.error(
`Could not instantate ${idpProviderName} provider : ${err}`
);
const errorMsg = `Error: ${err.message || err}`;
console.error(errorMsg, err.message && err);
LuigiConfig.setErrorMessage(errorMsg);
});
}
checkAuth(idpProviderSettings);
Expand Down
6 changes: 1 addition & 5 deletions core/src/core-api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ class LuigiAuthManager {
* @returns {boolean} returns true if authorization is enabled. Otherwise returns false.
*/
isAuthorizationEnabled() {
const idpProviderName = config.getConfigValue('auth.use');
const idpProviderSettings = config.getConfigValue(
`auth.${idpProviderName}`
);
return !!idpProviderSettings;
return !!config.getConfigValue('auth.use');
}

async handleAuthEvent(
Expand Down
8 changes: 6 additions & 2 deletions core/src/core-api/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class LuigiConfigManager {
id: undefined
};

this.configReadyCallback = function() {};
this.configReadyCallback = function () { };
}

setConfigCallbacks(configReadyCallback) {
this.configReadyCallback = configReadyCallback;
this.configReadyTimeout.id = setTimeout(() => {
// Avoid Luigi initialization if timeout reached
this.configReadyCallback = function() {};
this.configReadyCallback = function () { };
this.configNotReadyCallback();
}, this.configReadyTimeout.valueMs);
}
Expand All @@ -35,6 +35,10 @@ class LuigiConfigManager {
const errorMsg =
'Ups.. Looks like Luigi was not configured. Please use Luigi.setConfig(config) function to configure Luigi.';
console.error(errorMsg);
this.setErrorMessage(errorMsg);
}

setErrorMessage(errorMsg) {
var errorTextNode = document.createTextNode(errorMsg);
var fd_ui = document.createElement('div');
fd_ui.setAttribute('class', 'fd-ui');
Expand Down
5 changes: 1 addition & 4 deletions core/src/core-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ export const LuigiConfig = config;
export const LuigiAuth = auth;

// Expose it window for user app to call Luigi.setConfig()
window.Luigi = Object.assign(
config,
auth
);
window.Luigi = Object.assign(config, auth);
2 changes: 1 addition & 1 deletion core/src/navigation/TopNav.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<svelte:window on:click="closeAllDropdowns()" on:blur="closeAllDropdowns()" />
<svelte:window on:click="closeAllDropdowns()" on:blur="closeAllDropdowns()"/>
{#if showTopNav}
<div class="fd-shellbar {hideNavComponent ? 'hideNavComponent' : ''}">
<div class="fd-shellbar__group fd-shellbar__group--start">
Expand Down
11 changes: 5 additions & 6 deletions core/src/utilities/helpers/generic-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ export const getPathWithoutHash = path => {
* Returns the value of a given url parameter name
* @param {string} name
*/
export const getUrlParameter = (name) => {
export const getUrlParameter = name => {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var result = regex.exec(window.location.search);
return result && decodeURIComponent(result[1].replace(/\+/g, ' ')) || '';
return (result && decodeURIComponent(result[1].replace(/\+/g, ' '))) || '';
};


/**
* Prepend current url to redirect_uri, if it is a relative path
* @param {path} string full url, relative or absolute path
Expand Down Expand Up @@ -185,9 +184,9 @@ export const replaceVars = (
new RegExp(
escapeRegExp(
(parenthesis ? '{' : '') +
prefix +
entry[0] +
(parenthesis ? '}' : '')
prefix +
entry[0] +
(parenthesis ? '}' : '')
),
'g'
),
Expand Down
20 changes: 15 additions & 5 deletions core/test/utilities/helpers/async-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,30 @@ describe('Async-helpers', () => {
it('executes a pure function and returns a new promise', async () => {
const plainFunc = (one, two, three) => {
return three;
}
};
const thirdParam = 'hello';
const prom = AsyncHelpers.applyFunctionPromisified(plainFunc, [undefined, undefined, thirdParam]);
const prom = AsyncHelpers.applyFunctionPromisified(plainFunc, [
undefined,
undefined,
thirdParam
]);

assert.isTrue(GenericHelpers.isPromise(prom), 'is a promise');
assert.equal(await prom, thirdParam, 'value is equal');
});

it('executes an async function and returns its promise', async () => {
const promiseFunc = (one, two, three) => {
return new Promise((resolve) => { resolve(three); });
}
return new Promise(resolve => {
resolve(three);
});
};
const thirdParam = 'hello';
const prom = AsyncHelpers.applyFunctionPromisified(promiseFunc, [undefined, undefined, thirdParam]);
const prom = AsyncHelpers.applyFunctionPromisified(promiseFunc, [
undefined,
undefined,
thirdParam
]);

assert.isTrue(GenericHelpers.isPromise(prom), 'is a promise');
assert.equal(await prom, thirdParam, 'value is equal');
Expand Down

0 comments on commit 3bb7c1d

Please sign in to comment.