question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues in documentation page "Simple OAuth2 with Password and Bearer"

See original GitHub issue

First check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.
  • After submitting this, I commit to one of:
    • Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
    • I already hit the “watch” button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
    • Implement a Pull Request for a confirmed bug.

Description

In fastapi.security.oauth2.py, line 51 (OAuth2PasswordRequestForm class definition), it’s defined scope: str = Form(""). However, Form("") is not a str. Below, in line 58 we find:

self.scopes = scope.split()

This is compatible with the type but it’s incompatible with the default value, as Form has no split method.

I know I’m being just picky here, but in my efforts to understand the whole thing, I did:

from fastapi.security import OAuth2PasswordRequestForm
x = OAuth2PasswordRequestForm(username='johndoe', password='secret')

and I got:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\shared\workspaces\manager-westend\.venv\lib\site-packages\fastapi\security\oauth2.py", line 58, in __init__
    self.scopes = scope.split()
AttributeError: 'Form' object has no attribute 'split'

In order for it to run, I have to do:

from fastapi.security import OAuth2PasswordRequestForm
x = OAuth2PasswordRequestForm(username='johndoe', password='secret', scope='')

This is expected. So, the beginner’s question is: should the default value of scope not be "" instead of Form("")?

Is this a pull request, or just ignorance? Should I just stop poking around with dependency classes?

Environment

  • OS: Windows
  • FastAPI Version: 0.66.0
  • Python version: 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32

Footnote

On a somewhat related topic, it is not too clear to me why we need the get_current_user functionality. Is this just to serve the /users/me endpoint? I don’t see it impacting on the login process. I can still login as alice, just not do anything in there with her inactive.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ricardo-reis-1970commented, Aug 16, 2021

@Cosmicoppai, thank you. I believe that’s the explanation someone like me usually looks for.

0reactions
Cosmicoppaicommented, Aug 16, 2021

@Cosmicoppai, thank you. I believe that’s the explanation someone like me usually looks for.

I’m glad if it helped you. Have a great day ahead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple OAuth2 with Password and Bearer - FastAPI
OAuth2 specifies that when using the "password flow" (that we are using) the client/user must send a username and password fields as form...
Read more >
How is the access token stored on the client, in the ... - GitHub
I'm pretty new to FastAPI and OAuth in general. I just worked through the tutorial "Simple OAuth2 with Password and Bearer" and it...
Read more >
How is this access token stored on the client, in FastAPI's ...
I'm pretty new to FastAPI and OAuth2 in general. I just worked through the tutorial "Simple OAuth2 with Password and Bearer" and it...
Read more >
OAuth 2.0 Making requests on behalf of users | Docs
The userid and password are separated by a single colon (":") character within a base64 encoded string in the credentials. An example would...
Read more >
OAuth 2.0 - Swagger
implicit: # <---- OAuth flow(authorizationCode, implicit, password or clientCredentials); authorizationUrl: https://api.example.com/oauth2/authorize ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found