gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:20:35 25 4
gpt4 key购买 nike

如果这个问题已经在本网站或广泛的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com