使用Google云端硬盘Api与另一个帐户进行身份验证

时间:2018-11-02 09:45:02

标签: google-oauth2 google-apis-explorer

我在Windows应用程序中使用Google Drive API。

每当用户单击按钮单击此处以使用另一个帐户登录时,导航到登录页面。

请参见以下图片

认证结果页面enter image description here之后

点击“单击此处以使用其他帐户登录”后,页面如下图所示enter image description here

对于以上页面,我正在xaml中使用 WebBrowser 控件。

正在重定向,但页面已禁用,这意味着鼠标单击无法在按钮上进行。

oauth网址和逻辑

var url = string.Format("https://accounts.google.com/o/oauth2/auth?client_id={0}&redirect_uri={1}&include_granted_scopes=true&state=6a56c58b-4199-4952-a060-320d4573017c&scope={2}&response_type=code&access_type=offline&approval_prompt=force", GoogleDriveConfig.MyClientId, GoogleDriveConfig.MyRedirectUri, "https://www.googleapis.com/auth/drive");
        SourceUrl = new Uri(url);
        var cookie = string.Empty;
        try
        {
            // Get every cookie (Expiration will not be in this response)
            cookie = Application.GetCookie(SourceUrl);
        }
        catch (Win32Exception ex)
        {
            MigrationConfig.Logger.LogException(ex);
            // "no more data is available" ... happens randomly so ignore it.
        }
        if (!string.IsNullOrEmpty(cookie))
        {
            // This may change eventually, but seems quite consistent for google.com.
            // ... they split all values w/ ';' and put everything in foo=bar format.
            string[] values = cookie.Split(';');
            foreach (string s in values)
            {
                if (s.IndexOf('=') > 0)
                {
                    // Sets value to null with expiration date of yesterday.
                    _DeleteSingleCookie(s.Substring(0, s.IndexOf('=')).Trim(), SourceUrl);
                }
            }
        }

谢谢。

0 个答案:

没有答案
相关问题