Description
I am working on implementing security for my web application with AWS Cognito. I've written a little Auth API that will return an access token for a given scope, and I would like to customize my endpoints so that they automatically add the Authorization header to the request with an appropriately scoped access token.
So, for instance, my endpoint for reading the schedule would need an access token with the scope "schedules.read".
Since I may need to asynchronously fetch the accessToken if a valid one for that scope isn't cached, I can't use the headers
property on the endpoint.
There is the prepareHeaders
function on the baseQuery which looks promising. However, I'd need a good way to inform that function of what scopes to request for the endpoint in question. Is there mechanism to add and retrieve metadata for endpoints that could be used in prepareHeaders
? Or a way to use an asynchronous function on the endpoint definition to set the headers?