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 appEvents from 'app/core/app_events';
|
||||
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 { DashboardModel } from 'app/features/dashboard/state';
|
||||
import { DashboardSearchItem } from 'app/features/search/types';
|
||||
@ -390,10 +390,11 @@ export class BackendSrv implements BackendService {
|
||||
}
|
||||
|
||||
let authChecker = this.loginPing();
|
||||
|
||||
const expired = getSessionExpiry() * 1000 < Date.now();
|
||||
if (expired) {
|
||||
authChecker = this.rotateToken();
|
||||
if (hasSessionExpiry()) {
|
||||
const expired = getSessionExpiry() * 1000 < Date.now();
|
||||
if (expired) {
|
||||
authChecker = this.rotateToken();
|
||||
}
|
||||
}
|
||||
|
||||
return from(authChecker).pipe(
|
||||
|
@ -86,6 +86,11 @@ const getTestContext = (overides?: object, mockFromFetch = true) => {
|
||||
};
|
||||
};
|
||||
|
||||
jest.mock('app/core/utils/auth', () => ({
|
||||
getSessionExpiry: () => 1,
|
||||
hasSessionExpiry: () => true,
|
||||
}));
|
||||
|
||||
describe('backendSrv', () => {
|
||||
describe('parseRequestOptions', () => {
|
||||
it.each`
|
||||
|
@ -11,3 +11,7 @@ export function getSessionExpiry() {
|
||||
|
||||
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