Support HMAC authorization schemes
See original GitHub issueHi RTK Team. First off, I’m a big fan of rtk, and excited for the direction this project is heading in. Thank you for your efforts!
Currently, prepareHeaders
has this signature1:
;(
headers: Headers,
api: {
getState: () => unknown
extra: unknown
endpoint: string
type: 'query' | 'mutation'
forced: boolean | undefined
}
) => Headers
Problem:
HMAC authorization schemes typically involve hashing the request method, path, query params, and body (among others) and adding the hash result as an authorization header2.
Ideally, the mentioned values would be available to consumers within the prepareHeaders
function
Proposal:
Add params to prepareHeaders
at call time
config
(https://github.com/reduxjs/redux-toolkit/blob/v1.8.1/packages/toolkit/src/query/fetchBaseQuery.ts#L197). This gives access to the requestbody
andmethod
url
(https://github.com/reduxjs/redux-toolkit/blob/v1.8.1/packages/toolkit/src/query/fetchBaseQuery.ts#L191). This allows parsing outhost
and/orpath
params
https://github.com/reduxjs/redux-toolkit/blob/v1.8.1/packages/toolkit/src/query/fetchBaseQuery.ts#L192. This allows parsing outquery
params
Issues
There isn’t an HMAC ‘spec’ that I’m aware of, so different implementations end up wanting different parts of the request details hashed. I think the above proposal covers the common implementation areas but its likely not 100%
References:
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Guide on implementing HMAC scheme to protect API requests
In this guide you'll learn about an important authentication scheme called HMAC - what is it, its advantages, things to consider while ...
Read more >What is HMAC Authentication and why is it useful?
Hash-based message authentication code (HMAC) is a mechanism for calculating a message authentication code involving a hash function in ...
Read more >Azure App Configuration REST API - HMAC authentication
You can authenticate HTTP requests by using the HMAC-SHA256 authentication scheme. (HMAC refers to hash-based message authentication code.) ...
Read more >HMAC Authentication in Web API - Dot Net Tutorials
The HMAC stands for Hash-based Message Authentication Code. From the full form of HMAC, we need to understand two things one is Message...
Read more >Specifying HMAC-based authentication in the spec #344
The current spec (v2.0) defines three valid security schemes: basic HTTP authentication, authentication using an API key, and Oauth2.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vanities
args.headers = { ...args.headers, FooBarHeader: "fooBar!" }
Sounds like this has been addressed, so I’ll close this.