mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Auth: Only call rotate token if we have a session expiry cookie (#84169)
Only call rotate token if we have a session expiry cookie
This commit is contained in:
parent
0913324668
commit
4272483c54
@ -19,7 +19,7 @@ import { AppEvents, DataQueryErrorType } from '@grafana/data';
|
|||||||
import { BackendSrv as BackendService, BackendSrvRequest, config, FetchError, FetchResponse } from '@grafana/runtime';
|
import { BackendSrv as BackendService, BackendSrvRequest, config, FetchError, FetchResponse } from '@grafana/runtime';
|
||||||
import appEvents from 'app/core/app_events';
|
import appEvents from 'app/core/app_events';
|
||||||
import { getConfig } from 'app/core/config';
|
import { getConfig } from 'app/core/config';
|
||||||
import { getSessionExpiry } from 'app/core/utils/auth';
|
import { getSessionExpiry, hasSessionExpiry } from 'app/core/utils/auth';
|
||||||
import { loadUrlToken } from 'app/core/utils/urlToken';
|
import { loadUrlToken } from 'app/core/utils/urlToken';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state';
|
import { DashboardModel } from 'app/features/dashboard/state';
|
||||||
import { DashboardSearchItem } from 'app/features/search/types';
|
import { DashboardSearchItem } from 'app/features/search/types';
|
||||||
@ -390,11 +390,12 @@ export class BackendSrv implements BackendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let authChecker = this.loginPing();
|
let authChecker = this.loginPing();
|
||||||
|
if (hasSessionExpiry()) {
|
||||||
const expired = getSessionExpiry() * 1000 < Date.now();
|
const expired = getSessionExpiry() * 1000 < Date.now();
|
||||||
if (expired) {
|
if (expired) {
|
||||||
authChecker = this.rotateToken();
|
authChecker = this.rotateToken();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return from(authChecker).pipe(
|
return from(authChecker).pipe(
|
||||||
catchError((err) => {
|
catchError((err) => {
|
||||||
|
@ -86,6 +86,11 @@ const getTestContext = (overides?: object, mockFromFetch = true) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jest.mock('app/core/utils/auth', () => ({
|
||||||
|
getSessionExpiry: () => 1,
|
||||||
|
hasSessionExpiry: () => true,
|
||||||
|
}));
|
||||||
|
|
||||||
describe('backendSrv', () => {
|
describe('backendSrv', () => {
|
||||||
describe('parseRequestOptions', () => {
|
describe('parseRequestOptions', () => {
|
||||||
it.each`
|
it.each`
|
||||||
|
@ -11,3 +11,7 @@ export function getSessionExpiry() {
|
|||||||
|
|
||||||
return parseInt(expiresStr, 10);
|
return parseInt(expiresStr, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasSessionExpiry() {
|
||||||
|
return document.cookie.split('; ').findIndex((row) => row.startsWith('grafana_session_expiry=')) > -1;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user