2017-07-18 40 views
1

我在MVC應用程序中很年輕將ASP.NET Core Identity設置爲服務

我想創建一個爲外部MVC應用程序提供標識的web服務。暴露ASP.NET核心身份作爲服務的

優點:

  • 實際的應用程序代碼更簡單,從它的身份脫鉤涉及

  • 支持建立的認證標準和模式簡化了安全擔憂和建立信任

  • 身份證服務可以住在一個單獨的過程

  • 在多個應用

重用用戶身份這可能嗎?任何想法,我可以做到這一點?

+1

詳細的解釋,我認爲你正在尋找https://identityserver.io/ – Veikedo

回答

0

這是可能的。

這就是我們的做法。

我們使用IdentityServer4爲客戶端生成JWT令牌。我們創建了一個簡單的MVC項目,其中包含一個簡單的啓動文件,可以給你一個想法。

public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddIdentityServer() 
     .AddSigningCredential(new X509Certificate2(Path.Combine(".", "cert", "token-cert.pfx"), "cert-password")) 
     .AddInMemoryApiResources(Config.GetApiResources()) 
     .AddClientStore<CustomClientStore>(); 

     string connectionString = Configuration.GetConnectionString("DefaultConnection"); 
     // a data service to fetch user data from database 
     services.AddTransient<IUserDataMapper>(s => new UserDataMapper(connectionString)); 
    } 

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(); 
     loggerFactory.AddDebug(); 

     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
     } 

     app.UseIdentityServer(); 

     app.Run(async (context) => 
     { 
      await context.Response.WriteAsync("ACME Auth Token API v1.0"); 
     }); 
    } 

你可以找到IdentityServer4在https://identityserver4.readthedocs.io/en/release/quickstarts/1_client_credentials.html#defining-the-api