C# OAuthWebSecurity不起作用
我开发了我们的应用程序,允许用户通过Facebook、Microsoft、Google、Twitter和LinkedIn登录 在Globas.asax注册服务中:C# OAuthWebSecurity不起作用,c#,asp.net,oauth,webforms,C#,Asp.net,Oauth,Webforms,我开发了我们的应用程序,允许用户通过Facebook、Microsoft、Google、Twitter和LinkedIn登录 在Globas.asax注册服务中: protected void Application_Start(object sender, EventArgs e) { BundleTable.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled;
protected void Application_Start(object sender, EventArgs e)
{
BundleTable.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled;
BundleConfig.RegisterBundles(BundleTable.Bundles);
ScriptManager.ScriptResourceMapping.AddDefinition("jquery",
new ScriptResourceDefinition
{
Path = "~/Scripts/jquery-1.10.2.min.js",
DebugPath = "~/Scripts/jquery-1.10.2.js"
});
this.RegisterAuthenticationProviders();
}
private void RegisterAuthenticationProviders()
{
OAuthWebSecurity.RegisterFacebookClient("key1", "key2", "Facebook");
OAuthWebSecurity.RegisterGoogleClient("Google");
OAuthWebSecurity.RegisterLinkedInClient("key1", "key2", "LinkedIn");
OAuthWebSecurity.RegisterMicrosoftClient("key1", "key2", "Microsoft");
OAuthWebSecurity.RegisterTwitterClient("key1", "key2", "Twitter");
}
单击按钮调用相应的方法:
OAuthWebSecurity.RequestAuthentication("ServiceName", String.Format("~/Login.ashx"));
根据按下的按钮,服务名称包括:微软、谷歌、LinkedIn、Facebook或Twitter
Handler Login.aspx看起来像:
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
var result = OAuthWebSecurity.VerifyAuthentication();
if (result.IsSuccessful)
{
var service = (LoginServices)Enum.Parse(typeof(LoginServices), result.Provider, true);
//Find user in DB, if not find create and login at last
this.TryLogin(result, context, service);
this.RedirectRequest(context);
}
else
{
// Login failed
DBLogger.WriteLog(LogPriority.Fatal, String.Format("{0}-{1}_1", this.GetType().Name, "ProcessRequest"), result.Error);
this.RedirectRequest(context, ErrorMessages.LoginFailed);
}
}
Facebook:一切正常,一切正常
Microsoft:重定向到登录可以,但作为回报,我将返回错误:
The remote server returned an error: (400) Bad Request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.HttpWebRequest.GetResponse() +6442312
DotNetOpenAuth.AspNet.Clients.MicrosoftClient.QueryAccessToken(Uri returnUrl, String authorizationCode) +334
DotNetOpenAuth.AspNet.Clients.OAuth2Client.VerifyAuthentication(HttpContextBase context, Uri returnPageUrl) +142
DotNetOpenAuth.AspNet.OpenAuthSecurityManager.VerifyAuthentication(String returnUrl) +239
Microsoft.Web.WebPages.OAuth.OAuthWebSecurity.VerifyAuthenticationCore(HttpContextBase context, String returnUrl) +129
Microsoft.Web.WebPages.OAuth.OAuthWebSecurity.VerifyAuthentication(String returnUrl) +86
Login.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
谷歌和LinkedIn:单击链接我报告javascript错误:Sys.WebForms.PageRequestManagerServerErrorException:在服务器上处理请求时发生未知错误。从服务器返回的状态代码为:0
Twitter点击我报告javascript错误的链接:
Sys.WebForms.PageRequestManagerServerErrorException: Error occurred while sending a direct message or getting the response.
按钮与第页的OnInit事件中的register onclick envet一起使用
你知道为什么我的代码不起作用吗?
谢谢
更新
问题解决了。对于LinkedIn来说,UpdatePanel中的ImageButtons就是这么回事,只要更新包就行了,它肯定会工作的 更新包DotNetOpenAuth.Core
点击“回车”并享受。尝试使用Fiddler调试请求,也许它会在响应正文中为您提供更多关于出错原因的信息。当前的异常非常广泛,您需要找出OAuth或其他方面是否有任何问题罗伯特:问题解决了。这就是我的全部