SDK Code Auth Setup Bad Requests

Hello, I have been trying to use the Python SDK but I haven't been able to figure out how to setup a Auth Code login with it. I looked at the documentation but it either seemed incomplete. I have tried to piece it together bu looking at the other code but I'm still getting errors and I'm not sure what else I need to do.

The documentation I saw said to get the api client by using the following code:

apiclient, auth_token_info = apiclient.get_code_authorization_token(os.environ['GENESYS_CLOUD_CODEAUTH_CLIENT_ID'],
os.environ['GENESYS_CLOUD_CODEAUTH_CLIENT_SECRET'],
auth_code,
"https://redirect-uri.com/oauth/callback")

But that seems to be trying to assign a variable by also using that variable.

Looking at other credential types in the instructions I wrote it as
apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_code_authorization_token(...)
instead, but I'm getting the following error and I'm not really sure where to go from here.

PureCloudPlatformClientV2.rest.ApiException: (400)

Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 07 Dec 2022 00:10:01 GMT', 'Content-Type': 'application/json', 'Content-Length': '28', 'Connection': 'keep-alive', 'Inin-Correlation-Id': '668b112d-7b99-4dfc-7e79-f662a45f0e14', 'Strict-Transport-Security': 'max-age=7776000', 'Vary': 'Accept-Encoding'})
HTTP response body: {"error":"invalid_request"}

I'm able to navigate it all through HTTP calls, but I would really like to learn how to use the SDK.

Hi,

What type of application you are building? If it is a headless application without direct user interaction (e.g. a service or batch job), you should look at the client credential grant. An example of this can be found here.

If you are building a user-based application, I take a look at the Code Auth route (which you are doing above). You can find an example of this oauth flow here.

Make sure that you have the right OAuth client setup in Genesys Cloud too. The client credential grant and the code auth grant can look the same if they are being setup by an admin who doesn't have experience working with OAuth Client Credential grants.

Thanks and I hope that helps.

  • John Carnell
    Manager, Developer Engagment

Thank you very much for the response. I have looked at those documents before and they are what helped me get stated with the Code Auth route that I'm interested in. I do need the user-based token and that's why I haven't used the client credentials route. However, my question now is about how to set up the Code Auth with the python SDK specifically. I'm having trouble finding clear documentation on that or any examples, so far I've only seen examples with client credentials.

@ObsTech did you see the code auth example John referenced above? It's also available as a guide here: https://developer.genesys.cloud/authorization/platform-auth/guides/oauth-auth-code-guide. That guide demonstrates how to use a code auth grant in a python web server.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.