0

我正在使用Google Provisioning API。我使用了来自Google 开发者控制台的 Web 应用程序类型项目。我使用了 Diamto 博客和示例,它在我的本地上完美运行,具有 FileStore、自定义文件存储、服务帐户等所有选项,但是当我在服务器用户同意屏幕上上传时,不会弹出任何选项,如 FileStore、自定义文件店铺。我花了几天的时间来找出问题和解决方案,但到目前为止对我没有任何帮助。

我的配置

  1. 我的服务器配置是 windows server 2008 datacenter r2,.net 4.5,IIS 7.5。
  2. 服务帐户可以完美运行,但我需要通过同意屏幕来完成,所以 Web 应用程序类型的项目。
  3. 我使用了版本 1.9.2.27817 的 google .net 客户端库。
  4. 我只是突出显示卡住的主要代码,其余部分与 Diamto 帖子和 github 示例相同。

如果您需要更多信息,请告诉我。

代码

public static DirectoryService AuthenticateOauth(string clientId, string clientSecret, string userName, IDataStore datastore)
{
    string[] scopes = new string[] {DirectoryService.Scope.AdminDirectoryUser };    

            try
            {
                // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
                                                                                             , scopes
                                                                                             , userName
                                                                                             , CancellationToken.None
                                                                                             , datastore).Result; // at this point it calls getasynch method for custom datasource

                DirectoryService service = new DirectoryService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "GoogleProv",
                });
                return service;
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.InnerException);
                return null;

            }

        }
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "GoogleProv",
                });
                return service;
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.InnerException);
                return null;

            }

        }


  ///<summary>
        // Returns the stored value for the given key or <c>null</c> if the matching file (<see cref="GenerateStoredKey"/>
        // in <see cref="FolderPath"/> doesn't exist.
        // </summary>
        // <typeparam name="T">The type to retrieve</typeparam>
        // <param name="key">The key to retrieve from the data store</param>
        // <returns>The stored object</returns>




        public Task<T> GetAsync<T>(string key)
        {
            //Key is the user string sent with AuthorizeAsync
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("Key MUST have a value");
            }
            TaskCompletionSource<T> tcs = new TaskCompletionSource<T>();


            // Note: create a method for opening the connection.
            SqlConnection myConnection = new SqlConnection(myconn);
            myConnection.Open();

            // Try and find the Row in the DB.
            using (SqlCommand command = new SqlCommand("select RefreshToken from GoogleUser where UserName = @username;", myConnection))
            {
                command.Parameters.AddWithValue("@username", key);

                string RefreshToken = null;
                SqlDataReader myReader = command.ExecuteReader();
                while (myReader.Read())
                {
                    RefreshToken = myReader["RefreshToken"].ToString();
                }

                if (RefreshToken == null )
                {
                    // we don't have a record so we request it of the user.
                    tcs.SetResult(default(T)); // it comes here
                }
                else
                {

                    try
                    {
                        // we have it we use that.
                        tcs.SetResult(NewtonsoftJsonSerializer.Instance.Deserialize<T>(RefreshToken));
                    }
                    catch (Exception ex)
                    {
                        tcs.SetException(ex);
                    }

                }
            }

            return tcs.Task; // it comes here and than gets hang forever
        }

非常感谢您的任何帮助。

4

0 回答 0