代码之家  ›  专栏  ›  技术社区  ›  Ein2012

Google“GoogleWebAuthorizationBroker”显示错误重定向uri不匹配

  •  0
  • Ein2012  · 技术社区  · 6 年前

     UserCredential credential;
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        new ClientSecrets
                        {
                            ClientId = "xxxxxx.apps.googleusercontent.com",
                            ClientSecret = "FxxxxxxxxxZ"
                        },
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath)).Result;
    

    当这个方法被执行时,我们应该被重定向到同意屏幕,相反,我得到的错误是 shown in this image

    但它显示的重定向URI我从未在控制台中指定过。这些是我在googleprojectconsole中指定的重定向uri。 console settings 我做错什么了吗?如何正确重定向到权限屏幕?

    0 回复  |  直到 6 年前
        1
  •  1
  •   Linda Lawton - DaImTo    6 年前

    重定向uri问题

    http://127.0.1:59693/authorize 您还没有在授权重定向uri下添加它。

    host:port/authorize
    

    应用程序类型

    您可以创建几种类型的客户机。这些客户机设计用于处理不同类型的应用程序。用于连接这些客户机的代码也不同。

    • 安装的应用程序-安装在用户计算机上的应用程序

    已安装的应用程序

    您正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync

    Web应用程序

    Web applications 以及使用 GoogleAuthorizationCodeFlow

    using System;
    using System.Web.Mvc;
    
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Auth.OAuth2.Flows;
    using Google.Apis.Auth.OAuth2.Mvc;
    using Google.Apis.Drive.v2;
    using Google.Apis.Util.Store;
    
    namespace Google.Apis.Sample.MVC4
    {
        public class AppFlowMetadata : FlowMetadata
        {
            private static readonly IAuthorizationCodeFlow flow =
                new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                    {
                        ClientSecrets = new ClientSecrets
                        {
                            ClientId = "PUT_CLIENT_ID_HERE",
                            ClientSecret = "PUT_CLIENT_SECRET_HERE"
                        },
                        Scopes = new[] { DriveService.Scope.Drive },
                        DataStore = new FileDataStore("Drive.Api.Auth.Store")
                    });
    
            public override string GetUserId(Controller controller)
            {
                // In this sample we use the session to store the user identifiers.
                // That's not the best practice, because you should have a logic to identify
                // a user. You might want to use "OpenID Connect".
                // You can read more about the protocol in the following link:
                // https://developers.google.com/accounts/docs/OAuth2Login.
                var user = controller.Session["user"];
                if (user == null)
                {
                    user = Guid.NewGuid();
                    controller.Session["user"] = user;
                }
                return user.ToString();
    
            }
    
            public override IAuthorizationCodeFlow Flow
            {
                get { return flow; }
            }
        }
    }
    
    推荐文章