codemation / easyauth

Create a centralized Authentication and Authorization token server. Easily secure FastAPI endpoints based on Users, Groups, Roles or Permissions with very little database usage.
https://easyauth.readthedocs.io/en/latest/
MIT License
553 stars 52 forks source link

Python tool without service account #93

Closed remydewa closed 1 year ago

remydewa commented 1 year ago

Hello,

I want to know how can I have a python tools which give me access to my authenticated api without creating a service account.

Actually, what I'm trying to do:

req_header = {
        "Content-Type": "application/json"
    }

    req_body = {
            "username": "myuser",
            "password": "xxxx"
    }

resp = requests.post(
        "http://127.0.0.1:5858/auth/token",
        headers=req_header,
        json=req_body,
        verify=False
    )

The goal below is to get a token to access to my other api but it doesn't works:

{'detail': [{'loc': ['body', 'username'], 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ['body', 'password'], 'msg': 'field required', 'type': 'value_error.missing'}]}

What Am it doing wrong?

Thanks for your help

Rémy

codemation commented 1 year ago

Hey @remydewa,

There are a few examples of how token is exchanged for credentials in tests here

Looks like you are just missing the /login in front of auth/token, -> auth/token/login

remydewa commented 1 year ago

Hey @codemation

Thanks for your answer. It's working well! My bad. Sorry.

Good evening

Rémy