Skip to content

[HELP | BUG] Multiple OAUTH2 schemes for different user types #11492

Discussion options

You must be logged in to vote

Hi!
That's because if you don't specify scheme_name for security scheme, FastAPI uses it's class name as a default value. And it's 'OAuth2PasswordBearer' for both of them.

self.scheme_name = scheme_name or self.__class__.__name__

Just specify scheme_name parameter:

oauth2_scheme_recruit = OAuth2PasswordBearer(tokenUrl="/auth/recruit/token", scheme_name="oauth2_scheme_recruit")
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/token", scheme_name="oauth2_scheme")

There is a PR (#4791) that fixes the same issue in APIKey, but it should be slightly modified and merged.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by dharik-arsath
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants