c# – ServiceStack .NET Core的OAuth2身份验证插件

如果这已在本网站或广泛的ServiceStack文档中得到解答,请致歉 – 我看过,但如果确实存在,我会很感激指针!

我一直试图敲定一个示例服务堆栈(1.0.35)服务,该服务演示了使用.NET核心(不是.NET 4.5.x)的OAuth2的使用.

我找到了this web page,并且已经添加了所描述的AuthFeature插件,这对于可用的提供商来说似乎没问题.

我的问题:Yahoo,OpenId,Google和LinkedIn提供商不会出现ServiceStack.Auth命名空间的一部分(但是?).我查看了Servicestack.Authentication.OAuth2 NuGET包,但这似乎是针对.NET 4.6.x.这个功能是可用的还是ServiceStack .NET核心的路线图?

我的演示应用程序的完整代码回购:

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
{

}

解决方法:

ServiceStack的OAuth2依赖于DotNetOpenAuth,遗憾的是它不支持.NET Core,因此目前不支持OAuth2.

上一篇:c# – 在插件中注册服务前缀 – ServiceStack


下一篇:微信小程序之画布,给图片添加圆角,画圆,文字换行