2

I am using the package Xamarin.Auth to authenticate an user against an authentication service within my UWP App.

The authenticator is instantiated like the following:

this.Authenticator = new OAuth2Authenticator(
    CLIENT_ID,
    CLIENT_SECRET,
    "openid profile",
    new Uri("https://<authentication-example-server>/authorize"),
    new Uri("my-app://oauth2redirect"),
    new Uri("https://<authentication-example-server>/access_token"),
    GetUsernameAsync,
    isUsingNativeUI: false);
this.Authenticator.Completed += this.OnAuthenticationCompleted;

Later I launch the authentication process:

var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(this.Authenticator);

Everything works as expected so far and authentication works fine. However, I get an issue on the redirection. Although the redirection with the custom URL calls the app itself and calls the method

protected override void OnActivated(IActivatedEventArgs args)

as expected, Windows always triggers an additional dialogue window: Did you meant to switch apps?

How can I avoid that interception of the authentication process without changing a registry or any system wide settings? Actually, the app is only calling itself and therefore I cannot understand, why the mesage is triggered. Do I have to use another redirection approach?

I also tried to user isUsingNativeUI: true and nothing changed.

Ipsit Gaur
  • 2,872
  • 1
  • 23
  • 38
Rafael
  • 88
  • 1
  • 8
  • I know this is several months late, but did you ever find a solution to this? I am facing the same problem – BeeLabeille Jun 03 '19 at 23:03
  • Sorry, actually, I did not solve this problem directly. I removed the OAuth2Authenticator and implemented a little OAuth solution myself (for my simple usecase). Basically I call my authentication provider site in a `WebView`, register for the `WebViewNavigating`-Event and handle the event when the `WebView` "returns" with the token. Unfortunately I cannot provide a better solution. – Rafael Jun 04 '19 at 10:32

1 Answers1

0

It looks that the redirection parameter(my-app://oauth2redirect) was regarded app launch uri. You could modify the it to another, such as https://auth0.com/

this.Authenticator = new OAuth2Authenticator(
    CLIENT_ID,
    CLIENT_SECRET,
    "openid profile",
    new Uri("https://<authentication-example-server>/authorize"),
    new Uri("https://auth0.com/"),
    new Uri("https://<authentication-example-server>/access_token"),
    GetUsernameAsync,
    isUsingNativeUI: false);
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • 1
    Unfortunately using this approach OnActivated does not get called and therefore Xamarin.Auth does not go on handling the authentication process. – Rafael Dec 12 '18 at 07:33
  • You could check this [document](https://github.com/xamarin/Xamarin.Auth/wiki/GettingStarted#11-create-and-configure-an-authenticator) and use correct `redirectUrl` for current scenario. – Nico Zhu Dec 12 '18 at 07:40
  • @NicoZhu-MSFT your solution does not allow OnActivated to get called and the link provided in your comment does not have complete implementation scenarios for windows apps – BeeLabeille Jun 03 '19 at 23:06