c# - Xamarin.Auth - UWP - Windows 拦截的重定向 URL

标签 c# xamarin xamarin.forms uwp xamarin.auth

我正在使用程序包 Xamarin.Auth 根据我的 UWP 应用程序中的身份验证服务对用户进行身份验证。

验证器实例化如下:

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;

稍后我启动身份验证过程:

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

到目前为止,一切都按预期进行,身份验证工作正常。但是,我在重定向时遇到问题。尽管使用自定义 URL 的重定向会调用应用程序本身并调用方法

protected override void OnActivated(IActivatedEventArgs args)

正如预期的那样, Windows 总是会触发一个额外的对话窗口: Did you meant to switch apps?

如何在不更改注册表或任何系统范围设置的情况下避免身份验证过程的拦截?实际上,该应用程序只是在调用自身,因此我不明白为什么会触发消息。我必须使用其他重定向方法吗?

我也试过用户 isUsingNativeUI: true 并且没有任何改变。

最佳答案

看起来重定向参数(my-app://oauth2redirect) 被认为是应用程序启动uri。您可以将它修改为另一个,例如 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);

关于c# - Xamarin.Auth - UWP - Windows 拦截的重定向 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53554174/

相关文章:

c# - 对异步任务使用取消

c# - Holotoolkit 中的 HandDraggable 和 GestureAction 脚本有什么区别?

android - 三星更新后的错误 |单人游戏 |将 viewport.height 检测为设备宽度

xamarin.forms - Xamarin形式:ITMS-90809:不推荐使用的API,但是我的项目中没有webview

listview - 停止 Xamarin Forms ListView 中的单元格回收

android - Xamarin跨平台(Xamarin.Forms)中如何识别后退按钮事件

c# - 按另一个集合值对集合进行排序

c# - Xamarin 形成具有可绑定(bind)属性的 ValueConverter

c# - 在 Xamarin.Forms 中编写特定于设备平台的代码

c# - 为什么 `w("hi")` doesn' t 工作但 `this.w("hi")` 工作?