【问题标题】:What URL do I use to send users to google oauth2 consent screen我使用什么 URL 将用户发送到 google oauth2 同意屏幕
【发布时间】:2021-08-30 21:35:43
【问题描述】:

我正在尝试编写一个简单的应用程序来使用用户身份验证令牌和 html 请求访问 google 的 api,但是我正在努力寻找我发送给用户的 URL,以便他们选择个人资料并登录。

【问题讨论】:

  • 您使用的是 google APIs .Net 客户端库吗?如果是这样,您是否在 asp .net core 中执行此操作?

标签: google-api google-oauth google-authentication google-api-dotnet-client


【解决方案1】:

我也向用户发送 URL,以便他们选择个人资料并登录。

问题是您混淆了授权和身份验证。 Oauth2 用户可以授权您访问他们的数据,这与登录您的 OpenID 连接应用程序无关。

但是您可能正在寻找的是 oauth2 同意屏幕 这是用户同意您的应用程序访问其数据的屏幕。

https://accounts.google.com/o/oauth2/auth?client_id={clientid}&redirect_uri={redirectURI}&scope={scope}&response_type=code

请记住,如果他们同意,这只是第一步,然后您将获得一个授权码,然后您的应用程序必须将授权码交换为可用于访问 api 的访问令牌。

您可能会发现此视频有助于了解填充 Oauth2 舞蹈。 Understanding Google OAuth 2.0 with curl

如果您希望登录用户并检查他们的个人资料,这样会更好

[GoogleScopedAuthorize(PeopleServiceService.ScopeConstants.UserinfoProfile)]
 public async Task UserProfile([FromServices] IGoogleAuthProvider auth)
        {
            var cred = await auth.GetCredentialAsync();
            var service = new PeopleServiceService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = cred
                });
            

            var request = service.People.Get("people/me");
            request.PersonFields = "names";
            var person = await request.ExecuteAsync();

            return View(person);
        }

完整的教程和配套视频可以在这里找到Asp .net core 3 and Google login

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-05
    • 2012-05-17
    • 2019-03-20
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 2016-12-11
    • 2019-10-05
    相关资源
    最近更新 更多