Tag: oauth 2.0

NativeApplicationClient和OAuth2Authenticator未解析

我正在编写一个控制台应用程序来从BigQuery下载数据。 再一次,.NET库是模糊和混乱的。 在这个问题中 , 两名Google员工发布了一个回复,但我的机器上没有任何响应正在进行,因为他们还没有明确说明他们正在使用哪些参考。 我再次粘贴代码并详细说明: using DotNetOpenAuth.OAuth2; using Google.Apis.Authentication.OAuth2; using Google.Apis.Authentication.OAuth2.DotNetOpenAuth; using Google.Apis.Bigquery.v2; using Google.Apis.Util; { public class Program { public static void Main(string[] args) { // Register an authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); // Put your client id and secret here (from https://developers.google.com/console) // Use the installed app flow here. provider.ClientIdentifier = […]

DotNetOpenAuth OAuth2访问额外数据

我正在使用DotNetOpenAuth的OAuth2库来处理与另一个第三方系统的授权。 这一切都很有效,除了第三方系统在使用AccessToken的Response中返回UserId =“testname”。 我需要UserId,因为这个第三方API需要它作为API调用的一部分(例如:users / {userId} / account)。 使用DotNetOpenAuth,我无法访问AccessToken响应,因此无法获取UserId。 我正在调用:( _client是一个WebServerClient)var state = _client.ProcessUserAuthorization(request); state有我的AccessToken,但没有发送的额外数据。 基于DotNetOpenAuth源代码,UserId进入库内,我没有任何访问权限。 无论如何使用DotNetOpenAuth获取UserId? 或者我是否需要放弃DotNetOpenAuth并尝试其他方法?

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) […]

用于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 Open Auth 2.0在服务器端获得access_token(错误请求错误,ProtocolError)

我正在尝试通过Google Open Auth 2.0实现用户身份validation。 我已经成功获得了Google的“代码”,现在我正在尝试获取access_token来访问用户的信息。 这是控制器的代码: public void Google(string code) { if (!string.IsNullOrWhiteSpace(code)) { var parameters = new Dictionary(); parameters[“code”] = code; parameters[“client_id”] = ConfigurationProvider.GoogleApplicationId; parameters[“client_secret”] = ConfigurationProvider.GoogleClientSecret; parameters[“redirect_uri”] = “http://localhost:1291” + Url.Action(“GoogleAuth”); parameters[“grant_type”] = “authorization_code”; var keyValuePairs = new string[parameters.Count]; var i = 0; const string keyValueTemplate = “{0}={1}”; foreach (var parameter in parameters) […]

Google API / OAUTH / NativeApplicationClient / OAuth2Authenticator>退出?

我正在构建一个桌面应用程序,使用OATH按照此线程中的方案连接到Googles API: 适用于dotnet的Google API v3; 使用带有API密钥的日历 一切正常。 我已经构建了一个表单,显示一个WebBrowser来收集authCode。 但是我该如何实施“退出”呢? 找不到任何APIfunction。

OpenID Connect – 在WinForms和Web应用程序之间使用IdentityServer进行SSO

我有Thinktecture IdentityServer设置,我有两个可信客户端应用程序,一个WinForms应用程序和一个Web应用程序,我想在它们之间实现SSO。 用户将首先打开桌面应用程序,该应用程序具有通过身份服务器进行身份validation的登录页面。 桌面应用程序将包含一些生成的Web链接,单击这些链接时会打开一个新的浏览器窗口,指向需要身份validation的Web应用程序的安全区域,但是,单击这些链接后,我不希望用户必须再次登录已通过桌面应用程序validation过一次。 我很难看到哪些流程可以实现这一目标。 OpenID connect或Thinktecture IdentityServer提供哪些机制(如果有)可以促进此过程?

强制用户使用mvc c中的Google Organization(G Suite)帐户登录

我在我的mvc网站上实施了Google身份validation。 这是我的示例代码 – AuthConfig.cs public static class AuthConfig { private static string GoogleClientId = ConfigurationManager.AppSettings[“GoogleClientId”]; private static string GoogleClientSecret = ConfigurationManager.AppSettings[“GoogleClientSecret”]; public static void RegisterAuth() { GoogleOAuth2Client clientGoog = new GoogleOAuth2Client(GoogleClientId, GoogleClientSecret); IDictionary extraData = new Dictionary(); OpenAuth.AuthenticationClients.Add(“google”, () => clientGoog, extraData); } } Global.asax中 AuthConfig.RegisterAuth(); AccountController.cs public ActionResult RedirectToGoogle() { string provider = “google”; […]

Google驱动示例:未找到oauth2callback

我需要对Google-Drive的C#示例程序有所帮​​助…… 我使用了这个所谓的 “教程”/“例子”: https://developers.google.com/drive/examples/dotnet 而这里的代码: https://code.google.com/p/google-drive-sdk-samples/source/checkout 我在这里上传了我的(仅略微修改过的)源代码,以防任何人没有Mercurial(我没有Mercurial,也没有管理员权限来安装它,Mercurial是获取源代码的唯一方法……): http://verzend.be/elt0k13enraw/DrEdit.rar.html 我总是得到 “无法找到资源” 请求的URL:/ oauth2callback 我没有发现这令人惊讶,因为没有实现oauth2callback控制器或处理程序… 我尝试添加一个名为oauth2callbackController的Controller,并重定向到oauth2callbackController.Index中的另一个动作, return new RedirectResult(“/about/about”); 但是这只会创建一个NULL引用exception。 所以我想,可能是错误的控制器并重定向到 return new RedirectResult(“/drive/Index”); 但这只会创建一个无限循环的重定向 – >允许 – >重定向 – 允许 – >等。 顺便说一句,更改API密钥+ REDIRECT_URI的配置在 Models\ClientCredentials.cs 注意: 问题不是我的修改。 样本也没有修改,没有完全相同的错误。 我所做的只是删除EntityFramwork引用,并在调用使用实体的方法时抛出“未实现的exception”。 编辑: 附加信息: 我真正想要做的是编写一个导出我的数据库的控制台服务,LZMA压缩导出的内容,使用OpenPGP加密,并在24:00每天将我的服务器数据库上传到Google驱动器’时钟,没有任何用户输入。 我的导出工作没有问题,我得到LZMA压缩工作没有问题,我得到加密与PGP工作没有问题。 在工作日结束后(grrrr),当我在家时,我甚至可以在家里的Linux机器上安装mercurial下载示例代码,并使用SMB将其带到Windows机器上。 。 但现在我无法获得Google-drive SDK的样本… 而且,我真正需要的是控制台服务/守护进程的示例,而不是Web应用程序。 当我创建API密钥时,我看到可以为服务创建密钥,但是没有关于如何编写Google-Drive服务(控制台应用程序)的示例,也没有有用的文档(是的,有参考,但它只是一个参考,IntelliSense提供的相同)…

:通过IdentityServer3通过LDAPvalidation用户

我需要一种方法来通过IdentityServer3validation组织内的用户(使用LDAP和Active Directory)并授予他们对资源的访问权限。 IdentityServer3似乎是OpenID Connect协议的实现框架,适用于身份validation和授权。 到目前为止,我已经能够使用InMemory实现validation硬编码用户并获得JWT(JSON Web令牌)访问令牌。 请参考这个例子: https://rajdeep.io/2015/05/07/creating-a-single-sign-on-using-thinktecture-identity-server-part-1/ 但是,在我必须validation大型组织中的用户(存储在活动目录中)并发出令牌来访问资源的情况下,这不会非常有用。 以下是我根据此链接所做的工作 ( http://stackoverflow.com/questions/31536420/thinktecture-identityserver-v3-with-windowsauth ): 创建了一个实现IUserService的ActiveDirectoryUserService。 namespace LDAPSSO { public class ActiveDirectoryUserService : IUserService { private const string DOMAIN = “company domain”; public Task AuthenticateExternalAsync(ExternalIdentity externalUser, SignInMessage message) { return Task.FromResult(null); } public Task AuthenticateLocalAsync(string username, string password, SignInMessage message) { try { using (var pc = […]