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

标签 c# oauth-2.0 servicestack .net-core

如果这个问题已经在本网站或广泛的 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 .NET Core 的 OAuth2 身份验证插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42343306/

相关文章:

c# - 如何在 .NET 1.1 中创建和启动参数化线程?

Nginx 和 Oauth2-proxy : After logging in with Google, 重定向回 Oauth 登录页面

python - 如何注册一个oauth2客户端?

php - Google Apps 和 OAuth 最佳实践

c# - 当路径中存在句点时找不到 ServiceStack 处理程序

routes - 向ServiceStack的基本路径添加参数

ServiceStack 自定义格式和供应商特定内容类型

c# - 如何从 Azure Web 应用程序与 IIS 中本地托管的 WCF 服务进行通信?

c# - 设置在 .NET 中解析部分日期值时假定的年份

c# - 如何在 ASP.NET MVC 中实现插页式 "loading..."页面?