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.

[QUESTION] - How does Oauth2 (Bearer token) work when getting access_token?

See original GitHub issue

First check

  • 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.

Description

I will start off by saying I have followed a guide of how to make a secure API using FastAPI (https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/).

What happens is that you will have two api which one is post and get

POST is where you pass the

curl -X POST "http://127.0.0.1:8000/token" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=&username=hello&password=world&scope=&client_id=&client_secret="

GET is an api that requires the access_token Bearer to be able to access the API etc http://127.0.0.1:8000/getUser

Now I am pretty confused on how safe you can run the application because what makes me confused is that I would need to make a POST request with my username and password to the API which will return me access_token and I believe with that access_token I later on access the next api which is http://127.0.0.1:8000/getUser? Is this the correct way or am I out of scope?

Because what makes me unsafe is that if I now lets say “hardcode” my username and password into a python script and someone manages to reverese engineer the script/exe/whatever (Maybe even see through network what is sending as params/data)- they will be able to access my token in that case. So what would be the suggestion here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shifrcommented, Dec 18, 2019

Indeed, I assume a better way is to connect to etc mongodb where you store your username and password instead for example?

Sure, in the example https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/ you can see fake_users_db - it’s like a projection of the real database where you can store your users, but simplified for the tutorial purposes.

0reactions
github-actions[bot]commented, Feb 23, 2020

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Bearer token and How it works? - DevOpsSchool.com
How bearer token works? ... The Bearer Token is created for you by the Authentication server. When a user authenticates your application (client) ......
Read more >
Bearer Tokens - OAuth 2.0 Simplified
The most common way of accessing OAuth 2.0 APIs is using a “Bearer Token”. This is a single string which acts as the...
Read more >
ID Token and Access Token: What Is the Difference? - Auth0
In the OAuth 2 context, the access token allows a client application to access a specific resource to perform specific actions on behalf...
Read more >
Spring Boot OAuth2 Part 2 - Getting the Access Token and ...
As can be seen the authorization code is received as a request parameter. And the resource server is trying to contact the client...
Read more >
OAuth 2 Access Token Usage Strategies for Multiple ...
One key question we explore in this blog post series is: Should the application obtain a single access token that is used against...
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