https://prefect.io logo
Title
d

Dmitry Sandovich

01/30/2023, 6:33 PM
Hi everyone, I'm exploring Prefect REST API. Authentication request fails with 401 (Unauthorized). Here is my request using curl: curl --request POST 'https://api.prefect.cloud/auth/login' --header 'Content-Type: application/json' --header 'Authorization: Bearer <Service Account API key>' I validated service account api key using cli: prefect auth login --key <Service Account API key> With cli I'm able to login successfully. Does anyone know why my authentication request fails? Thanks, Dmitry
j

jawnsy

01/30/2023, 6:35 PM
I think that API (/auth) is meant for browser authentication only, I’d suggest trying an authenticated read (e.g. GET) API instead (e.g. /api)
d

Dmitry Sandovich

01/30/2023, 6:40 PM
Hi Jonathan, thanks for your response. I tried GET: curl --location --request GET 'https://api.prefect.cloud/api/accounts/permissions' --header 'Authorization: Bearer ....' I'm still getting 401
j

jawnsy

01/30/2023, 10:25 PM
this worked for me:
curl  --location --request GET --header "Authorization: Bearer pnu_xxx" <https://api.prefect.cloud/api/me/>
d

Dmitry Sandovich

01/30/2023, 10:39 PM
Thanks. It doesn't work for me. I'm using service account API key as a Bearer token. Is that what you use?
j

jawnsy

01/30/2023, 10:58 PM
I was using a user API key token, I’m not sure if service accounts have the same permission for this API 🤔
d

Dmitry Sandovich

01/31/2023, 2:02 PM
Hi Jonathan, thanks again for your response. I generated personal API key but I'm still getting 401. I found another way to implement what I'm trying to do with Python and GraphQL. I will investigate issue with REST API authentication later when I have more time. Thanks again! Regards, Dmitry
x

Xun Wang

02/13/2023, 11:43 PM
Looks like not many people used the /auth/login endpoint as no reply to my question for the last two days. Yes, I am getting the 401 with pnu_xxxx token. Here is my test code:
def login():
    auth_token = 'pnu_xxxxxxxxxxxxx'
    hed = {'Authorization': 'Bearer ' + auth_token}
    response = <http://requests.post|requests.post>('<https://api.prefect.cloud/auth/login>', headers=hed)
    print(response.headers)
    print(response)
    print(response.json())
If change to GET, it returns http 200 with an empty body plus a lot of values in the header. According to the API doc, this endpoint should be working. Wonder if it is actually not working at this point without anyone noticed. Any advice?
j

jawnsy

02/13/2023, 11:59 PM
Can you create an issue in the prefect repo? https://github.com/PrefectHQ/prefect If you have a support agreement, then filing a ticket should be faster
1
x

Xun Wang

02/14/2023, 3:10 PM