Legacy Dev Forum Posts

 View Only

Sign Up

Blank token returned from client credential log in

  • 1.  Blank token returned from client credential log in

    Posted 06-05-2025 18:06

    David_McLaughlin | 2021-04-08 17:40:26 UTC | #1

    Hello,

    Using the .Net SDK, I'm attempting to authenticate with client credential, but the token returned is blank. An error is not raised - the token is simply blank. Any thoughts on why?

    The following is my C# page code:

    using System; using PureCloudPlatform.Client.V2.Client; using PureCloudPlatform.Client.V2.Extensions;

    public partial class Test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {

    // Set Region PureCloudRegionHosts region = PureCloudRegionHosts.uswest2; Configuration.Default.ApiClient.setBasePath(region);

    // Configure SDK Settings AuthTokenInfo accessTokenInfo = Configuration.Default.ApiClient.PostToken("myClientID", "myClientSecret");

    Trace.Warn("token", accessTokenInfo.ToJson()); // Wrikes blank token info } }

    Thank you! David


    tim.smith | 2021-04-08 17:52:35 UTC | #2

    The members are explicitly set to not serialize. You can get the information via accessing the properties directly or trace out using the ToString method. https://github.com/MyPureCloud/platform-client-sdk-dotnet/blob/master/build/src/PureCloudPlatform.Client.V2/Extensions/AuthTokenInfo.cs#L25


    David_McLaughlin | 2021-04-08 17:58:00 UTC | #3

    Ok thanks. But I traced using the ToString method and AccessToken and these returned blank token info as well.


    tim.smith | 2021-04-08 18:03:09 UTC | #4

    Can you make API requests successfully? Are there values in the AuthTokenInfo's properties when you access them directly?


    David_McLaughlin | 2021-04-08 18:47:54 UTC | #5

    When I try to make an API request using the method, PostAnalyticsQueuesObservationsQuery, I get the following error:

    "Error calling PostAnalyticsQueuesObservationsQuery: {"message":"No authentication bearer token specified in authorization header.","code":"authentication.required","status":401}".

    My guess is this is due to the blank token.

    ** "Are there values in the AuthTokenInfo's properties when you access them directly?" I've used ToString to trace out the members and they're all blank and I've traced the AccessToken property directly and it's blank as well. Perhaps I'm misunderstanding your question.

    The following is my C# code with the API request included:

    using System; using System.Collections.Generic; using PureCloudPlatform.Client.V2.Api; using PureCloudPlatform.Client.V2.Client; using PureCloudPlatform.Client.V2.Extensions; using PureCloudPlatform.Client.V2.Model;

    public partial class TestDRM : System.Web.UI.Page { protected void PageLoad(object sender, EventArgs e) {

    //Set Region PureCloudRegionHosts region = PureCloudRegionHosts.uswest2; Configuration.Default.ApiClient.setBasePath(region);

    // Configure SDK Settings AuthTokenInfo accessTokenInfo = Configuration.Default.ApiClient.PostToken("myClientID", "myClientSecret"); Configuration.Default.AccessToken = accessTokenInfo.AccessToken;

    Trace.Warn("token", accessTokenInfo.ToString());

    var query = new QueueObservationQuery(); query.Metrics = new List<QueueObservationQuery.MetricsEnum>() { QueueObservationQuery.MetricsEnum.Oactiveusers, QueueObservationQuery.MetricsEnum.Ooffqueueusers, QueueObservationQuery.MetricsEnum.Oonqueueusers };

    var predicate = new QueueObservationQueryPredicate( QueueObservationQueryPredicate.TypeEnum.Dimension, QueueObservationQueryPredicate.DimensionEnum.Queueid, QueueObservationQueryPredicate.OperatorEnum.Matches ); var predicates = new List<QueueObservationQueryPredicate>() { predicate }; query.Filter = new QueueObservationQueryFilter(QueueObservationQueryFilter.TypeEnum.Or, Predicates: predicates);

    predicate.Value = "myQueueID"; var analytics = new AnalyticsApi(); analytics.PostAnalyticsQueuesObservationsQuery(query); } }


    tim.smith | 2021-04-08 18:51:55 UTC | #6

    Configuration.Default.AccessToken = accessTokenInfo.AccessToken;

    This is unnecessary as PostToken sets it on the api client automatically.

    The way PostToken is written, there's the possibility that a 3xx or 1xx response could sneak through without raising an exception, though the auth server shouldn't ever return those to my knowledge. Can you use PostTokenWithHttpInfo and see exactly what response you're getting from the login attempt? I'd like to see the StatusCode and RawData in particular.


    David_McLaughlin | 2021-04-08 19:38:21 UTC | #7

    I used PostTokenWithHttpInfo and it appears that a valid token is being returned. There was a token in the RawData > access_token field. The following are the properties of the ApiResponse that were returned:

    RawData {"accesstoken":"<myToken>","tokentype":"bearer","expires_in":172799}

    StatusCode 200

    StatusDescription OK

    Headers Connection: keep-alive Inin-Correlation-Id: <myCorrelationId> Strict-Transport-Security: max-age=7776000 Vary: Accept-Encoding Content-Length: 148 Content-Type: application/json Date: Thu, 08 Apr 2021 19:24:37 GMT

    CorrelationId <myCorrelationId>

    Data class AuthTokenInfo { AccessToken: RefreshToken: TokenType: ExpiresIn: Error: }


    David_McLaughlin | 2021-04-08 21:05:27 UTC | #8

    I extracted the token from the RawData and used it successfully to call the API. The following was used to set the token:

    Configuration.Default.AccessToken = token;

    However, this is not an elegant solution of course.


    system | 2021-05-09 20:58:41 UTC | #9

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


    This post was migrated from the old Developer Forum.

    ref: 10555