OAuth doesn't work

Hi,
I created an oauth of type "credential client information" to which I assigned the administrator privileges
then I created an api in .net to connect to it and access the predefined responses
but unfortunately I have the following error message
below my code in .net

var clientId = "57468896-0e27-4ab8-9ff2-c745121c03a1";
var clientSecret = "HANDLE CLIENT SECRETS LIKE PASSWORDS";
PureCloudRegionHosts region = PureCloudRegionHosts.eu_west_1;

        // Set up the API client configuration
        var apiConfig = new PureCloudPlatform.Client.V2.Client.Configuration();  
        apiConfig.ApiClient.setBasePath(region);
        // Get the access token
        var accessTokenInfo = apiConfig.ApiClient.PostToken(clientId, clientSecret, "", "", false);
        var accessToken = accessTokenInfo.AccessToken;

        var apiInstance2 = new ResponseManagementApi(apiConfig);
        var res = apiInstance2.GetResponsemanagementLibraries(1, 100, null);

the error is displayed after res

Below the error message :

{"message":"No authentication bearer token specified in authorization header.","code":"authentication.required","status":401,"contextId":"32e9613b-1e3d-48f6-9c26-14b394f36130","details":[],"errors":[]}

@Ericblanc welcome to the forum!

Please be sure to regenerate your client secret immediately as this is a public forum and anyone that saw your original message may now have access to your org.

I've tagged in the SDK team to help with this post.

@tim.smith
Thank you for your update,
OK, I got a new one, thanks
I am waiting for your feedback regarding my problem
Regards

Hi @tim.smith,
Any Update please?
Regards

Hi Eric,

I was able to reproduce the issue based on your code example. I am going to open a ticket on our side for further investigation and look at how/if we can fix. In the meantime, if you are able to you can set the oauth client creds on the default object. I verified that I was able to make a call successfully. Here is the code I used:

using PureCloudPlatform.Client.V2.Api;
using PureCloudPlatform.Client.V2.Client;
using PureCloudPlatform.Client.V2.Model;
using PureCloudPlatform.Client.V2.Extensions;

public class MyResponse
{
    public static void Main(string[] args)
    {
        var clientId = "CLIENT_ID";
        var clientSecret = "CLIENT_SECRET";
        PureCloudRegionHosts region = PureCloudRegionHosts.us_west_2;
        Configuration.Default.ApiClient.setBasePath(region);
        Configuration.Default.ApiClient.PostToken(clientId, clientSecret);

        var apiInstance2 = new ResponseManagementApi();
        var res = apiInstance2.GetResponsemanagementLibraries(1, 100, null);
    }
}

Thanks for posting. When the engineer I have assigned this to gets through his assessment he will respond back. In the meantime, I hope this workaround will keep you moving forward.

Thanks,
John Carnell
Director, Developer Engagement

Hi @John_Carnell
I thank you very much for your assistance
on the other hand I have a question, the token has a life span of 48h maximum and I need to create a new one.
The problem is that the client will want to send conversations every day and I can not give the hand to the user on the part of API development so that he can modify. How can I make sure that the token does not expire? or has a longer lifetime
Regards

Hi @Ericblanc

It looks like you are not setting the access token on the configuration object which would result in the above error. To set the access token, you should do the following:

apiConfig.AccessToken = accessTokenInfo.AccessToken;

Here is some example code that works for me.. (you may need to change the region etc..)

using PureCloudPlatform.Client.V2.Api;
using PureCloudPlatform.Client.V2.Client;
using PureCloudPlatform.Client.V2.Extensions;

internal class Program
{
    private static void Main(string[] args)
    {
        var clientId = "your_client_id";
        var clientSecret = "your_client_secret";

        var config = new Configuration();

        PureCloudRegionHosts region = PureCloudRegionHosts.us_east_1;

        config.ApiClient.setBasePath(region);

        var accessTokenInfo = config.ApiClient.PostToken(clientId, clientSecret, "", "", false);

        config.AccessToken = accessTokenInfo.AccessToken;

        var apiInstance = new ResponseManagementApi(config);

        var res = apiInstance.GetResponsemanagementLibraries(1, 100, null);

        Console.WriteLine(res);
    }
}

Thanks,

Mike

Hi @Michael_Roddy
Thank you for your update,
i will test and let you know,
regarding my question about the expiration time of the token how can I get around this problem because the token expires after 48 hours but the customer wants to use the api every day?

Regards

A well-formed application will notice when it receives a 401 (unauthorized) response and will initiate the oauth flow again to reauthorize itself. Access tokens cannot have a TTL longer than 48 hours and there are several scenarios that can cause the access token to be revoked before its natural expiration, which requires all applications to behave reactively to 401 responses regardless of the TTL.

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