Azure Function v2 谷歌身份验证与谷歌 [英] Azure Function v2 google authentication with google
问题描述
我有一个 Azure Function 应用程序,使用 google 登录(我现在只需要 google),但我无法正确验证
I have an Azure Function app with Log in with google (I only need google right now) and I cant authenticate correctly
- 我向我的 api 发出 get 请求:https://examplefunctions.azurewebsites.net/
- Google 身份验证弹出窗口
- 输入我的凭据
- 然后我向 https://examplefunctions.azurewebsites.net/.auth/发出获取请求我
- 我得到一个带有 access_token 和 id_token 以及 user_claims 等其他属性的 json
- 那我去找邮递员
- 向具有 AuthorizationLevel.Anonymous 的函数发出 get 请求:https://examplefunctions.azurewebsites.net/api/myfunction
- 在使用 OAuth 2.0 的自动化中输入 access_token
- 服务器返回 401:您无权查看此目录或页面.
- 然后将 access_token 替换为 post man 中的授权选项卡中的 id_token 信息,服务器返回相同的信息.
- I make a get request to my api : https://examplefunctions.azurewebsites.net/
- Google authentication pop up
- Enter my credentials
- then I make a get request to https://examplefunctions.azurewebsites.net/.auth/me
- I get an json with access_token and id_token and other properties like user_claims etc
- then I go to postman
- make an get request to an function that have AuthorizationLevel.Anonymous : https://examplefunctions.azurewebsites.net/api/myfunction
- Enter the access_token in the autorization with OAuth 2.0
- server return an 401 : You do not have permission to view this directory or page.
- then replace the access_token with the id_token information in the autorization tab in post man and the server return the same.
然后执行以下操作:
- 转到 https://examplefunctions.azurewebsites.net/.auth/login/google 在浏览器中
- Google 身份验证弹出窗口
- 输入我的凭据
- 服务器重定向到具有此属性 authenticationToken 的 url
- 我在postman的OAuth2.0中输入了这个authenticationToken,返回同样的401:你没有权限查看这个目录或页面.
然后我这样做并进行身份验证:
Then I do this and authenticate :
- 转到 https://examplefunctions.azurewebsites.net/.auth/login/google 在浏览器中
- Google 身份验证弹出窗口
- 输入我的凭据
- 服务器重定向到具有此属性 authenticationToken 的 url
- 在邮递员的标题中,我将 X-ZUMO-AUTH 与以前在 authenticationToken 中收到的值放在一起,然后用我预期的 json 以 OK 状态查看服务器响应.
- go to https://examplefunctions.azurewebsites.net/.auth/login/google in the browser
- Google authentication pop up
- Enter my credentials
- the server redirect to an url that have this property authenticationToken
- In the headers of post man I put X-ZUMO-AUTH with the value previusly receive in authenticationToken and voila the server response with an OK status with my expected json.
但这里是试用 3 中的问题(唯一有效的)我没有收到索赔.--> 这里我得到一个空 var claim = req.HttpContext.User.Claims;
But here the problem in the trial 3 (the only one that works) I dont receive the claims. --> here I get a null var claims = req.HttpContext.User.Claims;
我需要用户谷歌信息.另一件事是我不想使用 X-ZUMO-AUTH 之类的标头登录,我想使用 OAuth 2.0 标准.
And I need the user google information. Another thing is That I dont want to login using a header like X-ZUMO-AUTH, I want to use the OAuth 2.0 standard.
我不知道为什么我使用试用1和2无法访问,因为我登录后服务器返回一个令牌,这个令牌似乎没用.
I dont know why I cant access using the trial 1 and 2, because the server return me an token after i log in, this token seems useless.
一周来我一直在尝试做一个好的谷歌身份验证,但我做不到,我需要你的帮助.
I have been trying to make a good google authentication for a week and I cant, I need your help.
注意:我将使用 angular、postman、xamarin 或颤振来使用这个 api
NOTE : I will consume this api with an angular, postman, xamarin or maybe flutter
推荐答案
我找到了解决方案!!!
I found a solution!!!
问题是我单独使用 azure function autentication,但要在 azure 中获得最佳实践 autentication,您需要使用 azure function app 说服 Azure B2C Active Directory Tenant
The problem was that I was using the azure function autentication alone, but for a best practice autentication in azure, you need to convinate Azure B2C Active Directory Tenant with your azure function app
我遵循了 thouse 教程:
I followed thouse tutorials :
在这里学习配置租户
https://youtu.be/a1s6LMXi7Xk
在前面的学习中,您完成了 Azure Functions 身份验证https:///blogs.msdn.microsoft.com/hmahrt/2017/03/07/azure-active-directory-b2c-and-azure-functions/
现在每个登录到我的应用程序的用户都在 B2C 租户中注册,我可以更详细地了解谁在使用我的应用程序以及何时登录等
Now every user that log in to my app is registed in the B2C tenant and I can have more detail information of who is using my app and when is loging in, etc
这篇关于Azure Function v2 谷歌身份验证与谷歌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!