Tag: 谷歌 的OAuth

Google Drive Api – 带有entity framework的自定义IDataStore

我实现了我的自定义IDataStore以便我可以在我的数据库上存储最终用户令牌而不是默认实现,该实现保存在%AppData%中的FileSystem上 。 public class GoogleIDataStore : IDataStore { … public Task GetAsync(string key) { TaskCompletionSource tcs = new TaskCompletionSource(); var user = repository.GetUser(key.Replace(“oauth_”, “”)); var credentials = repository.GetCredentials(user.UserId); if (key.StartsWith(“oauth”) || credentials == null) { tcs.SetResult(default(T)); } else { var JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(Map(credentials)); tcs.SetResult(NewtonsoftJsonSerializer.Instance.Deserialize(JsonData)); } return tcs.Task; } } 调节器 public async Task AuthorizeDrive(CancellationToken cancellationToken) […]

使用预先存在的访问令牌通过ASP.NET创建YouTube服务

我一直在使用一个网站,用户可以将video上传到共享的YouTube帐户,以便以后访问。 经过大量的工作,我已经能够获得一个主动令牌和可行的刷新令牌。 但是,初始化YouTubeService对象的代码如下所示: UserCredential credential; using (var stream = new FileStream(“client_secrets.json”, FileMode.Open, FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, // This OAuth 2.0 access scope allows an application to upload files to the // authenticated user’s YouTube channel, but doesn’t allow other types of access. new[] { YouTubeService.Scope.YoutubeUpload }, “user”, CancellationToken.None ); } var youtubeService […]

用于access_token的Youtube API C#OAuth令牌交换返回无效请求

我正在尝试在其Google帐户中对用户进行身份validation,以访问和修改其Youtube数据。 我设法获得从用户登录和条款接受返回的令牌,但是当我执行POST以交换用户access_token的令牌时,它在Json文件上返回“无效请求”。 以下是我显示登录页面的方式: string url = string.Format(“https://accounts.google.com/o/oauth2/auth?client_id=XXXXXXX&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://gdata.youtube.com&response_type=code&access_type=offline”); WBrowser.Navigate(new Uri(url).AbsoluteUri); 我使用HttpWebRequest来发布POST string url = “https://accounts.google.com/o/oauth2/token?code=XXXXXX&client_id=XXXXXXXXX&client_secret=XXXXXXXXX&redirect_uri=http://localhost/oauth2callback&grant_type=authorization_code”; HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url); byte[] byteArray = Encoding.UTF8.GetBytes(url); httpWReq.Method = “POST”; httpWReq.Host = “accounts.google.com”; httpWReq.ContentType = “application/x-www-form-urlencoded; charset=utf-8”; httpWReq.ContentLength = byteArray.Length; 但它失败了: HttpWebResponse myHttpWebResponse = (HttpWebResponse)httpWReq.GetResponse(); 出现以下错误: 如果设置ContentLength> 0或SendChunked == true,则必须提供请求正文。 通过在[Begin] GetResponse之前调用[Begin] GetRequestStream来完成此操作。 然后我将我的POST请求更改为TcpClient,如下所示: TcpClient client = new TcpClient(“accounts.google.com”, 443); […]

Google Calendar API v3 – 在服务器上部署时请求超时

我试图登录localhost,一切正常。 代码: public static bool LoginGoogleCalendar(string clientId, string clientSecret, string idGCalendarUser, string calendarServiceScope, string folder) { try { UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret, }, new[] { calendarServiceScope }, idGCalendarUser, CancellationToken.None, new FileDataStore(folder)).Result; return true; } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return false; } } (我正确设置了fileDataStore的授权) 在Google Developers […]

Google Cloud Storage InsertMediaUpload Service BaseUri ArgumentNullException

我正在尝试将文件上传到Google云端存储中的存储桶。 我编写了以下代码来创建StorageService并将文件上传到存储桶。 GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer() { ClientSecrets = new ClientSecrets { ClientId = _googleSettings.ClientID, ClientSecret = _googleSettings.ClientSecret }, DataStore = new FileDataStore(System.Web.HttpContext.Current.Server.MapPath(“/App_Data”)), Scopes = new string[] { StorageService.Scope.DevstorageReadWrite }, }); UserCredential userCredentials = new UserCredential(flow, Environment.UserName, new TokenResponse()); StorageService service = new StorageService(new BaseClientService.Initializer() { HttpClientInitializer = userCredentials, ApplicationName = “GCS Sample” […]

使用Google服务帐户私钥签名数据失败

我无法使用从Google Developer Console下载的Service Application私钥对数据进行签名。 我收到以下错误: OAuthTests.TestCrypto.testSha256SignWithGoogleKey: System.Security.Cryptography.CryptographicException : Invalid algorithm specified. at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr) at System.Security.Cryptography.Utils._SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash, Int32 dwFlags) at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, String str) at OAuthTests.TestCrypto.testSha256SignWithGoogleKey() in e:\Development\MiscellaneousProjects\RSSNewsFeeder\Oauth\OAuthTests.cs:line 43 是的,我之前已经问过这个问题,但没有得到太多的帮助,因为Stack的论坛模型不容易添加到现有的线程上,似乎我最好的改写问题就是做到这一点; 改写并提出一个新问题。 我写了三个unit testing(下面的代码)。 第一个unit testing显示我可以使用带有SHA256的RSACryptoServiceProvider对数据进行签名和validation,但此测试不使用我的Google证书的私钥。 当我使用Google的私钥证书和测试(下面的第二个测试)时,代码错误(上面的错误消息)。 第3次测试演示了使用Google的私钥并使用SHA1进行测试,这有效! 但根据规格无效。 以下代码是否有问题,或者证书有问题,或者可能是我的操作系统或其他环境问题? 我正在Windows 8.1机器上使用Windows C#3.5进行开发。 **这个工作** 不使用Google证书 var cert = […]

NativeApplicationClient不受支持

在我的Visual Stuidio Win表单项目中使用此代码时。 var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret); 我收到了一条消息 不再支持NativeApplicationClient,它将在1.7.0-beta中删除。 考虑使用支持.NET 4,.NET for Windows Store应用程序,Windows Phone 7.5和8以及便携式类库的新Google.Apis.Auth NuGet软件包 我在用 install-package Google.Apis.Authentication -pre 如果我添加Google.apis.auth而不是Google.Apis.Authentication它甚至没有NativeApplicationClient。 但我无法找到任何有关我使用NativeApplicationClient的内容的信息。

谷歌日历Api在本地工作正常但不提高其在服务器上的身份validation

我在console.developers.google.com创建了一个项目以使用Google Calendar API 。 我们需要生成凭证并选择应用程序类型 对于Localhost和应用程序类型, other以下是Json工作正常。 { “installed”: { “client_id”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com”, “project_id”: “xxxxxx-00000”, “auth_uri”: “https://accounts.google.com/o/oauth2/auth”, “token_uri”: “https://accounts.google.com/o/oauth2/token”, “auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”, “client_secret”: “xxxxxxxxxxxx”, “redirect_uris”: [ “urn:ietf:wg:oauth:2.0:oob”, “http://localhost” ] } } 对于应用程序类型Web Application在服务器上托管少数参数在Json具有不同的值,如下所示。 { “web”: { “client_id”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com”, “project_id”: “xxxxxxxx-99999”, “auth_uri”: “https://accounts.google.com/o/oauth2/auth”, “token_uri”: “https://accounts.google.com/o/oauth2/token”, “auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs”, “client_secret”: “xxxxxxxxxxxxxxxxxxxxxxx”, “redirect_uris”: [ “http://demo.mydemo.com” ], “javascript_origins”: [ “http://demo.mydemo.com” ] } […]

从Google OpenID迁移到新的OAuth 2

我看到有一些问题已经存在,但我找不到任何细节。 我之前使用过自己的DotNetOpenAuth代码,但现在我决定切换到Microsoft Wrapper for Authentication。 无论如何,我发现这个非常好的OAuth客户端: https://github.com/mj1856/DotNetOpenAuth.GoogleOAuth2 它似乎工作正常,但现在它来到迁移部分。 在我当前的登录系统中,我保存了Google返回的完整OpenIDurl,其格式为: https://www.google.com/accounts/o8/id?id= ???????????????????????????? ???? 根据此处的文档https://developers.google.com/accounts/docs/OpenID我应该能够通过新的OAuth系统以某种方式获得该值。 我在Auth请求中包含了“openid.realm”参数。 return BuildUri(AuthorizationEndpoint, new NameValueCollection { { “response_type”, “code” }, { “client_id”, _clientId }, { “scope”, string.Join(” “, scopes) }, { “redirect_uri”, returnUrl.GetLeftPart(UriPartial.Path) }, { “state”, state }, { “openid.realm”, “http://myoldopenidrealm” } }); 据我所知,文档应该是我需要做的全部。 我确保我用于OpenID 2身份validation的Realm是相同的,它也与我的返回URL相同。 在我完成之后,我做了令牌请求,据我所知,我应该看到一个“open_id”字段,但我无法理解如何获取它。 protected override string QueryAccessToken(Uri returnUrl, […]

Google OAuth2:何时以及如何使用刷新令牌

我有一个已安装的c#app,其代码可以获取授权代码并将其交换为访问令牌。 我正在存储刷新令牌。 我知道在某些时候我需要使用它来获取新的访问令牌。 我们假设我定期调用以下方法来监控已与我的云端硬盘帐户共享的文件。 /// /// Retrieve a list of File resources. /// /// Drive API service instance. /// List of File resources. public static List retrieveAllFiles(DriveService service) { List result = new List(); FilesResource.ListRequest request = service.Files.List(); request.Q = “sharedWithMe and trashed=false”; do { try { FileList files = request.Fetch(); result.AddRange(files.Items); request.PageToken = files.NextPageToken; […]