gpt4 book ai didi

android - 具有 spring boot 后端的 android native 应用程序的 oauth 授权类型

转载 作者:行者123 更新时间:2023-12-05 00:00:04 25 4
gpt4 key购买 nike

我在后端有一个 Android 原生应用程序作为客户端和 Spring Boot 服务,带有 REST 端点。我想知道使用 oAuth2 进行身份验证的最佳策略(没有社交登录方法)。

我目前正在使用 spring oauth security 并启动并运行授权服务器(用户使用电子邮件和密码注册)。我使用授权类型“密码”在 Android 应用程序中获取访问 token 。但是,这种方法需要 android 应用程序在请求中发送客户端 ID 和密码。我读了一些posts这表明这种资助类型并不理想。我不介意收到用户的密码,但我认为将客户端密码存储在应用程序中不是一个好方法。

另一种方法是使用授权代码授权流程,但在这种情况下,因为我只有一个 native 应用程序和后端 API,所以我不知道如何授权用户。用户看到要求他们授权应用程序的浏览器页面似乎并不是一种无缝体验。这也没有意义,因为这不是第三方应用程序。

我找到了一个 post人们建议在 PKCE 中使用授权代码流。但这显然不适用于 spring .

所以,现在我想知道其他 native 移动应用程序如何处理身份验证?他们不使用访问 token 吗?在处理移动应用程序和 Spring 后端时,如何最好地支持身份验证?

最佳答案

Spring Security OAuth 支持 passwordauthorization_codewithout the client secret ,意思是“公共(public)客户端”。由于您拥有授权服务器 native 应用程序并且您可以接受 native 应用程序获取凭据,因此让您的 native 应用程序使用具有 password 授权的公共(public)客户端是合理的类型。

但是,如果您决定您的 native 应用不应获取凭据,那么 PKCE 是当前的最佳实践。建议将 authorization_code 流与公共(public)客户端一起使用 alternative to PKCE :

In the time since the spec was originally written, the industry best practice has changed to recommend using the authorization code flow with no secret for native apps.

正如您提到的,这意味着 jumping out to a browser

关于android - 具有 spring boot 后端的 android native 应用程序的 oauth 授权类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55381923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com