Tag: oauth

检索Linkedin电子邮件地址

我正在使用Hammock库和C#来获取用户的基本个人资料和电子邮件地址,链接在以下post中。 我也在这里和这里关注这些post 但是对于我的生活,我无法获得linkedin用户的电子邮件地址。 阅读这篇新帖后,我得到了一个新的应用程序,以获得新的密钥,但仍然没有运气。 通过这个 linkedinpost,但无法让它工作 我正在发布下面的代码,但是从我遵循的链接中大量提升 var credentials = new OAuthCredentials { CallbackUrl = “http://localhost:2715/Callback.aspx”, ConsumerKey = “my consumer key”,//not shown ConsumerSecret = “my consumer secret”,//not shown Type = OAuthType.RequestToken, }; var client = new RestClient { Authority = “https://api.linkedin.com/uas/oauth”, Credentials = credentials }; //var scope = HttpUtility.UrlEncode(“r_basicprofile r_emailaddress”); var request = new RestRequest […]

使用api 1.1的Twitter POST问题

我们刚刚更改为Twitter api 1.1,现在Tweeting不起作用并返回错误“远程服务器返回错误:(400)错误请求。” 关于SO的研究表明它与身份validation有关,但我们正在发送我们刚刚从登录页面获得的accessToken和secret。 这一切都适用于api 1.0。 代码是 – public void Tweet(Action response, string message) { StringBuilder sb = new StringBuilder(); sb.Append(“POST&”); sb.Append(Uri.EscapeDataString(_postUrl)); sb.Append(“&”); string oauthNonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString())); string timeStamp = MakeTimestamp(); var dict = new SortedDictionary { { “oauth_consumer_key”, _oAuthConfig.ConsumerKey }, { “oauth_nonce”, oauthNonce }, { “oauth_signature_method”, “HMAC-SHA1” }, { “oauth_timestamp”, timeStamp }, { […]

使用Azure Active Directory – 一个应用程序在本地登录和发布时

我正在使用Azure Active Directory身份validation构建MVC应用程序。 当我在本地开发时,我希望能够登录进行测试/开发。 应用程序URL就像http://localhost:43400 。 这也在Sign-On Url和Reply Url中的AD应用程序中编码。 当我将相同的应用程序部署到服务器时,应用程序URL已更改 – 变为类似myappname.azurewebsites.net ,我无法使用相同的AD应用程序登录。 我能管理的最好的办法是通过登录过程,然后AD将我重定向回localhost:43400 ,这是错误的。 Startup.Auth.cs中有PostLogoutRedirectUri属性,我提供给应用程序,但它没有任何区别。 有没有使用相同Azure AD的本地应用程序和已部署应用程序的方法? 我可以使用不同的URL和密钥执行2个AD Applica,并在部署时重写web.config的值。 但这听起来不是最好的解决方案。 还有什么我能做的吗? UPD 以下是我在Startup.Auth.cs引用的内容: app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions { ClientId = clientId, Authority = Authority, PostLogoutRedirectUri = postLogoutRedirectUri, // <– this is coming from web.config, different in dev and prod Notifications = new OpenIdConnectAuthenticationNotifications() { ….. […]

跨两个Web API项目共享OAuth令牌

我创建了一个带有OAuth令牌认证的Web API应用程序。 当令牌服务器在与服务相同的应用程序上运行时,这没有问题。 但是,我想将授权服务移动到自己的应用程序(VS项目)中,并将其用于我正在处理的几个Web API项目中。 但是,当我将授权逻辑隔离到它自己的项目中时,原始服务不再将生成的令牌视为有效。 我的问题是,一个Web API项目是否有可能为另一个Web API项目生成令牌以进行validation? 这是我的授权服务和原始服务的OWIN启动代码 认证服务: public void Configuration(IAppBuilder app) { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888 HttpConfiguration config = new HttpConfiguration(); ConfigureOAuth(app); WebApiConfig.Register(config); app.UseWebApi(config); app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); } private void ConfigureOAuth(IAppBuilder app) { OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new […]

如何使用.NET HttpWebRequest API从响应中读取HTTP头?

我的应用目前使用OAuth与Twitter API进行通信。 早在去年12月,Twitter就将OAuth的费率上限提高到每小时350个请求。 但是,我没有看到这一点。 我仍然从account / rate_limit_status方法获得150。 有人告诉我,我需要使用X-RateLimit-Limit HTTP标头来获得新的速率限制。 但是,在我的代码中,我没有看到标题。 这是我的代码…… HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newURL); request.Method = “GET”; request.ServicePoint.Expect100Continue = false; request.ContentType = “application/x-www-form-urlencoded”; using (WebResponse response = request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { responseString = reader.ReadToEnd(); } } 如果我检查response ,我可以看到它有一个Headers的属性,并且有16个头。 但是,我没有列表中的X-RateLimit-Limit 。 图片http://sofzh.miximages.com/c%23/33201085434am.png 知道我做错了什么吗?

owin oauth发送其他参数

我确信这是可能的,但不确定如何实现。 我有一个OWIN OAUTH实现,它当前接受用户的用户名和密码,并根据数据库对它们进行身份validation。 我想扩展它以通过SmartCard Uid来支持使用SmartCard进行单点登录。 我可以在OWIN登录中传递其他参数吗?如果是,如何传递? 基本前提是用户可以使用用户名/密码组合或SmartCard uid登录(如果通过SmartCard uid并且在数据库中找到,则应用程序将登录用户) 我目前正在传递username , password和grant_type ,我想将uid添加到该列表中并在我的AuthorizationServiceProvider选择它。 我可以在OAuthGrantResourceOwnerCredentialsContext上看到UserName , Password和ClientId ,但我看不到任何其他属性可以支持我想要实现的内容。 这是我目前在我的服务提供商中所拥有的 public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add(“Access-Control-Allow-Origin”, new[] { “*” }); var user = await this._userService.FindUser(context.UserName, context.Password); if (user == null) { context.SetError(“invalid_grant”, “The user name or password is incorrect.”); return; } var identity = new […]

将google idToken替换为本地openId令牌c#

我正在使用这个github项目https://github.com/openiddict/openiddict-core这很棒。 但是,当用户使用外部身份提供商时,我会被困在程序应该是什么,或者如何实现它们,对于这个例子,我将使用谷歌。 我有一个angular2 app运行,带有aspnet核心webAPI。 我的所有本地登录工作都很完美,我使用用户名和密码调用connect/token ,并返回accessToken。 现在我需要将谷歌作为外部身份提供商实施。 我已按照此处的所有步骤实施Google登录按钮。 这会在用户登录时打开一个弹出窗口。这是我为google按钮创建的代码。 // Angular hook that allows for interaction with elements inserted by the // rendering of a view. ngAfterViewInit() { // check if the google client id is in the pages meta tags if (document.querySelector(“meta[name=’google-signin-client_id’]”)) { // Converts the Google login button stub to an actual button. […]

使用HMAC-SHA1加密创建OAuth签名返回HTTP 401

问题 您好,我需要对需要OAuth加密的API进行身份validation。 我的方向正确,但我确信我的签名基本字符串有问题。 由于HMACSHA1 Hash基于Key和BaseString,因此我得到了错误的oauth_signature。 OAuth签名流程 至今 我已经能够收集所有必需的数据,其中包括: 消费者密钥 消费者秘密 Acces Token Acces Secret Sha1Hased Value(基于Key和Message,其中Message是签名Base string) 签名基本字符串 问题 由于签名无效,我收到了HTTP(401错误请求)。 注意:我很确定这是我如何构建我的签名基本字符串 。 有关我使用的API文档的信息,请查看底部页面。 代码 GetOAuthToken (做实际请求) public static string GetAuthorizationToken() { string TimeInSecondsSince1970 = ((int)(DateTime.UtcNow – new DateTime(1970, 1, 1)).TotalSeconds).ToString(); string Nonce = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(TimeInSecondsSince1970 + TimeInSecondsSince1970 + TimeInSecondsSince1970)); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(GetAppleApiUrl.GetUrl(AppleApiUrl.SESSION_TOKEN)); httpWebRequest.Method = “GET”; […]

使用Instagram API在.NET中使用OAuth 2.0

我正在努力使用Instagram API,我被困在他们的OAuth的第2步。 我有一个代码从他们的重定向回到我,但然后他们希望我做一个如下参数的post… curl \ -F ‘client_id=CLIENT-ID’ \ -F ‘client_secret=CLIENT-SECRET’ \ -F ‘grant_type=authorization_code’ \ -F ‘redirect_uri=YOUR-REDIRECT-URI’ \ -F ‘code=CODE’ \ https://api.instagram.com/oauth/access_token 我将其实现为ASP.NET MVC 3解决方案。 我试着像这样实施post…… WebRequest request = HttpWebRequest.Create(“https://api.instagram.com/oauth/access_token”); request.Method = “POST”; request.Headers.Add(“client_id”, “sdlf0982jiejfopijfp92jjiwoijf90”); request.Headers.Add(“client_secret”, “39993939393939393939393939393”); request.Headers.Add(“grant_type”, “authorization_code”); request.Headers.Add(“redirect_uri”, “http://localhost:34962/Home/Auth”); request.Headers.Add(“code”, 111111); var response = request.GetResponse(); return View(); 这给了我一个400错误,说“client_id是必需的”。 我已经包含了client_id,但我显然没有正确实现它。 执行OAuth第二站的“最佳实践”方法是什么?

在使用facebook或twitter授权后,存储并检索为用户收到的令牌

嗨我正在尝试编写一个MVC5应用程序,该应用程序能够存储在使用facebook或twitter授权后为用户收到的令牌。 我想将它存储在数据库而不是cookie中,并将其用于用户未来的任何API请求和登录尝试,以便每当他们尝试使用Facebook登录时,都不会提示他们使用Facebook或Twitter进行授权。方法或尝试访问个人资料信息。 查看成员资格数据库,我可以看到有一个名为AspNetTokens的表没有被使用 – 所以有什么我错过了我可以使用它的地方吗?