2017-02-20 47 views
4

如果已在本網站或廣泛的ServiceStack文檔中得到回答,我們表示歉意 - 我已看過,但如果確實存在,我將不勝感激!ServiceStack .NET核心的OAuth2身份驗證插件

我一直在試圖敲起一個示例服務堆棧(1.0.35)服務,它演示了使用.NET核心(不是.NET 4.5.x)的OAuth2的使用。

我找到了this web page,並添加了所描述的AuthFeature插件,這對於可用的提供者來說似乎很好。

我的問題:雅虎,的OpenID,谷歌和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 
{ 

} 
+0

我打算編寫一個與.NET核心兼容的ServiceStack.Auth.OAuth2.OAuth2Provider端口作爲OSS,但首先我要查看它是否已經完成。任何人之前做過? –

+0

同時在https://servicestack.uservoice.com/forums/176786-feature-requests/suggestions/19534429-support-oauth2-on-net-core –

回答

3

ServiceStack的OAuth2用戶依賴於DotNetOpenAuth不幸的是不支持.NET核心所以有目前的OAuth2用戶的支持。

+1

上投票這很好(感謝官方的答覆!) - 我很想知道是否有任何未來的計劃來支持這些OAuth2提供商? 我開始認爲我可以(應該?)得到一個公共的Nginx網守/反向代理類型的東西來處理auth,並將相關的令牌轉發給我的內部服務堆棧服務。 – Jay

+0

@Jay我們確實希望在.NET Core中支持OAuth2,只需要找到可以與ServiceStack集成的解決方案。 – mythz

+0

@mythz對此有何動靜? Google Auth是阻止我們轉向.net核心的唯一因素! – JMK