GenesysCloudOAuthWebView.Wpf.OAuthWebView not functioning unless embedded directly in a WPF form

I am attempting to use the OAuthWebView, ultimately in a WPF app, but I need to instantiate it in code and not directly embedded in XAML. I started with the example at https://github.com/MyPureCloud/oauth-webview-dotnet/tree/main/examples/WPF%20Example. It was originally my intention to implement it as a Task using TaskCompletionSource for a cleaner async implementation, but after no success I dropped back to the example and only moved the instantiation code into a C# class. Otherwise, the code is identical to the working example (almost working except even that returns an 'invalidRedirectUrl' even though RedirectUriIsFake is set to true). Back to the main issue, after calling BeginImplicitGrant() no event is ever raised after that. Unless I am missing something, I believe my code is identical to the example except for the XAML hosting. This makes no sense to me. Here is my code...

using System;
using System.Threading.Tasks;
using GenesysCloudOAuthWebView.Core;
//using PureCloudPlatform.Client.V2.Client;
//using PureCloudPlatform.Client.V2.Model;

namespace WPF_Testing.Services
{
public class GenesysPhoneSystem2
{
public string AccessToken { get; private set; } = null;

    private readonly string _clientID;
    private GenesysCloudOAuthWebView.Wpf.OAuthWebView _authBrowser;

    public GenesysPhoneSystem2(string clientID)
    {
        _clientID = clientID;
    }

    public void Authenticate()
    {
        _authBrowser = new();

        // configure
        _authBrowser.Config = new OAuthConfig
        {
            RedirectUri = "http://invaliduri/",
            RedirectUriIsFake = true,
            Environment = "usw2.pure.cloud"
        };

        // add result handlers
        _authBrowser.Authenticated += (response) =>
        {
            if (response == null || string.IsNullOrWhiteSpace(response.AccessToken))
                Console.WriteLine("Authentication Response returned with empty Access Token.");
            else
            {
                AccessToken = response.AccessToken;
                Console.WriteLine($"Access Token: {response.AccessToken}");
            }
        };

        _authBrowser.ExceptionEncountered += (source, exception) =>
        {
            Console.WriteLine($"Error: {exception.Message}");
        };

        // execute
        _authBrowser.Config.ClientId = _clientID;
        _authBrowser.BeginImplicitGrant();
    }

}

}

Hi Mark,

Thanks for reaching out to us. This is an open-source project that was posted by a member of our professional services team. It is an open-source project, not part of our core product and unfortunately, support is limited. I am going to put some inquiries out to our PS team to determine whether or not they have someone who might be able to answer your question, but my initial reaction is that it was probably designed to only work in a WPF form.

Thanks,
John Carnell
Director, Developer Engagement

Thanks John. I understand that support might be limited. If you do find someone who might be able to provide some insight, I would point out that the md file does show sample usage code that instantiates the control directly in a C# class. Also, the issue I mentioned with the RedirectUriIsFake property is dysfunctional in the example project posted on Github. From the md file...

var oAuthWebView = new OAuthWebView();
form.oAuthWebView.Config.ClientId = "babbc081-0761-4f16-8f56-071aa402ebcb";
form.oAuthWebView.Config.RedirectUriIsFake = true;
form.oAuthWebView.Config.RedirectUri = "http://localhost:8080";

Hi Mark
When I plug (basically) your code into MainWindow() of the original working example I see the "OAuth Example" window appear, but it is empty. If I then click "Start Implicit Grant" it calls BeginImplicitGrant() again which triggers the Genesys Cloud Login screen to appear as expected. Could it be that your code is calling BeginImplicitGrant() too soon, before the OAuthWebView is ready? Do you even see the OAuthWebView window?
Hope this helps,
Mark D

Hi Mark,

I am attempting two different approaches.

(1) The original example posted in GitHub (out of the box), which embeds the OAuthWebView control directly in a WPF window. This code does pop the login window, however, the control returns an ‘invalidRedirectUrl’ error even though the ‘RedirectUriIsFake ’ property is set to true, when the BeginImplicitGrant() method is invoked. So that fails in contrast to the documentation for this property.
(2) The code I posted, which I refactored from the original. This code instantiates the control directly in a C# class. After instantiation and setting the callbacks and executing BeginImplicitGrant(), none of the callbacks are ever invoked. With this approach, a UI window shouldn’t pop. This approach follows the documented code example in the MD file.

So, the original example just seems broken around the RedirectUrlIsFake property and instantiating within a C# class just doesn’t seem to work at all.

Thanks

Hi Mark

  1. I ran into the same issue. Rather than fighting with it, I just set the Fake property to false and updated my Genesys Cloud OAuth Client's "Authorized redirect URIs (one per line)" to include the RedirectUri that I had set in the code (https://ca.yahoo.com/).
  2. I'll take a look at the MD file but if there is no UI window, how would the user authenticate on the applications behalf?

Mark

  1. I could set it to a valid URI, I guess, but the whole point was to utilize method #2 without a UI.

  2. That's kinda the point of this code library, allowing client auth instead of user auth. In the sample app (#1) there is a UI but it is capturing the Client ID and not the user's credentials. It ultimately just passes the client ID to the code behind, such as...

oAuthWebView.Config.ClientId = "babbc081-0761-4f16-8f56-071aa402ebcb"

... and then invokes BeginImplicitGrant(). My goal was to supply this Client ID from an application setting so the user does not need to enter it.

Thanks

If you provide a valid URI you'll see that the popup window doesn't just collect the cliendId from the user but after the user submits the clientId, BeginImplicitGrant() triggers the same popup window to display a Genesys Cloud login screen where the user then logs in which ultimately results in a Token that the application can use to call the Genesys APIs. Using Implicit Grant authorization there's no way to avoid having the user login to Genesys (but yes you can avoid having the user also enter the clientId).

Thanks for all of your help Mark. I have decided to move away from this control and move toward homegrown code so I can gain more granular control over the auth process. I have been able to grab an access token, but I am having authorization issues. I have posted a new topic here... Invalid login credentials

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