Bearer token for keycloak
Hi, am a little lost with the documentation as there doesn't seem to be much information on how the login works for the keycloak abstraction. This was what my project was generated with:
I am also utilizing a simple-rest server.
Where does it store the auth token? And how can i pass this auth token in my simple-rest provider?
2 Replies
Hi @dion. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To handle authentication with Keycloak and ensure that the bearer token is passed in your
simple-rest
provider, you need to store the token and configure your axios
instance to include it in the headers for every request.
Here's how you can achieve this:
1. Store the Token: When you log in, you need to store the token in a place where it can be accessed later, such as localStorage
.
2. Configure Axios to Include the Token: Create a custom axios
instance and use an interceptor to add the token to the headers of every request.
3. Update the Data Provider: Pass the custom axios
instance to the simple-rest
data provider.
Here is an example based on the information provided:
Step 1: Store the Token
Modify your authProvider
to store the token in localStorage
when logging in:
Step 2: Configure Axios to Include the Token
Create a custom axios
instance and use an interceptor to add the token to the headers:
Step 3: Update the Data Provider
Pass the custom axios
instance to the simple-rest
data provider:
By following these steps, you ensure
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1120211410354446426> kapa.ai is still learning and improving, please let us know how it did by reacting below