Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuthWebSecurity.VerifyAuthentication IsSuccessful returns false how do I to determine the reason?

I'm using DotNetOpenAuth with a MVC 4 application. All the sudden Google auth is failing (MS is working). The stock code does this:

[AllowAnonymous]
public ActionResult ExternalLoginCallback(string returnUrl)
{
    var result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
    if (!result.IsSuccessful)
    {
        return RedirectToAction("ExternalLoginFailure");
    }

I know that result.IsSuccessful is false, but how do I get the reason? result.Error is null.

I also looked at this page to use log4net. I do get a log on the local dev box but not when I deploy it to a remote server.

log4net webconfig:

<log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="RelyingParty.log" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="100KB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date (GMT%date{%z}) [%thread] %-5level %logger - %message%newline" />
      </layout>
    </appender>
    <!-- Setup the root category, add the appenders and set the default level -->
    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
    </root>
    <!-- Specify the level for some specific categories -->
    <logger name="DotNetOpenAuth">
      <level value="ALL" />
    </logger>
  </log4net>

Edit I also tried log4net to a sql db but it still didn't log anything

like image 470
Eonasdan Avatar asked Oct 17 '12 17:10

Eonasdan


1 Answers

I finally figured this out. The actual error message I was getting:

Protocol error: This message has a timestamp of 10/23/2012 12:19:33 PM, 
which is beyond the allowable clock skew for in the future. 

Turns out after a server crash the timezone didn't get set correctly. This caused the validation/token to fail from google's end.

The AdoNetAppender was "not working" because bufferSize was set to 100. After setting it to 1 it started getting logs. Here is the adonetappender I'm using

  <log4net>
        <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionStringName value="CONNECTIONSTRINGNAME" />
      <commandText value="INSERT INTO Log4Net ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>
    <root>
      <level value="Debug" />
      <appender-ref ref="AdoNetAppender" />
    </root>
    <logger name="DotNetOpenAuth">
      <level value="ALL" />
    </logger>
  </log4net>

You should set the bufferSize back to 100 when you get your issue worked out.

like image 152
Eonasdan Avatar answered Nov 10 '22 19:11

Eonasdan