Merge pull request #15181 from marefr/fix_ping_unauthorized
auth: /api/login/ping fixes
This commit is contained in:
+2
-2
@@ -108,8 +108,8 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
r.Get("/api/snapshots-delete/:deleteKey", Wrap(DeleteDashboardSnapshotByDeleteKey))
|
r.Get("/api/snapshots-delete/:deleteKey", Wrap(DeleteDashboardSnapshotByDeleteKey))
|
||||||
r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
|
r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
|
||||||
|
|
||||||
// api renew session based on remember cookie
|
// api renew session based on cookie
|
||||||
r.Get("/api/login/ping", quota("session"), hs.LoginAPIPing)
|
r.Get("/api/login/ping", quota("session"), Wrap(hs.LoginAPIPing))
|
||||||
|
|
||||||
// authed api
|
// authed api
|
||||||
r.Group("/api", func(apiRoute routing.RouteRegister) {
|
r.Group("/api", func(apiRoute routing.RouteRegister) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import coreModule from 'app/core/core_module';
|
import coreModule from 'app/core/core_module';
|
||||||
import appEvents from 'app/core/app_events';
|
import appEvents from 'app/core/app_events';
|
||||||
|
import config from 'app/core/config';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
||||||
|
|
||||||
export class BackendSrv {
|
export class BackendSrv {
|
||||||
@@ -103,10 +104,17 @@ export class BackendSrv {
|
|||||||
err => {
|
err => {
|
||||||
// handle unauthorized
|
// handle unauthorized
|
||||||
if (err.status === 401 && this.contextSrv.user.isSignedIn && firstAttempt) {
|
if (err.status === 401 && this.contextSrv.user.isSignedIn && firstAttempt) {
|
||||||
return this.loginPing().then(() => {
|
return this.loginPing()
|
||||||
options.retry = 1;
|
.then(() => {
|
||||||
return this.request(options);
|
options.retry = 1;
|
||||||
});
|
return this.request(options);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
if (err.status === 401) {
|
||||||
|
window.location.href = config.appSubUrl + '/logout';
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$timeout(this.requestErrorHandler.bind(this, err), 50);
|
this.$timeout(this.requestErrorHandler.bind(this, err), 50);
|
||||||
@@ -184,13 +192,20 @@ export class BackendSrv {
|
|||||||
|
|
||||||
// handle unauthorized for backend requests
|
// handle unauthorized for backend requests
|
||||||
if (requestIsLocal && firstAttempt && err.status === 401) {
|
if (requestIsLocal && firstAttempt && err.status === 401) {
|
||||||
return this.loginPing().then(() => {
|
return this.loginPing()
|
||||||
options.retry = 1;
|
.then(() => {
|
||||||
if (canceler) {
|
options.retry = 1;
|
||||||
canceler.resolve();
|
if (canceler) {
|
||||||
}
|
canceler.resolve();
|
||||||
return this.datasourceRequest(options);
|
}
|
||||||
});
|
return this.datasourceRequest(options);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
if (err.status === 401) {
|
||||||
|
window.location.href = config.appSubUrl + '/logout';
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// populate error obj on Internal Error
|
// populate error obj on Internal Error
|
||||||
|
|||||||
Reference in New Issue
Block a user