发布到服务器

时间:2015-08-04 20:13:52

标签: google-apps google-api-dotnet-client google-oauth2 google-provisioning-api

我正在使用Google Provisioning API。我使用了来自Google developer console的Web应用程序类型项目。我已经使用了Diamto blog and samples并且它在我的本地完美地运行了所有选项,如FileStore,自定义文件存储,服务帐户等,但当我上传到服务器用户同意屏幕时,不会弹出任何选项,如FileStore,Custom文件存储。我花了几天时间来弄清楚问题和解决方案,但到目前为止我没有任何工作。

我的配置

  1. 我的服务器配置是Windows Server 2008数据中心r2,.net 4.5,IIS 7.5。
  2. 服务帐户工作正常但我需要通过Consent屏幕进行,因此Web应用程序类型的项目。
  3. 我使用版本为1.9.2.27817的google .net客户端库。
  4. 我只是突出显示它被卡住的主代码,其余部分与Diamto post和github示例相同。
  5. 如果您需要更多信息,请与我们联系。

    代码

    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
            }
    

    非常感谢您的任何帮助。

0 个答案:

没有答案