Authenticate with Bearer token in header #1130
Replies: 4 comments
-
one of options:
then each |
Beta Was this translation helpful? Give feedback.
-
Does the library contain functionality to automatically retrieve a new token? I got a JWT here with an expiry of 1800 seconds. Do I need to implement custom checks for this, or can the generated library handle this? |
Beta Was this translation helpful? Give feedback.
-
With some small tweaks to the above example, this worked for me:
|
Beta Was this translation helpful? Give feedback.
-
@holwech Thank you very much for this solution! This works perfectly with a token function that returns a promise! Auth0 example: //index.ts
import { Api } from './types/api-types';
import { useAuth0 } from '@auth0/auth0-vue';
export * from './types/api-types';
const apiClient = new Api({
secure: true,
baseURL: import.meta.env.VITE_BASE_URL,
securityWorker: async () => {
const { isAuthenticated, getAccessTokenSilently } = useAuth0();
return isAuthenticated
? {
headers: {
Authorization: `Bearer ${await getAccessTokenSilently()}`,
},
}
: {};
},
});
export { apiClient }; |
Beta Was this translation helpful? Give feedback.
-
I generated a client library for a swagger file that suggests the API required a JWT Bearer token.
I can't see to figure out how to supply this bearer token \ header to the client library such that it sends it to the server.
Can someone please point me at an example?
Beta Was this translation helpful? Give feedback.
All reactions