Ionic Android OpenID 认证问题

问题描述

我有一个 Ionic Angular 应用程序,我正在将它部署到 Android 设备上。我使用 OpenID + KeyCloak 进行身份验证,在客户端我通过使用 angular-auth-oidc-client 来处理这个问题。我设置的配置是:

    scope: 'openid profile tino_access',silentRenewUrl: `${window.location.origin}/silent-renew.html`,responseType: 'code',postlogoutRedirectUri: window.location.origin,silentRenew: true,logLevel: LogLevel.Warn,postLoginRoute: window.location.origin,useRefreshToken: true

在本地部署或在我的服务器上的自定义域上部署时,这非常有效,但是在手机上作为应用程序进行测试时,它不起作用。我注意到 window.location.origin 的值是 http://localhost。登录成功后,以${window.location.origin}/?state='token'&code='token'的形式发出请求,其中'token'就是OAuth生成的token的值。在移动设备上发出此请求时,请求 http://localhost/?state=...&code=... 无法识别并且应用程序无法启动,我只看到网页不存在的错误屏幕。

有什么办法可以解决这个问题吗? 谢谢

解决方法

答:由于应用的源是http://localhost,而手机上没有运行本地服务器,解决方法是将auth配置的redirect_url参数改成应用的package id。示例:com.package.id://home

在 OAuth 页面中完成身份验证后,这会将您重定向回应用