OAuth2 Authentication Plugin for ServiceStack.NET Core

Sorry if this has already been answered on this site or in the extensive ServiceStack documentation - I looked, but if it really exists, I would appreciate a pointer!

I tried to bring down the service stack service example (1.0.35), which demonstrates using OAuth2 using the .NET kernel (not .NET 4.5.x).

I found this web page and added the AuthFeature plugin as described, which seems to be suitable for available providers.

My question is . Providers of Yahoo, OpenId, Google, and LinkedIn are not part of the ServiceStack.Auth namespace (yet?). I looked at the Servicestack.Authentication.OAuth2 NuGET package, but it seems to be targeting .NET 4.6.x. Is this functionality available or in the roadmap for the ServiceStack.NET kernel?

Full repo code of my demo application:

namespace ServiceStackAuthTest1
{
public class Program
{
    public static void Main(string[] args)
    {
        IWebHost host = new WebHostBuilder()
           .UseKestrel()
           .UseContentRoot(Directory.GetCurrentDirectory())
           .UseStartup<Startup>()
           .UseUrls("http://*:40000/")
           .Build();

        host.Run();
    }
}

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddLogging();

    }


    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseServiceStack((AppHostBase)Activator.CreateInstance<AppHost>());

        app.Run((RequestDelegate)(context => (Task)Task.FromResult<int>(0)));
    }

}

public class AppHost : AppHostBase
{
    public AppHost() 
        : base("My Test Service", typeof(MyService).GetAssembly())
    {
    }

    public override void Configure(Container container)
    {
        Plugins.Add(new AuthFeature(() => new AuthUserSession(),
            new IAuthProvider[]
            {
                new JwtAuthProvider(AppSettings)
                {
                    HashAlgorithm = "RS256",
                    PrivateKeyXml = AppSettings.GetString("PrivateKeyXml")
                },
                new ApiKeyAuthProvider(AppSettings), //Sign-in with API Key
                new CredentialsAuthProvider(), //Sign-in with UserName/Password credentials
                new BasicAuthProvider(), //Sign-in with HTTP Basic Auth
                new DigestAuthProvider(AppSettings), //Sign-in with HTTP Digest Auth
                new TwitterAuthProvider(AppSettings), //Sign-in with Twitter
                new FacebookAuthProvider(AppSettings), //Sign-in with Facebook
                //new YahooOpenIdOAuthProvider(AppSettings), //Sign-in with Yahoo OpenId
                //new OpenIdOAuthProvider(AppSettings), //Sign-in with Custom OpenId
                //new GoogleOAuth2Provider(AppSettings), //Sign-in with Google OAuth2 Provider
                //new LinkedInOAuth2Provider(AppSettings), //Sign-in with LinkedIn OAuth2 Provider
                new GithubAuthProvider(AppSettings), //Sign-in with GitHub OAuth Provider
                new YandexAuthProvider(AppSettings), //Sign-in with Yandex OAuth Provider        
                new VkAuthProvider(AppSettings), //Sign-in with VK.com OAuth Provider 
            }));
    }
}

public class MyService : Service
{

}
+4
source share
1 answer

ServiceStack OAuth2 depends on DotNetOpenAuth, which unfortunately does not support .NET Core, so there is currently no support for OAuth2.

+3
source

Source: https://habr.com/ru/post/1670286/


All Articles