Building the authorization code flow
If the application is a public type and there is no authorization server to process the client_id
parameter, the client_secret
parameter, and other related parameters, this OAuth2 authorization code flow approach is appropriate to use. In this scheme, the client creates an authorization request for a short-lived authorization code from an authorizationUrl
. The client will then ask for the token from tokenUrl
in exchange for the generated code. In this discussion, we will be showcasing another version of our online auction system that will use the OAuth2 authorization code flow scheme.
Applying OAuth2AuthorizationCodeBearer
The OAuth2AuthorizationCodeBearer
class is a class from the fastapi.security
module that builds the authorization code flow. Its constructor requires authorizationUrl
, tokenUrl
, and the optional scopes
before instantiation. The following code shows how this API class is created before its injection into the get_current_user...