-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b818466
commit c9e2efc
Showing
7 changed files
with
111 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
self.addEventListener('fetch', (e) => { | ||
var url = new URL(e.request.url); | ||
if ( | ||
url.origin.endsWith(".ideaconsult.net") | ||
&& (e.request.destination === 'image') | ||
&& isGeneratedImage(url) | ||
&& url.origin.startsWith("https://") | ||
&& (url.origin !== "https://iam.ideaconsult.net") | ||
&& (url.origin !== "https://idp.ideaconsult.net") | ||
&& (e.request.method == "GET") | ||
&& (e.request.headers["Authorization"] == undefined)) { | ||
e.respondWith(localStorage.getItem("token").then((value) => { | ||
var _headers = {}; | ||
var header = "Bearer "+value; | ||
_headers["Authorization"] = header; | ||
const newRequest = new Request(e.request, { | ||
headers : {"Authorization" : header}, | ||
mode: "cors" | ||
}); | ||
return fetch(newRequest); | ||
|
||
}) ) | ||
} else { | ||
return fetch(e.request); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useKeycloak } from '@react-keycloak/web'; | ||
|
||
const App = () => { | ||
const { keycloak } = useKeycloak(); | ||
const [token, setToken] = useState(null); | ||
const [isAuthenticated, setIsAuthenticated] = useState(false); | ||
|
||
useEffect(() => { | ||
if (keycloak && keycloak.authenticated) { | ||
setIsAuthenticated(true); | ||
setToken(keycloak.token); | ||
|
||
const intervalId = setInterval(() => { | ||
if (keycloak.isTokenExpired(30)) { | ||
keycloak.updateToken(30).then((refreshed) => { | ||
if (refreshed) { | ||
console.log('Token automatically refreshed'); | ||
setToken(keycloak.token); // Update token state | ||
} else { | ||
console.warn('Token still valid, no need to refresh'); | ||
} | ||
}).catch((error) => { | ||
console.error('Failed to refresh token', error); | ||
}); | ||
} | ||
}, 60000); // Check every 60 seconds | ||
|
||
return () => clearInterval(intervalId); // Cleanup on unmount | ||
} | ||
}, [keycloak]); | ||
|
||
return ( | ||
<div> | ||
<h1>ReactKeycloakProvider Token Management</h1> | ||
{isAuthenticated ? ( | ||
<div> | ||
<p>Authenticated! Token is available.</p> | ||
<pre>{token}</pre> | ||
</div> | ||
) : ( | ||
<p>Not authenticated</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |