Auth: Allow soft token revocation (#31601)

* Add revoked_at field to user auth token to allow soft revokes

* Allow soft token revocations

* Update token revocations and tests

* Return error info on revokedTokenErr

* Override session cookie only when no revokedErr nor API request

* Display modal on revoked token error

* Feedback: Refactor TokenRevokedModal to FC

* Add GetUserRevokedTokens into UserTokenService

* Backendsrv: adds tests and refactors soft token path

* Apply feedback

* Write redirect cookie on token revoked error

* Update TokenRevokedModal style

* Return meaningful error info

* Some UI changes

* Update backend_srv tests

* Minor style fix on backend_srv tests

* Replace deprecated method usage to publish events

* Fix backend_srv tests

* Apply suggestions from code review

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com>

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com>

* Minor style fix after PR suggestion commit

* Apply suggestions from code review

Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>

* Prettier fixes

Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com>
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>
This commit is contained in:
Joan López de la Franca Beltran
2021-03-16 17:44:02 +01:00
committed by GitHub
co-authored by Alex Khomenko Hugo Häggmark Ursula Kallio
parent a1c7e0630d
commit 610999cfa2
13 changed files with 286 additions and 30 deletions
@@ -0,0 +1,66 @@
import React from 'react';
import { Button, InfoBox, Portal, stylesFactory, useTheme } from '@grafana/ui';
import { getModalStyles } from '@grafana/ui/src/components/Modal/getModalStyles';
import { css, cx } from 'emotion';
import { GrafanaTheme } from '@grafana/data';
interface Props {
maxConcurrentSessions?: number;
}
export const TokenRevokedModal = (props: Props) => {
const theme = useTheme();
const styles = getStyles(theme);
const modalStyles = getModalStyles(theme);
const showMaxConcurrentSessions = Boolean(props.maxConcurrentSessions);
const redirectToLogin = () => {
window.location.reload();
};
return (
<Portal>
<div className={modalStyles.modal}>
<InfoBox title="You have been automatically signed out" severity="warning" className={styles.infobox}>
<div className={styles.text}>
<p>
Your session token was automatically revoked because you have reached
<strong>
{` the maximum number of ${
showMaxConcurrentSessions ? props.maxConcurrentSessions : ''
} concurrent sessions `}
</strong>
for your account.
</p>
<p>
<strong>To resume your session, sign in again.</strong>
Contact your administrator or visit the license page to review your quota if you are repeatedly signed out
automatically.
</p>
</div>
<Button size="md" variant="primary" onClick={redirectToLogin}>
Sign in
</Button>
</InfoBox>
</div>
<div className={cx(modalStyles.modalBackdrop, styles.backdrop)} />
</Portal>
);
};
const getStyles = stylesFactory((theme: GrafanaTheme) => {
return {
infobox: css`
margin-bottom: 0;
`,
text: css`
margin: ${theme.spacing.sm} 0 ${theme.spacing.md};
`,
backdrop: css`
background-color: ${theme.colors.dashboardBg};
opacity: 0.8;
`,
};
});