GetAuthProviders returns empty list

I seem to be missing something. I had a legacy oauth2 provider that I removed and am converting to the newer one that doesn’t have the net framework dependency. I just inheritted from ServiceStack.Auth.OAuth2Provider:

public MyOAuthProvider(IAppSettings appSettings, string realm, string providerId) : base(appSettings, realm, providerId)
        {
            this.appSettings = appSettings;
        }
}
The actual registration is the same as before (when it was working):

Plugins.Add(new AuthFeature(() => new MySession(),
                new IAuthProvider[] {
                    //   new DtAuth(), 
                  
                    jwtProvider
                    ,
                    new MyOAuthProvider(AppSettings,  wpo.Realm, "myprovider") {
  AuthorizeUrl = wpo.Endpoint(wpo.AuthorizeUrl),
                        CallbackUrl = $"{AppSettings.Get("baseDomain","")}auth/myprovider",
                        ConsumerKey = wpo.Key,
                        ConsumerSecret = wpo.Secret,
                        AccessTokenUrl = wpo.Endpoint(wpo.AccessTokenUrl),
                        UserProfileUrl = wpo.Endpoint(wpo.UserProfileUrl),
                        SuccessRedirectUrlFilter = (auth, url) => {
                            var urls = new GetUserData().ToGetUrl();
                            urls.AddQueryParam("RedirectSuccess",1);
                            return urls+ ".json"; },
                        
                    },

Authentication.GetAuthProviders() returns an empty list after this and the /auth/myprovider throws an error that seems to indicate it is related when before it would redirect to the configured I’m just looking for a pointer in the right direction as this worked completely fine until I ripped out the ServiceStack.Authentcation.OAuth2Provider library.

Do you mean AuthenticateService.GetAuthProviders()? That’s run after the AuthFeature plugin is registered, whatever logic you’re using to check for it needs to be run after that, if you’re doing this from within your own plugin you should register it after AuthFeature otherwise your plugin can implement IPostInitPlugin.AfterPluginsLoaded() which will be called after all plugins are registered.

You can also access it from an AfterInitCallbacks which are fired after the AppHost has finished initializing.

Yes, I meant AuthenticationService.GetAuthProviders(). If I run that after the plugin setup, at the end of all the container registrations it returns an empty list. I don’t have any plugins. My question, if I implement a basic Oauth2Provider with an accesstoken url it should redirect the user right?

Something is wrong with your configuration then, the AuthFeature literally assigns its AuthProviders it’s configured with during its Plugin Registration. I don’t see how it could return an empty list unless the plugin isn’t run, maybe you have a Startup Error. Try enabling StrictMode to throw Exceptions on Startup:

SetConfig(new HostConfig {
    StrictMode = true
})

What your AuthProvider does is controlled by its own implementation. The built-in OAuth providers will redirect to the external OAuth provider on initial request.

No errors. Here you can see the plugin list and the authfeature has registered the three providers.

Now, at the end of the configure method when calling this it returns an empty list.

2019-10-23_17-09-41

Hitting my head against the wall here.

Plugins are run after Configure(), use the callbacks I’ve mentioned in my previous comment to check for state of plugins after they’re registered, otherwise you can access the Auth Providers from GetPlugin<AuthFeature>().AuthProviders instead if you need them before the Plugin is registered (although in general accessing plugins before they’re registered is not recommended).

1 Like

Thanks. That helped me get through this.

1 Like