Skip to content

SimpleAuthentication stopped working when I added forms Auth, any ideas? #203

@fschwiet

Description

@fschwiet

Maybe I should ask in StackOverflow, as I haven't really narrowed down the issue. I saw discussion in the issues AuthenticationProviderFactory registration, that may be related.

I've been using Google OAuth with SimpleAuthentication for awhile without problem. I finally went and added forms support. But then Google OAuth doesn't work, I am seeing the below exception. I do not know what the issue is. I later went back and reverted the forms changes to verify google auth works (to verify the google API secret key was still working).

After adding Forms auth, I see an exception:

Message: "Failed to obtain some UserInfo data from the Google Api OR the the response was not an HTTP Status 200 OK. Response Status: Forbidden. Response Description: Forbidden. Error Message: --no error exception--."

at SimpleAuthentication.Core.Providers.GoogleProvider.RetrieveUserInformation(AccessToken accessToken)
at SimpleAuthentication.Core.Providers.BaseOAuth20Provider`1.AuthenticateClient(NameValueCollection queryStringParameters, String state, Uri callbackUri)
at Nancy.SimpleAuthentication.SimpleAuthenticationModule.AuthenticateCallback()

This is my auth configuration with the change to support Forms auth:

public class AuthenticationConfiguration
{
    static readonly string GoogleApiKey = System.Configuration.ConfigurationManager.AppSettings["GoogleApiKey"];
    static readonly string GoogleApiSecret = System.Configuration.ConfigurationManager.AppSettings["GoogleApiSecret"];

    public static void ForApplicationContainerConfiguration (TinyIoCContainer container)
    {
        var googleProvider = new ConfiguredGoogleOauthProvider (new ProviderParams {
            PublicApiKey = GoogleApiKey,
            SecretApiKey = GoogleApiSecret
        });
        var authenticationProviderFactory = new AuthenticationProviderFactory ();
        authenticationProviderFactory.AddProvider (googleProvider);

        container.Register<IUserMapper, UserStore> ().AsSingleton ();
        container.Register<IAuthenticationCallbackProvider> (new HayAuthenticationCallbackProvider (container.Resolve<ILoggingService> ()));
    }

    public static void ForApplicationStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
    {
        var secretCodeForCookieAuthCrypt = new compartido.ExerciseStoreReader(ExternalDataPath.Get()).GetHashForAllExercises();

        var cryptographyConfiguration = new CryptographyConfiguration(
            new RijndaelEncryptionProvider(new PassphraseKeyGenerator(secretCodeForCookieAuthCrypt, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })),
            new DefaultHmacProvider(new PassphraseKeyGenerator(secretCodeForCookieAuthCrypt, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })));

        var formsAuthConfiguration = new FormsAuthenticationConfiguration
        {
            CryptographyConfiguration = cryptographyConfiguration,
            RedirectUrl = "/login",
            UserMapper = container.Resolve<IUserMapper>(),
        };

        FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
    }
}

The CryptographyConfiguration is also new, but GoogleOAuth broke before I added that so I don't think its the problem. I am concerned about AuthenticationProviderFactory. Maybe I need to add Forms in there somehow? Maybe something I did with Forms prevernts the googleProvider from being found?
There was a lot of churn in the nuget packages I am using as well, per below:

+  <package id="FluentValidation" version="6.1.0.0" targetFramework="net45" />
-  <package id="Nancy" version="1.2.0" targetFramework="net45" />
-  <package id="Nancy.Authentication.Forms" version="1.2.0" targetFramework="net45" />
+  <package id="Nancy" version="1.4.3" targetFramework="net45" />
+  <package id="Nancy.Authentication.Forms" version="1.4.1" targetFramework="net45" />
-  <package id="Nancy.Hosting.Self" version="1.2.0" targetFramework="net45" />
-  <package id="Nancy.Owin" version="1.2.0" targetFramework="net45" />
-  <package id="Nancy.SimpleAuthentication" version="0.3.14" targetFramework="net45" />
-  <package id="Nancy.Viewengines.Razor" version="1.2.0" targetFramework="net45" />
+  <package id="Nancy.Hosting.Self" version="1.4.1" targetFramework="net45" />
+  <package id="Nancy.Owin" version="1.4.1" targetFramework="net45" />
+  <package id="Nancy.SimpleAuthentication" version="0.6" targetFramework="net45" />
+  <package id="Nancy.Validation.FluentValidation" version="1.4.1" targetFramework="net45" />
+  <package id="Nancy.Viewengines.Razor" version="1.4.3" targetFramework="net45" />
-  <package id="RestSharp" version="105.1.0" targetFramework="net45" />
+  <package id="PasswordHashTool" version="1.0.0" targetFramework="net45" />
+  <package id="RestSharp" version="105.2.3" targetFramework="net45" />
-  <package id="SimpleAuthentication.Core" version="0.3.14" targetFramework="net45" />
+  <package id="SimpleAuthentication.Core" version="0.6" targetFramework="net45" />

Sorry I guess I tried to too much in one step, now I don't know where the breakage is coming from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions