|
|
|
@ -29,19 +29,22 @@ export function* authenticate(data) {
|
|
|
|
yield put(actions.authenticate.success(accessToken));
|
|
|
|
yield put(actions.authenticate.success(accessToken));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function* authenticateWithOidc() {
|
|
|
|
export function* authenticateUsingOidc() {
|
|
|
|
const oidcConfig = yield select(selectors.selectOidcConfig);
|
|
|
|
const oidcConfig = yield select(selectors.selectOidcConfig);
|
|
|
|
|
|
|
|
|
|
|
|
const nonce = nanoid();
|
|
|
|
const nonce = nanoid();
|
|
|
|
window.sessionStorage.setItem('oidc-nonce', nonce);
|
|
|
|
window.sessionStorage.setItem('oidc-nonce', nonce);
|
|
|
|
window.location.replace(`${oidcConfig.authorizationUrl}&nonce=${encodeURIComponent(nonce)}`);
|
|
|
|
window.location.href = `${oidcConfig.authorizationUrl}&nonce=${encodeURIComponent(nonce)}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function* authenticateWithOidcCallback() {
|
|
|
|
export function* authenticateUsingOidcCallback() {
|
|
|
|
const params = new URLSearchParams(window.location.hash.substring(1));
|
|
|
|
const params = new URLSearchParams(window.location.hash.substring(1));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yield put(replace(Paths.LOGIN));
|
|
|
|
|
|
|
|
|
|
|
|
if (params.get('error') !== null) {
|
|
|
|
if (params.get('error') !== null) {
|
|
|
|
yield put(
|
|
|
|
yield put(
|
|
|
|
actions.authenticateWithOidc.failure(
|
|
|
|
actions.authenticateUsingOidc.failure(
|
|
|
|
new Error(
|
|
|
|
new Error(
|
|
|
|
`OIDC Authorization error: ${params.get('error')}: ${params.get('error_description')}`,
|
|
|
|
`OIDC Authorization error: ${params.get('error')}: ${params.get('error_description')}`,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -53,7 +56,7 @@ export function* authenticateWithOidcCallback() {
|
|
|
|
const nonce = window.sessionStorage.getItem('oidc-nonce');
|
|
|
|
const nonce = window.sessionStorage.getItem('oidc-nonce');
|
|
|
|
if (nonce === null) {
|
|
|
|
if (nonce === null) {
|
|
|
|
yield put(
|
|
|
|
yield put(
|
|
|
|
actions.authenticateWithOidc.failure(
|
|
|
|
actions.authenticateUsingOidc.failure(
|
|
|
|
new Error('Unable to process OIDC response: no nonce issued'),
|
|
|
|
new Error('Unable to process OIDC response: no nonce issued'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
@ -63,29 +66,27 @@ export function* authenticateWithOidcCallback() {
|
|
|
|
const code = params.get('code');
|
|
|
|
const code = params.get('code');
|
|
|
|
if (code === null) {
|
|
|
|
if (code === null) {
|
|
|
|
yield put(
|
|
|
|
yield put(
|
|
|
|
actions.authenticateWithOidc.failure(new Error('Invalid OIDC response: no code parameter')),
|
|
|
|
actions.authenticateUsingOidc.failure(new Error('Invalid OIDC response: no code parameter')),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
window.sessionStorage.removeItem('oidc-nonce');
|
|
|
|
window.sessionStorage.removeItem('oidc-nonce');
|
|
|
|
|
|
|
|
|
|
|
|
yield put(replace(Paths.LOGIN));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (code !== null) {
|
|
|
|
if (code !== null) {
|
|
|
|
let accessToken;
|
|
|
|
let accessToken;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
({ item: accessToken } = yield call(api.exchangeToAccessToken, {
|
|
|
|
({ item: accessToken } = yield call(api.exchangeForAccessTokenUsingOidc, {
|
|
|
|
code,
|
|
|
|
code,
|
|
|
|
nonce,
|
|
|
|
nonce,
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
yield put(actions.authenticateWithOidc.failure(error));
|
|
|
|
yield put(actions.authenticateUsingOidc.failure(error));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
yield call(setAccessToken, accessToken);
|
|
|
|
yield call(setAccessToken, accessToken);
|
|
|
|
yield put(actions.authenticateWithOidc.success(accessToken));
|
|
|
|
yield put(actions.authenticateUsingOidc.success(accessToken));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -96,7 +97,7 @@ export function* clearAuthenticateError() {
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
initializeLogin,
|
|
|
|
initializeLogin,
|
|
|
|
authenticate,
|
|
|
|
authenticate,
|
|
|
|
authenticateWithOidc,
|
|
|
|
authenticateUsingOidc,
|
|
|
|
authenticateWithOidcCallback,
|
|
|
|
authenticateUsingOidcCallback,
|
|
|
|
clearAuthenticateError,
|
|
|
|
clearAuthenticateError,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|