Logging API changes
This commit is contained in:
parent
0577454f13
commit
329d826857
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
|
|
||||||
if (ticket == null)
|
if (ticket == null)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning(@"Unprotect ticket failed");
|
_logger.LogWarning(@"Unprotect ticket failed");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,14 +62,14 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
Claim claim = ticket.Principal.Claims.FirstOrDefault(c => c.Type.Equals(SessionIdClaim));
|
Claim claim = ticket.Principal.Claims.FirstOrDefault(c => c.Type.Equals(SessionIdClaim));
|
||||||
if (claim == null)
|
if (claim == null)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning(@"SessionId missing");
|
_logger.LogWarning(@"SessionId missing");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_sessionKey = claim.Value;
|
_sessionKey = claim.Value;
|
||||||
ticket = await Options.SessionStore.RetrieveAsync(_sessionKey);
|
ticket = await Options.SessionStore.RetrieveAsync(_sessionKey);
|
||||||
if (ticket == null)
|
if (ticket == null)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning(@"Identity missing in session store");
|
_logger.LogWarning(@"Identity missing in session store");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
Options.CookieManager = new ChunkingCookieManager();
|
Options.CookieManager = new ChunkingCookieManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger = loggerFactory.Create(typeof(CookieAuthenticationMiddleware).FullName);
|
_logger = loggerFactory.CreateLogger(typeof(CookieAuthenticationMiddleware).FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override AuthenticationHandler<CookieAuthenticationOptions> CreateHandler()
|
protected override AuthenticationHandler<CookieAuthenticationOptions> CreateHandler()
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
AuthenticationTicket ticket = await AuthenticateAsync();
|
AuthenticationTicket ticket = await AuthenticateAsync();
|
||||||
if (ticket == null)
|
if (ticket == null)
|
||||||
{
|
{
|
||||||
Logger.WriteWarning("Invalid return state, unable to redirect.");
|
Logger.LogWarning("Invalid return state, unable to redirect.");
|
||||||
Response.StatusCode = 500;
|
Response.StatusCode = 500;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
var value = query.Get("error");
|
var value = query.Get("error");
|
||||||
if (!string.IsNullOrEmpty(value))
|
if (!string.IsNullOrEmpty(value))
|
||||||
{
|
{
|
||||||
Logger.WriteVerbose("Remote server returned an error: " + Request.QueryString);
|
Logger.LogVerbose("Remote server returned an error: " + Request.QueryString);
|
||||||
// TODO: Fail request rather than passing through?
|
// TODO: Fail request rather than passing through?
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(tokens.AccessToken))
|
if (string.IsNullOrWhiteSpace(tokens.AccessToken))
|
||||||
{
|
{
|
||||||
Logger.WriteWarning("Access token was not found");
|
Logger.LogWarning("Access token was not found");
|
||||||
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.WriteError("Authentication failed", ex);
|
Logger.LogError("Authentication failed", ex);
|
||||||
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "TokenEndpoint"));
|
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "TokenEndpoint"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger = loggerFactory.Create(this.GetType().FullName);
|
Logger = loggerFactory.CreateLogger(this.GetType().FullName);
|
||||||
|
|
||||||
if (Options.StateDataFormat == null)
|
if (Options.StateDataFormat == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.WriteError("Exception occurred while processing message", ex);
|
_logger.LogError("Exception occurred while processing message", ex);
|
||||||
|
|
||||||
// Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification.
|
// Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification.
|
||||||
if (Options.RefreshOnIssuerKeyNotFound && ex.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
if (Options.RefreshOnIssuerKeyNotFound && ex.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Authentication.OAuthBearer
|
||||||
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions)
|
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions)
|
||||||
: base(next, services, options, configureOptions)
|
: base(next, services, options, configureOptions)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.Create<OAuthBearerAuthenticationMiddleware>();
|
_logger = loggerFactory.CreateLogger<OAuthBearerAuthenticationMiddleware>();
|
||||||
if (Options.Notifications == null)
|
if (Options.Notifications == null)
|
||||||
{
|
{
|
||||||
Options.Notifications = new OAuthBearerAuthenticationNotifications();
|
Options.Notifications = new OAuthBearerAuthenticationNotifications();
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions)
|
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions)
|
||||||
: base(next, services, options, configureOptions)
|
: base(next, services, options, configureOptions)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.Create<OpenIdConnectAuthenticationMiddleware>();
|
_logger = loggerFactory.CreateLogger<OpenIdConnectAuthenticationMiddleware>();
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Options.TokenValidationParameters.AuthenticationType))
|
if (string.IsNullOrWhiteSpace(Options.TokenValidationParameters.AuthenticationType))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
string redirectUri = notification.ProtocolMessage.CreateLogoutRequestUrl();
|
string redirectUri = notification.ProtocolMessage.CreateLogoutRequestUrl();
|
||||||
if (!Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute))
|
if (!Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute))
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("The logout redirect URI is malformed: {0}", (redirectUri ?? "null"));
|
_logger.LogWarning("The logout redirect URI is malformed: {0}", (redirectUri ?? "null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Response.Redirect(redirectUri);
|
Response.Redirect(redirectUri);
|
||||||
|
|
@ -195,7 +195,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
string redirectUri = notification.ProtocolMessage.CreateAuthenticationRequestUrl();
|
string redirectUri = notification.ProtocolMessage.CreateAuthenticationRequestUrl();
|
||||||
if (!Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute))
|
if (!Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute))
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute) returned 'false', redirectUri is: {0}", (redirectUri ?? "null"));
|
_logger.LogWarning("Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute) returned 'false', redirectUri is: {0}", (redirectUri ?? "null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Response.Redirect(redirectUri);
|
Response.Redirect(redirectUri);
|
||||||
|
|
@ -262,7 +262,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
AuthenticationProperties properties = GetPropertiesFromState(openIdConnectMessage.State);
|
AuthenticationProperties properties = GetPropertiesFromState(openIdConnectMessage.State);
|
||||||
if (properties == null)
|
if (properties == null)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("The state field is missing or invalid.");
|
_logger.LogWarning("The state field is missing or invalid.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,7 +279,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
// OpenIdConnect protocol allows a Code to be received without the id_token
|
// OpenIdConnect protocol allows a Code to be received without the id_token
|
||||||
if (string.IsNullOrWhiteSpace(openIdConnectMessage.IdToken))
|
if (string.IsNullOrWhiteSpace(openIdConnectMessage.IdToken))
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("The id_token is missing.");
|
_logger.LogWarning("The id_token is missing.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -424,7 +424,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
_logger.WriteError("Exception occurred while processing message", exception);
|
_logger.LogError("Exception occurred while processing message", exception);
|
||||||
|
|
||||||
// Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification.
|
// Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification.
|
||||||
if (Options.RefreshOnIssuerKeyNotFound && exception.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
if (Options.RefreshOnIssuerKeyNotFound && exception.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||||
|
|
@ -511,7 +511,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("Failed to un-protect the nonce cookie.", ex);
|
_logger.LogWarning("Failed to un-protect the nonce cookie.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
|
|
||||||
if (requestToken == null)
|
if (requestToken == null)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("Invalid state");
|
_logger.LogWarning("Invalid state");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,20 +71,20 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
string returnedToken = query.Get("oauth_token");
|
string returnedToken = query.Get("oauth_token");
|
||||||
if (string.IsNullOrWhiteSpace(returnedToken))
|
if (string.IsNullOrWhiteSpace(returnedToken))
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("Missing oauth_token");
|
_logger.LogWarning("Missing oauth_token");
|
||||||
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnedToken != requestToken.Token)
|
if (returnedToken != requestToken.Token)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("Unmatched token");
|
_logger.LogWarning("Unmatched token");
|
||||||
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
string oauthVerifier = query.Get("oauth_verifier");
|
string oauthVerifier = query.Get("oauth_verifier");
|
||||||
if (string.IsNullOrWhiteSpace(oauthVerifier))
|
if (string.IsNullOrWhiteSpace(oauthVerifier))
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("Missing or blank oauth_verifier");
|
_logger.LogWarning("Missing or blank oauth_verifier");
|
||||||
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,7 +120,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.WriteError("Authentication failed", ex);
|
_logger.LogError("Authentication failed", ex);
|
||||||
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
return new AuthenticationTicket(properties, Options.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +180,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.WriteError("requestToken CallbackConfirmed!=true");
|
_logger.LogError("requestToken CallbackConfirmed!=true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
AuthenticationTicket model = await AuthenticateAsync();
|
AuthenticationTicket model = await AuthenticateAsync();
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
_logger.WriteWarning("Invalid return state, unable to redirect.");
|
_logger.LogWarning("Invalid return state, unable to redirect.");
|
||||||
Response.StatusCode = 500;
|
Response.StatusCode = 500;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -224,7 +224,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
|
|
||||||
private async Task<RequestToken> ObtainRequestTokenAsync(string consumerKey, string consumerSecret, string callBackUri, AuthenticationProperties properties)
|
private async Task<RequestToken> ObtainRequestTokenAsync(string consumerKey, string consumerSecret, string callBackUri, AuthenticationProperties properties)
|
||||||
{
|
{
|
||||||
_logger.WriteVerbose("ObtainRequestToken");
|
_logger.LogVerbose("ObtainRequestToken");
|
||||||
|
|
||||||
string nonce = Guid.NewGuid().ToString("N");
|
string nonce = Guid.NewGuid().ToString("N");
|
||||||
|
|
||||||
|
|
@ -285,7 +285,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
{
|
{
|
||||||
// https://dev.twitter.com/docs/api/1/post/oauth/access_token
|
// https://dev.twitter.com/docs/api/1/post/oauth/access_token
|
||||||
|
|
||||||
_logger.WriteVerbose("ObtainAccessToken");
|
_logger.LogVerbose("ObtainAccessToken");
|
||||||
|
|
||||||
string nonce = Guid.NewGuid().ToString("N");
|
string nonce = Guid.NewGuid().ToString("N");
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
_logger.WriteError("AccessToken request failed with a status code of " + response.StatusCode);
|
_logger.LogError("AccessToken request failed with a status code of " + response.StatusCode);
|
||||||
response.EnsureSuccessStatusCode(); // throw
|
response.EnsureSuccessStatusCode(); // throw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "ConsumerKey"));
|
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "ConsumerKey"));
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger = loggerFactory.Create(typeof(TwitterAuthenticationMiddleware).FullName);
|
_logger = loggerFactory.CreateLogger(typeof(TwitterAuthenticationMiddleware).FullName);
|
||||||
|
|
||||||
if (Options.Notifications == null)
|
if (Options.Notifications == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -408,7 +408,7 @@ namespace Microsoft.AspNet.Authentication
|
||||||
string correlationCookie = Request.Cookies[correlationKey];
|
string correlationCookie = Request.Cookies[correlationKey];
|
||||||
if (string.IsNullOrWhiteSpace(correlationCookie))
|
if (string.IsNullOrWhiteSpace(correlationCookie))
|
||||||
{
|
{
|
||||||
logger.WriteWarning("{0} cookie not found.", correlationKey);
|
logger.LogWarning("{0} cookie not found.", correlationKey);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -424,7 +424,7 @@ namespace Microsoft.AspNet.Authentication
|
||||||
correlationKey,
|
correlationKey,
|
||||||
out correlationExtra))
|
out correlationExtra))
|
||||||
{
|
{
|
||||||
logger.WriteWarning("{0} state property not found.", correlationKey);
|
logger.LogWarning("{0} state property not found.", correlationKey);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -432,7 +432,7 @@ namespace Microsoft.AspNet.Authentication
|
||||||
|
|
||||||
if (!string.Equals(correlationCookie, correlationExtra, StringComparison.Ordinal))
|
if (!string.Equals(correlationCookie, correlationExtra, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
logger.WriteWarning("{0} correlation cookie and state property mismatch.", correlationKey);
|
logger.LogWarning("{0} correlation cookie and state property mismatch.", correlationKey);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue