不允许使用 OpenID 连接重定向加载本地资源

Not allowed to load local resource with OpenID connect redirection

当使用 OpenID Connect 标准的身份验证 API 试图重定向到我的本地 Android 应用程序时,我遇到了 Not allowed to load local resource: file:///android_asset/www/index.html?code=[code]&state=[state]

当我启动我的应用程序时,如果我尚未连接,则会执行重定向到身份验证 API,它要求提供用户凭据。然后,如果凭据良好,API 将执行另一个重定向到在第一个重定向中传递的 redirectUri(作为查询参数)。这个redirectUri就是之前的file:///android_asset/www/index.html.

我不知道如何配置我的 app/phone 让远程应用程序(身份验证 API)在身份验证成功后重定向到我的应用程序。

有几个选项可用于完成此操作。查看 OAuth 2.0 specification 中建议的那些,更具体地说,假设有一个外部用户代理。

External user-agent - the native application can capture the response from the authorization server using a (1) redirection URI with a scheme registered with the operating system to invoke the client as the handler, (2) manual copy-and-paste of the credentials, (3) running a local web server, (4) installing a user-agent extension, or by (5) providing a redirection URI identifying a server-hosted resource under the client's control, which in turn makes the response available to the native application.

选项 1:

您使用 Android 应用程序注册的自定义方案配置重定向,这样当外部用户代理(浏览器)收到指示重定向到您的方案的响应时,您的应用程序将被调用。鉴于,那里有一些 Android 应用程序 :),该方案应该非常独特。建议对您拥有的域使用反向域名表示法,例如,如果您拥有“app.example.com”,则方案可以是“com.example.app”。

选项 2:

您重定向到某个地方,它只显示一个带有代码的漂亮页面,并要求用户在您的应用程序中手动输入它。

选项 3:

您的应用程序启动了一个本地 Web 服务器,您将重定向配置为 http://localhost:[port]/。如果多个应用程序决定使用同一个端口,那么这里可能会出现端口冲突问题。

选项 4:

通过安装用户代理扩展,您将拥有代码 运行 浏览器,并且可以自动将代码传送到您的应用程序,更多用于桌面场景。

选项 5:

您配置了一个重定向 URI,该 URI 指向您托管的一些服务器端代码,并且您的客户端 Android 应用程序知道,以便它可以从 URL 获取代码。


有关此主题的更多信息,请查看:OAuth 2.0 for Native Apps

最后一点,使用 file URL 方案将不是一个选项。此外,如果您不想在需要服务器上的某些逻辑的选项上使用完整的服务器端,您可以通过编写一些 Webtask 来使用更少的代码行来完成相同的操作(一定要使用自定义域)。

披露:我是一名 Auth0 工程师。