Is it possible to change the header where the auth...
# support-questions-legacy
t
Is it possible to change the header where the authorization bearer is placed? E.g. use st-authorization instead of authorization
r
Hey. You can do this by writing your own interceptors on the frontend for XHR / fetch that changes the header used to your custom one
Then on the backend, you can use the getSessionWithoutRequestResponse instead of using verifySession or getSession functions
t
Thanks I checked the docs. But how can I use this for the SDK API like signup etc?
r
thats where your interceptors come in
your interceptors should be added to fetch / XHR before calling supertokens.init on the frontend
and so API calls that go through our sdk, will go through your interceptors which will modify the header
t
I mean on the backend, sorry
r
so to the backend supertokens middleware, you give the request / response object (based on your frameworks). You can make your own request / response wrappers that conform with our BaseReqeust (https://github.com/supertokens/supertokens-node/blob/master/lib/ts/framework/request.ts) and BaseResponse (https://github.com/supertokens/supertokens-node/blob/master/lib/ts/framework/response.ts) types, and then pass those to the middleware. In those custom wrappers, when a function like getHeaderValue(key) is called, you should check if the key is
authorization
and if it is, read from your custom header instead.
t
Thanks, but it is still not very clear where I should do this. I use python with flask, I think I have to overwrite the class Middleware in supertokens_python/framework/flask/flask_middleware.py?
r
right yea, i don't think you can override that particular function - but you can copy it into your code base and use that instead of ours. And then wherever in the function we are wrapping the flask request with our wrapper impl, you should wrap it instead with your wrapper impl
t
Yes I thought about copy pasting it. I found cookie_and_header.py:get_token(). I think in python I could patch just this function to extract the token not from AUTHORIZATION_HEADER but something else
r
oh yea. I guess that would be the best way. But im not sure how you could patch that function specifically.
t
I thought about monkey patch it like cookie_and_header.get_token = my_func
not totally sure if this works for modules
r
you could do that. However, that's an internal function. So patch updates might break your code
So i would still recommend to go the route of a custom request wrapper
t
Indeed. Though already thanks for the help
I noticed that verify_session creates it's own Request object from the flask request. So it is not enough to write a custom wrapper in the Middleware class.
But I could modify the original flask request object like this: request.headers.environ["HTTP_AUTHORIZATION"] = request.headers.environ.pop("HTTP_ST_AUTHORIZATION")
r
Right. Verify session is another middleware which you would have to copy (just like the supertokens middleware)
However, what you did is also fine I guess
t
Yeah, figured it out too, I have now overwritten verify session too.
4 Views