Question

OAU-251 error - Unauthorized for this grant type

  • 7 June 2023
  • 1 reply
  • 666 views

I want to generate a JWT for my users, hence, I used the following endpoint alongside the appropriate headers and body, but in order to provide the main JWT for the assertion I was required to created manually for the account. How could I automate it, so that I can create any JWTs using API requests? I tried using password grant_type but it did not work, and throws an OAU-251 error - Unauthorized for this grant type.

Sandbox # +12678284935
Client ID jfEaGJSpQgaMYwr8Q-O1Zg


The following code snippet works fine, but I want to automatically generate the main JWT.

def getAccessToken(username, extension, password, server, client_id, client_secret):
    url = f"{server}/restapi/oauth/token"
    data = {
        "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
        "username": f"{username}*{extension}",
        "password": password,
        "assertion":"eyJraWQiOiI4NzYyZjU5OGQ..."
    }
    
    headers = {
        "Content-Type": "application/x-www-form-urlencoded",
        "Authorization": "Basic " + base64.b64encode(f"{client_id}:{client_secret}".encode("utf-8")).decode("utf-8")
    }
    
    res = requests.post(url, headers=headers, data=data)
    return (res.json())



1 reply

Userlevel 1

Please refer to our Dev Guide documentation for instruction how to authenticate with a JWT token. The body data does not take others than just the grant_type and the assertion.

Reply