Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1007 from navikt/logout-url-param
Browse files Browse the repository at this point in the history
Parameter for overstyring av utloggings-url
  • Loading branch information
anders-nom authored Aug 24, 2021
2 parents c05dcd1 + 8ade8de commit 6fb4a48
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY##*/})" >> $GITHUB_ENV
echo "IMAGE_VERSION=${IMAGE_VERSION_RAW,,}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=$(echo ${GITHUB_TOKEN})" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY##*/})" >> $GITHUB_ENV
echo "IMAGE_VERSION=${IMAGE_VERSION_RAW,,}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=$(echo ${GITHUB_TOKEN})" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.q0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY##*/})" >> $GITHUB_ENV
echo "IMAGE_VERSION=${IMAGE_VERSION_RAW,,}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=$(echo ${GITHUB_TOKEN})" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.q1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY##*/})" >> $GITHUB_ENV
echo "IMAGE_VERSION=${IMAGE_VERSION_RAW,,}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=$(echo ${GITHUB_TOKEN})" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.q2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY##*/})" >> $GITHUB_ENV
echo "IMAGE_VERSION=${IMAGE_VERSION_RAW,,}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=$(echo ${GITHUB_TOKEN})" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.q6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY##*/})" >> $GITHUB_ENV
echo "IMAGE_VERSION=${IMAGE_VERSION_RAW,,}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=$(echo ${GITHUB_TOKEN})" >> $GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,16 @@ Dekoratøren kan tilpasses med følgende [URL-parametere / query-string](https:/
| urlLookupTable | boolean | true | Aktiverer eller deaktiverer url-lookup-table [7] |
| shareScreen | boolean | true | Aktiverer eller deaktiverer skjerdelingskomponent |
| utloggingsvarsel | boolean | false(prod)/true(dev) | Aktiverer eller deaktiverer Utloggingsvarsel for login-token (5min left) |
| logoutUrl | string | undefined | Setter url for logg-ut knappen |

[1] Kombineres med **level**, **redirectToApp** og [EnforceLoginLoader](https://github.com/navikt/nav-dekoratoren-moduler#readme) ved behov. <br>
[2] Gjelder både ved automatisk innlogging og ved klikk på innloggingsknappen. <br>
[3] Språk settes automatisk client-side dersom nåværende url inneholder **/nb/**, **/nn/**, **/en/**, **/se/**, uavhengig av dette parameteret. <br>
[4] Kan settes client-side med [setAvailableLanguages](https://github.com/navikt/nav-dekoratoren-moduler#readme) og [onLanguageSelect](https://github.com/navikt/nav-dekoratoren-moduler#readme) <br>
[5] Kan settes client-side med [setBreadcrumbs](https://github.com/navikt/nav-dekoratoren-moduler#readme) og [onBreadcrumbClick](https://github.com/navikt/nav-dekoratoren-moduler#readme) <br>
[6] Dersom en chat-sesjon er aktiv, så vil denne holdes i gang på alle sider på nav.no, uavhengig av dette parameteret. <br>
[7] Mapper prod-urler til dev-urler basert på [url-lookup-table](https://github.com/navikt/nav-dekoratoren-moduler/blob/master/src/csr/url-lookup-table/table.ts).
[7] Mapper prod-urler til dev-urler basert på [url-lookup-table](https://github.com/navikt/nav-dekoratoren-moduler/blob/master/src/csr/url-lookup-table/table.ts). <br>
[8] Dersom denne er satt vil dekoratørens utloggingsfunksjonalitet forbigåes, og **alt rundt utlogging må håndteres av appen.**

:information_source: &nbsp; Samtlige parameter kan settes [client-side](https://github.com/navikt/nav-dekoratoren-moduler#readme) <br>
:information_source: &nbsp; Bakgrunnsfarge på brødsmulesti og språkvelger kan overstyres:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nav-dekoratoren",
"version": "1.32.13-prod",
"version": "1.32.15-test",
"private": true,
"scripts": {
"start": "npm-run-all -p -r build-and-watch start-server-and-watch typecheck-watch",
Expand Down
4 changes: 2 additions & 2 deletions src/komponenter/common/utloggingsvarsel/Utloggingsvarsel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UtloggingsvarselInnhold from './komponenter/UtloggingsvarselInnhold';
import { AppState } from '../../../store/reducers';
import { useSelector } from 'react-redux';
import { useInterval } from './useInterval';
import { getLogOutUrl } from 'utils/login';

const stateSelector = (state: AppState) => ({
utloggingsvarsel: state.environment.PARAMS.UTLOGGINGSVARSEL,
Expand All @@ -19,7 +20,6 @@ const stateSelector = (state: AppState) => ({

const Utloggingsvarsel: FunctionComponent = () => {
const { utloggingsvarsel, timestamp, environment } = useSelector(stateSelector);
const { LOGOUT_URL } = environment;
const cls = BEMHelper('utloggingsvarsel');
const windowOnMount = () =>
verifyWindowObj() && window.innerWidth > BREAKPOINT ? WindowType.DESKTOP : WindowType.MOBILE;
Expand Down Expand Up @@ -57,7 +57,7 @@ const Utloggingsvarsel: FunctionComponent = () => {
const tokenExpire = unixTimeStamp - getCurrentTimeStamp();
if (timeStampIkkeUtgatt(getCurrentTimeStamp() - unixTimeStamp + 1)) {
setInterval(false);
window.location.href = LOGOUT_URL;
window.location.href = getLogOutUrl(environment);
}

if (tokenExpire <= 60) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { FunctionComponent } from 'react';
import { Knapp } from 'nav-frontend-knapper';
import BEMHelper from '../../../../utils/bem';
import { useSelector } from 'react-redux';
import { getLoginUrl } from '../../../../utils/login';
import { AppState } from '../../../../store/reducers';
import { getLoginUrl, getLogOutUrl } from 'utils/login';
import { AppState } from 'store/reducers';

interface Props {
minimized: boolean;
Expand All @@ -19,7 +19,6 @@ const UtloggingsvarselValg: FunctionComponent<Props> = (props) => {
const { minimized } = props;

const { arbeidsflate, environment } = useSelector(stateSelector);
const { LOGOUT_URL } = environment;
const LOGIN_URL = getLoginUrl(environment, arbeidsflate);

return (
Expand All @@ -37,7 +36,7 @@ const UtloggingsvarselValg: FunctionComponent<Props> = (props) => {
type="hoved"
tabIndex={minimized ? -1 : 0}
onClick={() => {
window.location.href = LOGOUT_URL;
window.location.href = getLogOutUrl(environment);
}}
>
logg ut
Expand Down
58 changes: 39 additions & 19 deletions src/komponenter/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ import { BrowserSupportMsg } from 'komponenter/header/header-regular/common/brow
import { getLoginUrl } from 'utils/login';
import Driftsmeldinger from './common/driftsmeldinger/Driftsmeldinger';
import Brodsmulesti from './common/brodsmulesti/Brodsmulesti';
import { msgSafetyCheck, postMessageToApp } from '../../utils/messages';
import { msgSafetyCheck, postMessageToApp } from 'utils/messages';
import { SprakVelger } from './common/sprakvelger/SprakVelger';
import { validateAvailableLanguages, validateUtilsBackground } from '../../server/utils';
import { validateBreadcrumbs } from '../../server/utils';
import { validateContext } from '../../server/utils';
import { validateLanguage, validateLevel } from '../../server/utils';
import { setParams } from '../../store/reducers/environment-duck';
import {
validateAvailableLanguages,
validateUtilsBackground,
validateLogoutUrl,
validateBreadcrumbs,
validateContext,
validateLanguage,
validateLevel,
} from '../../server/utils';
import { setParams } from 'store/reducers/environment-duck';
import Modal from 'nav-frontend-modal';
import { getUrlFromLookupTable } from '@navikt/nav-dekoratoren-moduler';
import cls from 'classnames';
Expand Down Expand Up @@ -227,11 +232,26 @@ export const Header = () => {
const { source, event, payload } = data;
if (isSafe) {
if (source === 'decoratorClient' && event === 'params') {
const { simple, context, level, language } = payload;
const { availableLanguages, breadcrumbs } = payload;
const { enforceLogin, redirectToApp } = payload;
const { feedback, chatbot, shareScreen } = payload;
const { utilsBackground, utloggingsvarsel } = payload;
const {
simple,
context,
level,
language,
availableLanguages: languagesFromPayload,
breadcrumbs: breadcrumbsFromPayload,
enforceLogin,
redirectToApp,
feedback,
chatbot,
shareScreen,
utilsBackground,
utloggingsvarsel,
logoutUrl,
} = payload;

if (logoutUrl) {
validateLogoutUrl(logoutUrl);
}
if (context) {
validateContext(context);
setContext(context);
Expand All @@ -243,11 +263,11 @@ export const Header = () => {
if (level) {
validateLevel(level);
}
if (availableLanguages) {
validateAvailableLanguages(availableLanguages);
if (languagesFromPayload) {
validateAvailableLanguages(languagesFromPayload);
}
if (breadcrumbs) {
validateBreadcrumbs(breadcrumbs);
if (breadcrumbsFromPayload) {
validateBreadcrumbs(breadcrumbsFromPayload);
}
if (utilsBackground) {
validateUtilsBackground(utilsBackground);
Expand All @@ -271,11 +291,11 @@ export const Header = () => {
...(language && {
LANGUAGE: language,
}),
...(availableLanguages && {
AVAILABLE_LANGUAGES: availableLanguages,
...(languagesFromPayload && {
AVAILABLE_LANGUAGES: languagesFromPayload,
}),
...(breadcrumbs && {
BREADCRUMBS: breadcrumbs,
...(breadcrumbsFromPayload && {
BREADCRUMBS: breadcrumbsFromPayload,
}),
...(feedback !== undefined && {
FEEDBACK: feedback === true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnalyticsCategory, analyticsEvent } from 'utils/analytics';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
import KnappBase from 'nav-frontend-knapper';
import { getLoginUrl } from 'utils/login';
import { getLoginUrl, getLogOutUrl } from 'utils/login';
import './LoggInnKnapp.less';

export const loginKnappId = 'login-knapp-id';
Expand All @@ -17,29 +17,19 @@ const stateSelector = (state: AppState) => ({
});

export const LoggInnKnapp = () => {
const { authenticated, arbeidsflate, language, environment } = useSelector(
stateSelector
);
const { authenticated, arbeidsflate, language, environment } = useSelector(stateSelector);

const handleButtonClick = () => {
const { LOGOUT_URL } = environment;
const loginUrl = getLoginUrl(environment, arbeidsflate);

analyticsEvent({
context: arbeidsflate,
category: AnalyticsCategory.Header,
action: authenticated ? 'logg-ut' : 'logg-inn',
});

return authenticated
? (window.location.href = LOGOUT_URL)
: (window.location.href = loginUrl);
window.location.href = authenticated ? getLogOutUrl(environment) : getLoginUrl(environment, arbeidsflate);
};

const knappetekst = finnTekst(
authenticated ? 'logg-ut-knapp' : 'logg-inn-knapp',
language
);
const knappetekst = finnTekst(authenticated ? 'logg-ut-knapp' : 'logg-inn-knapp', language);

return (
<div className={'login-knapp-container'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ import { AppState } from 'store/reducers';
import { useSelector } from 'react-redux';
import { Undertittel, Ingress } from 'nav-frontend-typografi';
import LoggutIkonMobil from 'ikoner/meny/LoggutIkonMobil';
import { getLogOutUrl } from 'utils/login';
import './InnloggetBruker.less';

const cls = BEMHelper('innloggetbruker');

const stateSelector = (state: AppState) => ({
innlogget: state.innloggingsstatus,
environment: state.environment,
});

const loggut = (LOGOUT_URL: string) => {
return (window.location.href = LOGOUT_URL);
const loggut = (logoutUrl: string) => {
window.location.href = logoutUrl;
};

const InnloggetBruker = () => {
const { LOGOUT_URL } = useSelector((state: AppState) => state.environment);
const { innlogget } = useSelector(stateSelector);
const { innlogget, environment } = useSelector(stateSelector);
return innlogget.data.authenticated ? (
<div className={cls.className}>
<div className={cls.element('label')}>
Expand All @@ -30,10 +31,7 @@ const InnloggetBruker = () => {
<div className={cls.element('bruker')}>
<Ingress>{innlogget.data.name.toLowerCase()}</Ingress>
</div>
<button
className={cls.element('loggut')}
onClick={() => loggut(LOGOUT_URL)}
>
<button className={cls.element('loggut')} onClick={() => loggut(getLogOutUrl(environment))}>
<LoggutIkonMobil />
<div className={cls.element('loggut', 'text')}>
<Ingress>
Expand Down
17 changes: 14 additions & 3 deletions src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export const clientEnv = ({ req, cookies }: Props): Environment => {
SHARE_SCREEN: req.query.shareScreen !== 'false',
UTLOGGINGSVARSEL: utloggingsvarsel.UTLOGGINGSVARSEL,
TIMESTAMP: utloggingsvarsel.TIMESTAMP,
...(req.query.logoutUrl && {
LOGOUT_URL: req.query.logoutUrl as string,
}),
},
}),
...(cookies && {
Expand Down Expand Up @@ -108,9 +111,7 @@ const getutloggingsvarsel = (req: Request, cookies: Cookies): { UTLOGGINGSVARSEL

// Validation utils
export const validateClientEnv = (req: Request) => {
const { level, context } = req.query;
const { availableLanguages, breadcrumbs } = req.query;
const { utilsBackground } = req.query;
const { level, context, availableLanguages, breadcrumbs, utilsBackground, logoutUrl } = req.query;
if (context) {
validateContext(context as string);
}
Expand All @@ -130,6 +131,16 @@ export const validateClientEnv = (req: Request) => {
if (utilsBackground) {
validateUtilsBackground(utilsBackground as string);
}
if (logoutUrl) {
validateLogoutUrl(logoutUrl as string);
}
};

export const validateLogoutUrl = (url: string) => {
if (!isNavUrl(url)) {
const error = `logoutUrl supports only nav.no urls - failed to validate ${url}`;
throw Error(error);
}
};

export const validateContext = (context: string) => {
Expand Down
1 change: 1 addition & 0 deletions src/store/reducers/environment-duck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface Params {
UTILS_BACKGROUND?: string;
UTLOGGINGSVARSEL: boolean;
TIMESTAMP: number;
LOGOUT_URL?: string;
}

export interface Cookies {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export const getLoginUrl = (environment: Environment, arbeidsflate: MenuValue) =
: `${LOGIN_URL}/login?redirect=${DITT_NAV_URL}`
}&level=${PARAMS.LEVEL}`;
};

export const getLogOutUrl = (environment: Environment) => environment.PARAMS.LOGOUT_URL || environment.LOGOUT_URL;

0 comments on commit 6fb4a48

Please sign in to comment.