1
votes

I am attempting a very basic call to the one login API to get an authentication token. I copied the client id and client secret correctly from the api credentials page (although the "copy to clipboard button doesn't seem to be working).

        r2 = requests.post('https://api.eu.onelogin.com/auth/oauth2/v2/token',
            auth=('<CLIENT ID>','<CLIENT SECRET>'),
            json={
                "grant_type": "client_credentials"
                }
                )

When I run this, I get an authentication failure error. I have no idea what I am doing wrong, any help would be really appreciated.

2

2 Answers

-1
votes

The client_id and the client_secret to use in this call actually are not the ones from an app configured in the oneLogin account, you have to set up some API client_id and client_secret in your oneLogin account administration page, give them at least an auth level and then use them in your call to get the tokens

-1
votes

Sure.

Depending on what privileges you need, there are different profiles in the Developers>API credentials section from the Administration portal.You can create a new profile by clicking in the top left blue button named "New credentials".

In your case, I think is enough with a "Authentication only" profile.

Once you have those API credentials, when you are using a BASIC authentication method, you have to set them in the JSON header, but encoded in base64, not just as plain text, and the client_id and client secret are separated by (:) not by (,). You also need to set up the content type to "application/json" in the header.

Hope this helps.