CookieAuthenticationMiddlewareの元のCookieはどのように作成されますか。
クッキー認証ミドルウェアがユーザーに署名し、クッキーを作成します。クッキー承認ミドルウェアは、クッキー値を探します。
説明すると、a few lines from the CookieAuthenticationHandler
は、クッキー認証ミドルウェアがクッキーを設定していることを示しています。
Options.CookieManager.AppendResponseCookie(
Context,
Options.CookieName,
cookieValue,
cookieOptions);
そしてここでは、コンテキストに追加されたクッキーの値を探して承認ミドルウェアを示しa few lines from the DenyAnonymousAuthorizationRequirement : IAuthorizationHandler
あります。
var user = context.User;
var userIsAnonymous =
user?.Identity == null ||
!user.Identities.Any(i => i.IsAuthenticated);
if (!userIsAnonymous)
{
context.Succeed(requirement);
}
ます。また、この質問:...
をどのようにFacebookの認証は、クッキー認証ミドルウェアを認識することになるクッキーを設定するのでしょうか?
Facebook認証はOAuth認証で、これは次の継承階層の最下部にあることを意味します。 FacebookのOAuthので
IAuthenticationHandler
└── AuthenticationHandler
└── CookieAuthenticationHandler
└── RemoteAuthenticationHandler
└── OAuthHandler
└── FacebookHandler
、
RemoteAuthenticationHander.HandleRemoteCallbackAsync
は、Facebookの応答を処理した後、
SignInAsync
を呼び出します。
Context.Authentication.SignInAsync(
Options.SignInScheme,
context.Principal,
context.Properties);
SignInAsync
への呼び出しは、あなたの質問で仮説したものです。
... Facebookミドルウェアは[SignInAsync]を呼び出してクッキーを設定しますが、このメソッドが何をしているのかは分かりません。
SignInAsync
とは何ですか? SignInAsync
の呼び出しは、Context.Authentication
プロパティの内部にあるAuthenticationManager
のインスタンスで発生します。そのインスタンスは通常DefaultAuthenticationManager
です。 the full SignInAsync
call hereが表示され、ここから抜粋したものです。すなわち
public override async Task SignInAsync(
string authenticationScheme,
ClaimsPrincipal principal,
AuthenticationProperties properties)
{
...
var handler = HttpAuthenticationFeature.Handler;
var signInContext = new SignInContext(
authenticationScheme,
principal,
properties?.Items);
if (handler != null)
{
await handler.SignInAsync(signInContext);
}
...
}
、SignInAsync
コール継承階層からIAuthenticationHandler
のインスタンスであることを起こる認証ハンドラにSignInAsync
。
最終的にはCookieAuthenticationHandler.HandleSigninAsync
に到着しました。which will append the cookie to the response.このクッキーハンドラには、セキュリティリポジトリにAppendResponseCookie
という2つのコールしか含まれていません。
protected override async Task HandleSignInAsync(SignInContext signin)
{
...
Options.CookieManager.AppendResponseCookie(
Context,
Options.CookieName,
cookieValue,
signInContext.CookieOptions);
...
}
多くの可動部品があります。うまくいけば、この答えはあなた自身が不足している作品を埋めるために十分な概要を与えます。
オープンソースのasp.netについての素晴らしいところは、あなたはソースコードを勉強することができます。 Cookieミドルウェアやその他のセキュリティコンポーネントの内部について詳しく知りたい場合は、こちらのコードをご覧ください。https://github.com/aspnet/Security –