これらすべてがうまく連携する単一のプロジェクトを構築するのに苦労しています。
- スパ
- 静的ファイル
- Web API (MVC)
- Swagger (スワッシュバックル)
- IdentityServer4
- IdentityServer4.AspNetIdentity
- IdentityServer4.EntityFramework
- ソーシャルログイン
私は、IdentityServer4.Samples\Quickstart6_AspNetIdentity コードを nuget の後に統合された nuget から始めました。
// spa
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseCors("any");
// api
app.Map(new PathString("/api"), map =>
{
map.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = PublicHostUri,
ScopeName = ScopeName,
ScopeSecret = "secret",
RequireHttpsMetadata = PublicHostUri.ToLower().StartsWith("https"),
SaveToken = true,
EnableCaching = true
});
map.UseMvc();
});
// sts
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseIdentity();
app.UseIdentityServer();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
AutomaticAuthenticate = false,
AutomaticChallenge = false
});
app.UseTwitterAuthentication(new TwitterOptions
{
ConsumerKey = "6XaCTaLbMqfj6ww3zvZ5g",
ConsumerSecret = "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI"
});
app.UseGoogleAuthentication(new GoogleOptions
{
AuthenticationScheme = "Google",
DisplayName = "Google",
SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com",
ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo"
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUi();
ベアラー AuthenticationScheme が /api パイプラインでアクティブな唯一の認証になるように、Web API 部分を分離するのに苦労しています。
現在、Cookie、Google、Twitter、OIDC、Bearer などの追加されたすべての AuthenticationSchemes が /api ルートに使用されています。
何が恋しいですか?/api が UseIdentityServerAuthentication 別名ベアラー トークン スキームを使用するだけではないのはなぜですか?
更新: ここで動作する概念実証コードを共有しましたhttps://github.com/ChrisRichner/CoreWebApp.Quickstart