Search code examples
pythonflaskpostmanhttp-headers

How to generate authorization request header?


How can I generate a authorization request header ?

I have read about authorization request header and I generated one using username and password in base 64, but when I pass it on request header it doesn't work ("error": "invalid_client).

Using Postman to make the request everything works :

POST /oauth/token
content-type: application/x-www-form-urlencoded
authorization: Basic M1g4Vlk2QllHOFFJTDA3amt1cWpsUnNKOmhoWkNlSEg0SzFuVVJ2VTZmNUs5MmFiTlNSN3h3ZlBCYVN6OXI1WG1pcDNZOGJCbA==
user-agent: PostmanRuntime/7.1.5
accept: */*
host: 127.0.0.1:5000
accept-encoding: gzip, deflate
content-length: 97

Obs ¹ : The api uses the password grant type and return a bearer token

Obs ² : When I generate a authorization request header using username and password (base64.b64encode(b'')) the lenght of the output is 20 characters


Solution

  • In Flask Authlib, you can define three types of Auth methods : client_secret_basic, client_secret_post and none, these types indicates witch parameters and how you need to pass them in headers. This is referente to RFC6749 spec.