fix auth redirect
add token to requests
This commit is contained in:
parent
8cdcb6620f
commit
093cdb97e7
@ -16,13 +16,6 @@ export const keycloakConfig: AuthProviderProps = {
|
|||||||
authority: oidpSettings.server,
|
authority: oidpSettings.server,
|
||||||
client_id: oidpSettings.clientId,
|
client_id: oidpSettings.clientId,
|
||||||
redirect_uri: hostURL.toString(),
|
redirect_uri: hostURL.toString(),
|
||||||
onSigninCallback: () => {
|
|
||||||
window.history.replaceState(
|
|
||||||
{},
|
|
||||||
document.title,
|
|
||||||
window.location.pathname
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootStore = new RootStore()
|
const rootStore = new RootStore()
|
||||||
@ -41,6 +34,4 @@ root.render(
|
|||||||
// If you want to start measuring performance in your app, pass a function
|
// If you want to start measuring performance in your app, pass a function
|
||||||
// to log results (for example: reportWebVitals(console.log))
|
// to log results (for example: reportWebVitals(console.log))
|
||||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||||
reportWebVitals();
|
reportWebVitals();
|
||||||
|
|
||||||
|
|
||||||
@ -10,12 +10,31 @@ import { FrigateConfig } from "../../types/frigateConfig";
|
|||||||
import { url } from "inspector";
|
import { url } from "inspector";
|
||||||
import { RecordSummary } from "../../types/record";
|
import { RecordSummary } from "../../types/record";
|
||||||
import { EventFrigate } from "../../types/event";
|
import { EventFrigate } from "../../types/event";
|
||||||
|
import { keycloakConfig } from "../..";
|
||||||
|
|
||||||
|
|
||||||
|
const getToken = (): string | undefined => {
|
||||||
|
const key = `oidc.user:${keycloakConfig.authority}:${keycloakConfig.client_id}`;
|
||||||
|
const stored = sessionStorage.getItem(key);
|
||||||
|
const storedObject = stored ? JSON.parse(stored) : null;
|
||||||
|
return storedObject?.access_token;
|
||||||
|
}
|
||||||
|
|
||||||
const instanceApi = axios.create({
|
const instanceApi = axios.create({
|
||||||
baseURL: proxyURL.toString(),
|
baseURL: proxyURL.toString(),
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
});
|
})
|
||||||
|
|
||||||
|
instanceApi.interceptors.request.use(
|
||||||
|
config => {
|
||||||
|
const token = getToken();
|
||||||
|
if (token) {
|
||||||
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
error => Promise.reject(error)
|
||||||
|
);
|
||||||
|
|
||||||
export const frigateApi = {
|
export const frigateApi = {
|
||||||
getConfig: () => instanceApi.get<GetConfig[]>('apiv1/config').then(res => res.data),
|
getConfig: () => instanceApi.get<GetConfig[]>('apiv1/config').then(res => res.data),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user