OAuthWebSecurity不起作用

时间:2013-10-07 08:38:43

标签: 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;
            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"));

serviceNames是:Microsoft,Google,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

Google和LinkedIn :点击我报告javascript错误的链接:Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0

Twitter 点击我报告javascript错误的链接:

Sys.WebForms.PageRequestManagerServerErrorException: Error occurred while sending a direct message or getting the response.

这些按钮在页面中的OnInit事件中有注册onclick envet。

你知道为什么我的代码不起作用吗? 感谢

更新

问题解决了。这就是UpdatePanel中的ImageButtons

1 个答案:

答案 0 :(得分:0)

对于LinkedIn,只需更新包,它肯定会有效。

  

update-package DotNetOpenAuth.Core

点击'输入'并享受。