[QUESTION] Can OAuth login via Json data instead of Form?
See original GitHub issueDescription
I want to use the jwt auth, and learn the tutorial about it. There are sth confused me:
@router.post('/token')
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
user = await authenticate_user(form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail='incorrect username')
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = await create_access_token(data={'sub': user.username}, expires_delta=access_token_expires)
return {'access_token': access_token, 'token_type': 'bearer'}
If login success, the token will be returned , and next time you send other request need auth like
oauth2_scheme = OAuth2PasswordBearer(tokenUrl='/token')
async def get_current_user(token: str=Depends(oauth2_scheme)):
pass
- How does it works the next request was added a header with Authorization: Bear automically? Where does the token returned stored?
- When I replace the Form with json, the following requests after login are failing to be with Auth Header
async def login(user_data: schemas.UserLogin):
pass
I am sorry about my English and less experience about auth in Web, wish you could solve my confusion. Thanks in advance.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Return RESTful/json response instead of login form in Spring ...
When I do a get request using the browser or postman, I receive back the default spring HTML login form. security.basic.enabled=true. I'm using...
Read more >Using OAuth 2.0 for Server to Server Applications | Authorization
This document describes how an application can complete the server-to-server OAuth 2.0 flow by using either a Google APIs client library ( ...
Read more >[SOLVED] Receiving oAuth POST Response - Comes back as ...
BigCommerce Developers — Morgan Wowk (Partner) asked a question. ... [SOLVED] Receiving oAuth POST Response - Comes back as BC Login instead of...
Read more >What the Heck is OAuth? - Okta Developer
The OAuth spec doesn't define what a token is. It can be in whatever format you want. Usually though, you want these tokens...
Read more >JSON Web Token Tutorial using AngularJS & Laravel - Toptal
(You can use a JSON formatter tool to prettify the JSON object.) ... the username and password data from the sign-in and sign-up...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Look inside the
OAuth2PasswordRequestForm
– form fields are described there. You can replace this class with your own, acceptingapplication/json
instead ofapplication/x-www-form-urlencoded
.@dmig-alarstudios I have a requirement where frontend is posting content using content-type = “application/json”. Due to OAuth2PasswordRequestForm,I am getting error as “username field required”.
Is there a way to add support of application/json or any middleware to convert incoming json to www-form-urlencoded? I am in situation that either frontend works (with custom class) or swagger works with OAuth2PasswordRequestForm.