Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oidc provider uses storage type also for oidc client configuration #1269

Merged
merged 15 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions core/src/navigation/services/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,7 @@ class NavigationClass {
this.buildVirtualTree(node, nodeNamesInCurrentPath, pathParams);

// STANDARD PROCEDURE
let children = await this.getChildren(
node,
newContext,
nodeNamesInCurrentPath
);
let children = await this.getChildren(node, newContext);
const newNodeNamesInCurrentPath = nodeNamesInCurrentPath.slice(1);
result = this.buildNode(
newNodeNamesInCurrentPath,
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/auth-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ class AuthLayerSvcClass {
);

if (hasAuthSuccessFulFn && AuthStoreSvc.isNewlyAuthorized()) {
AuthStoreSvc.removeNewlyAuthorized();
await LuigiAuth.handleAuthEvent(
'onAuthSuccessful',
idpProviderSettings,
authData
);
}
AuthStoreSvc.removeNewlyAuthorized();

if (
GenericHelpers.isFunction(
Expand Down
10 changes: 0 additions & 10 deletions core/webpack-common-plugins.js

This file was deleted.

1 change: 0 additions & 1 deletion core/webpack-ie11.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const commonPlugins = require('./webpack-common-plugins');
const commonRules = require('./webpack-common-rules');
const exec = require('child_process').exec;
const fundamentalStyles = require('./fundamentalStyleClasses');
Expand Down
1 change: 0 additions & 1 deletion core/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const CleanWebpackPlugin = require('clean-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const commonRules = require('./webpack-common-rules');
const commonPlugins = require('./webpack-common-plugins');
const exec = require('child_process').exec;
const fundamentalStyles = require('./fundamentalStyleClasses');

Expand Down
2 changes: 2 additions & 0 deletions plugins/auth/public/auth-oidc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# vendor
oidc-client.min.js
2 changes: 1 addition & 1 deletion plugins/auth/public/auth-oidc/silent-callback.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script src="/assets/auth-oidc/plugin.js"></script>
<script src="/assets/auth-oidc/oidc-client.min.js"></script>
<script>
var mgr = new Oidc.UserManager();
mgr.signinSilentCallback().catch(error => {
Expand Down
50 changes: 45 additions & 5 deletions plugins/auth/src/auth-oidc/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Oidc from 'oidc-client';
import {
UserManager,
WebStorageStateStore,
InMemoryWebStorage
} from 'oidc-client';
import { Helpers } from '../helpers';
import { thirdPartyCookiesStatus } from '../third-party-cookies-check';
export default class openIdConnect {
Expand All @@ -16,16 +20,35 @@ export default class openIdConnect {
silent_redirect_uri:
window.location.origin + '/assets/auth-oidc/silent-callback.html'
};

const mergedSettings = Helpers.deepMerge(defaultSettings, settings);

// Prepend current url to redirect_uri, if it is a relative path
['redirect_uri', 'post_logout_redirect_uri'].forEach(key => {
mergedSettings[key] = Helpers.prependOrigin(mergedSettings[key]);
});

// set storage type
const storageType = Luigi.getConfigValue('auth.storage');
const isValidStore = ['none', 'sessionStorage', 'localStorage'].includes(
storageType
);
if (isValidStore && storageType == 'none') {
mergedSettings.userStore = new WebStorageStateStore({
store: new InMemoryWebStorage()
});
mergedSettings.stateStore = new WebStorageStateStore({
store: new InMemoryWebStorage()
});
} else if (isValidStore) {
mergedSettings.stateStore = new WebStorageStateStore({
store: window[storageType]
});
} // else fall back to OIDC default

this.settings = mergedSettings;

this.client = new Oidc.UserManager(this.settings);
this.client = new UserManager(this.settings);

this.client.events.addUserLoaded(async payload => {
let profile = payload.profile;
Expand Down Expand Up @@ -168,9 +191,8 @@ export default class openIdConnect {
return resolve(true);
}

this.client
.signinRedirectCallback()
.then(authenticatedUser => {
this.tryToSignIn()
.then((authenticatedUser = {}) => {
if (authenticatedUser.error) {
return console.error(
'Error',
Expand Down Expand Up @@ -211,4 +233,22 @@ export default class openIdConnect {
});
});
}

async tryToSignIn() {
try {
// If the user was just redirected here from the sign in page, sign them in.
await this.client.signinRedirectCallback();
console.debug('User was redirected via the sign-in page. Now signed in.');
} catch (error) {
console.debug(
"Sign-in redirect callback doesn't work. Let's try a silent sign-in.",
error
);
// Barring that, if the user chose to have the Identity Server remember their
// credentials and permission decisions, we may be able to silently sign them
// back in via a background iframe.
await this.client.signinSilent();
console.debug('Silent sign-in completed.');
}
}
}
18 changes: 18 additions & 0 deletions plugins/auth/src/auth-oidc/webpack-extra.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const CopyWebpackPlugin = require('copy-webpack-plugin');

const pluginRoot = __dirname + '/../../../';
module.exports = {
plugins: [
new CopyWebpackPlugin(
[
{
from: pluginRoot + 'node_modules/oidc-client/dist/oidc-client.min.js',
to: pluginRoot + 'auth/public/auth-oidc'
}
],
{
verbose: true
}
)
]
};
152 changes: 152 additions & 0 deletions plugins/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
"acorn": "^6.0.5",
"babel-loader": "^8.0.5",
"bundlesize": "^0.17.0",
"copy-webpack-plugin": "^5.1.1",
"core-js": "^3.0.1",
"diff": ">=3.5.0",
"lodash": ">=4.17.13",
"lodash.merge": "^4.6.2",
"mixin-deep": ">=1.3.2",
"npm": ">=6.13.4",
"oidc-client": "^1.10.1",
Expand Down
Loading