예제 #1
0
        public static Task OnMessageReceived(MessageReceivedContext context)
        {
            var logger = GetLogger(context.HttpContext.RequestServices);

            AuthenticationLogMessages.HttpMessageReceiptHandling(logger);

            var options = context.HttpContext.RequestServices.GetRequiredService <IOptions <ApiAuthenticationOptions> >().Value;
            var cookies = context.Request.Cookies;

            if (cookies.TryGetValue(options.TokenHeaderAndPayloadCookieKey, out var tokenHeaderAndPayload) &&
                cookies.TryGetValue(options.TokenSignatureCookieKey, out var tokenSignature))
            {
                context.Token = $"{tokenHeaderAndPayload}.{tokenSignature}";
                AuthenticationLogMessages.AuthenticationTokenExtracted(logger, context.Token);
            }
            AuthenticationLogMessages.AuthenticationTokenNotFound(logger, options.TokenHeaderAndPayloadCookieKey, options.TokenSignatureCookieKey);

            AuthenticationLogMessages.HttpMessageReceiptHandled(logger);
            return(Task.CompletedTask);
        }