Set variable from hook #212
CaptainQuirk
started this conversation in
General
Replies: 1 comment 2 replies
-
It should go easily. Just use requestHook and set your JWT Token as Variable. See Interfaces httpClientProvider and HttpHooksApi
module.exports = {
configureHooks: function (api) {
api.hooks.onRequest.addHook('jwt', async function (request, context) {
const response = await api.httpClientProvider.exchange({method: "POST", url: "/auth/token"}, {});
request.headers = Object.assign({
'Authorization': `Bearer ${response.parsedBody.access_token}',
}, request.headers);
context.variables.jwt = response.parsedBody.access_token;
});
}
} It may be easier to resolve it with |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi !
I would like to set a simple
jwt
variable as value of aAutorization: Bearer
header. My api does not use oauth2 and simply returns a token on aPOST /auth/token
endpoint.Is it possible to perform the call in a hook and set the value of the jwt variable there ?
Thanks in advance !
Beta Was this translation helpful? Give feedback.
All reactions