Azure Function v2 谷歌身份验证与谷歌

标签 azure azure-active-directory postman azure-functions azure-authentication

我有一个使用 google 登录的 Azure Function 应用(我现在只需要 google),但无法正确进行身份验证

gooogle configured and log in with google on

试验 1:

  1. 我向我的 api 发出 get 请求:https://examplefunctions.azurewebsites.net/
  2. Google 身份验证弹出窗口
  3. 输入我的凭据
  4. 然后我向 https://examplefunctions.azurewebsites.net/.auth/me 发出 get 请求
  5. 我得到一个带有 access_tokenid_token 以及 user_claims 等其他属性的 json
  6. 然后我去找 postman
  7. 向具有 AuthorizationLevel.Anonymous 的函数发出 get 请求:https://examplefunctions.azurewebsites.net/api/myfunction
  8. 在 OAuth 2.0 授权中输入 access_token
  9. 服务器返回 401:您无权查看此目录或页面。
  10. 然后将 postman 授权选项卡中的access_token替换为id_token信息,服务器返回相同的信息。

之后执行以下操作:

试验 2:

  1. 转到https://examplefunctions.azurewebsites.net/.auth/login/google在浏览器中
  2. Google 身份验证弹出窗口
  3. 输入我的凭据
  4. 服务器重定向到具有此属性的网址authenticationToken
  5. 我在postman的OAuth2.0中输入这个authenticationToken并返回相同的401:您没有权限查看此目录或页面。

然后我执行此操作并进行身份验证:

试验 3:

  1. 转到https://examplefunctions.azurewebsites.net/.auth/login/google在浏览器中
  2. Google 身份验证弹出窗口
  3. 输入我的凭据
  4. 服务器重定向到具有此属性的网址authenticationToken
  5. 在 postman 的标题中,我将 X-ZUMO-AUTH 与之前在 authenticationToken 中收到的值放在一起,然后瞧,服务器响应状态为 OK,其中包含我预期的 json 。

但是这里是试验 3 中的问题(唯一有效的)我没有收到 claim 。 --> 这里我得到一个 null var Claims = req.HttpContext.User.Claims;

我需要用户谷歌信息。另一件事是我不想使用像 X-ZUMO-AUTH 这样的 header 登录,我想使用 OAuth 2.0 标准。

我不知道为什么我无法使用试用版1和2访问,因为我登录后服务器返回给我一个 token ,这个 token 似乎没什么用。

我已经尝试进行良好的 Google 身份验证一周了,但我做不到,我需要你的帮助。

注意:我将使用 Angular、Postman、Xamarin 或 Flutter 来使用此 api

最佳答案

我找到了解决办法!!!

问题是我单独使用了 azure 函数身份验证,但对于 azure 中的最佳实践身份验证,您需要将 Azure B2C Active Directory 租户与您的 azure 函数应用程序连接起来

我遵循了这些教程:

在这里您将学习配置租户
https://youtu.be/a1s6LMXi7Xk

通过之前的学习,您已完成 Azure Functions 身份验证 https://blogs.msdn.microsoft.com/hmahrt/2017/03/07/azure-active-directory-b2c-and-azure-functions/

现在,登录我的应用程序的每个用户都已在 B2C 租户中注册,我可以获得有关谁在使用我的应用程序以及何时登录等的更多详细信息

关于Azure Function v2 谷歌身份验证与谷歌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56730137/

相关文章:

sql-server - 是否可以使用 Azure DevOps 构建任务将 SQL 脚本部署到多个数据库?

java - HTTP 405 不支持请求方法 'PUT'

node.js - 如何在单次上传操作中将大小大于 5mb 的文件上传到 AWS

javascript - 使用 JavaScript 使用 HmacSHA256 正确地签署字符串

azure - 我可以使用 Terraform 将 azure 函数添加到 DPS 吗?

azure - 创建不带配置文件的 ApplicationInsight TelemetryConfiguration

database - 克服 Windows Azure Sql 数据库 150 GB 大小限制

c# - 如何获取委派权限的 token (microsoft graph)

azure - AADSTS76020 : Azure AD SSO with Signin certificate cannot authenticate graph client

node.js - 使用 Azure AD 承载 token 时身份验证失败,无法返回容器列表 [Azure Blob] [Azure AD OAuth 2.0] [REST API]