|
|
|
|
@ -1,11 +1,12 @@
|
|
|
|
|
import { apply, call, put, select } from 'redux-saga/effects';
|
|
|
|
|
import { nanoid } from 'nanoid';
|
|
|
|
|
import { call, put, select } from 'redux-saga/effects';
|
|
|
|
|
import { replace } from '../../../lib/redux-router';
|
|
|
|
|
|
|
|
|
|
import selectors from '../../../selectors';
|
|
|
|
|
import actions from '../../../actions';
|
|
|
|
|
import api from '../../../api';
|
|
|
|
|
import { setAccessToken } from '../../../utils/access-token-storage';
|
|
|
|
|
import Paths from '../../../constants/Paths';
|
|
|
|
|
import { nanoid } from 'nanoid';
|
|
|
|
|
|
|
|
|
|
export function* initializeLogin() {
|
|
|
|
|
const { item: config } = yield call(api.getConfig); // TODO: handle error
|
|
|
|
|
@ -32,30 +33,42 @@ export function* authenticateWithOidc() {
|
|
|
|
|
const oidcConfig = yield select(selectors.selectOidcConfig);
|
|
|
|
|
|
|
|
|
|
const nonce = nanoid();
|
|
|
|
|
window.sessionStorage.setItem("oidc-nonce", nonce);
|
|
|
|
|
window.location.replace(oidcConfig.authorizationUrl + "&nonce=" + encodeURIComponent(nonce));
|
|
|
|
|
window.sessionStorage.setItem('oidc-nonce', nonce);
|
|
|
|
|
window.location.replace(`${oidcConfig.authorizationUrl}&nonce=${encodeURIComponent(nonce)}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* authenticateWithOidcCallback() {
|
|
|
|
|
const params = new URLSearchParams(window.location.hash.substring(1));
|
|
|
|
|
if(params.get("error") !== null) {
|
|
|
|
|
yield put(actions.authenticateWithOidc.failure(new Error(`OIDC Authorization error: ${params.get("error")}: ${params.get("error_description")}`)));
|
|
|
|
|
if (params.get('error') !== null) {
|
|
|
|
|
yield put(
|
|
|
|
|
actions.authenticateWithOidc.failure(
|
|
|
|
|
new Error(
|
|
|
|
|
`OIDC Authorization error: ${params.get('error')}: ${params.get('error_description')}`,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nonce = window.sessionStorage.getItem("oidc-nonce");
|
|
|
|
|
const nonce = window.sessionStorage.getItem('oidc-nonce');
|
|
|
|
|
if (nonce === null) {
|
|
|
|
|
yield put(actions.authenticateWithOidc.failure(new Error("Unable to process OIDC response: no nonce issued")));
|
|
|
|
|
yield put(
|
|
|
|
|
actions.authenticateWithOidc.failure(
|
|
|
|
|
new Error('Unable to process OIDC response: no nonce issued'),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const code = params.get("code");
|
|
|
|
|
if(code === null) {
|
|
|
|
|
yield put(actions.authenticateWithOidc.failure(new Error("Invalid OIDC response: no code parameter")));
|
|
|
|
|
const code = params.get('code');
|
|
|
|
|
if (code === null) {
|
|
|
|
|
yield put(
|
|
|
|
|
actions.authenticateWithOidc.failure(new Error('Invalid OIDC response: no code parameter')),
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.sessionStorage.removeItem("oidc-nonce");
|
|
|
|
|
window.sessionStorage.removeItem('oidc-nonce');
|
|
|
|
|
|
|
|
|
|
yield put(replace(Paths.LOGIN));
|
|
|
|
|
|
|
|
|
|
|