【问题标题】:Hybrid Authentication with asp.net Identity and Android Authorization具有 asp.net 身份和 Android 授权的混合身份验证
【发布时间】:2017-07-27 16:27:36
【问题描述】:

我正在创建一个使用 Identity (v2.0) 的 asp 网站,以及一个通过 Web API 连接到该网站的 Android 应用程序。

我已将 Identity 配置为使用 Google OAuth 登录,并且运行良好。现在我正在尝试为应用程序制作一个 Web API,我还需要对移动用户进行身份验证。

我已经到了配置身份来管理 api 的不记名令牌的地步。但是要执行登录,我发现的唯一方法是通过用户名和密码documentation 说:

grant_type=password&username=user&password=pass

或通过网络执行 OAuth 质询。

Android 也是 manages Google OAuth。有没有办法配置 Identity 以使用 Google Oauth 执行登录?

我既没有找到管理外部不记名令牌的方法,也没有找到使用 Google 身份验证令牌通过身份使用 Web Api 进行签名的方法。

也许我误解了什么。

提前致谢。

【问题讨论】:

  • 好问题,很高兴您自己找到了答案。请在您自己的问题的答案中写下解决方案。我会赞成它! :-)

标签: android asp.net-web-api oauth-2.0 google-oauth asp.net-identity-2


【解决方案1】:

好的,不知怎的,我找到了方法。

  1. 在 Android 中,使用范围 Audience:server: 获取 ID 令牌,如 Google“Accounts Authentication and Authorization”文档中所述。

  2. 将 Web API 令牌端点作为用户发送电子邮件并作为密码发送令牌。

    grant_type=password&username={email}&password={GoogleToken}

  3. 在服务器中来自 OAuthAuthorizationServerProvider 的扩展类中,我将来自 github repo googleplus/gplus-verifytoken-csharp 的令牌验证添加到方法 GrantResourceOwnerCredentials

  4. 如果令牌有效,我可以填充 UserLoginInfo 并使用 UserManager 查找用户。

然后正常的身份验证继续进行,并且用户以正常的身份进行身份验证。

无论如何,我认为必须有一种更优雅的方式来做到这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多