Search code examples
onelogin

OneLogin credential not working on API-V2


I have credentials with scope 'Manage users'. I manage to create access_token but ​credentials work for API v1 (/api/1/users) but not for v2 (/api/2/users). The error message I get is: {"message":"Unauthorized","name":"UnauthorizedError","statusCode":401}

I've tried it from python and postman. Anyone working with users V2 and managed to make it work?

r = requests.post(
    url='https://api.us.onelogin.com/auth/oauth2/v2/token',
    auth=(CLIENT_ID, CLIENT_SECRET),
    json={'grant_type': 'client_credentials'}
)
response = r.json()
auth_token = response['access_token']


r = requests.get(
    url='https://api.us.onelogin.com/api/1/users',
    headers= {'Authorization': f'bearer:{auth_token}'}
)
print(r.status_code)
>> 200

r = requests.get(
    url='https://api.us.onelogin.com/api/2/users',
    headers= {'Authorization': f'bearer:{auth_token}'}
)
print(r.status_code)
>>401

Solution

  • I was able to reproduce your issue using Postman.

    Your Input

    Authorization:bearer:<access_token>

    Correct Input:

    Authorization:bearer <access_token>

    Notice the whitespace between bearer and <access_token>. I am assuming you downloaded OneLogin provided Postman Collection. With their Collection, it doesn't work.