using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Http; namespace OAuth.AspNet.AuthServer { /// /// Base class used for certain event contexts /// public abstract class BaseValidatingContext : BaseContext { /// /// Initializes base class used for certain event contexts /// protected BaseValidatingContext(HttpContext context, TOptions options) : base(context) { Options = options; } /// /// The context options. /// public TOptions Options { get; private set; } /// /// True if application code has called any of the Validate methods on this context. /// public bool IsValidated { get; private set; } /// /// True if application code has called any of the SetError methods on this context. /// public bool HasError { get; private set; } /// /// The error argument provided when SetError was called on this context. This is eventually /// returned to the client app as the OAuth "error" parameter. /// public string Error { get; private set; } /// /// The optional errorDescription argument provided when SetError was called on this context. This is eventually /// returned to the client app as the OAuth "error_description" parameter. /// public string ErrorDescription { get; private set; } /// /// The optional errorUri argument provided when SetError was called on this context. This is eventually /// returned to the client app as the OAuth "error_uri" parameter. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "error_uri is a string value in the protocol")] public string ErrorUri { get; private set; } /// /// Marks this context as validated by the application. IsValidated becomes true and HasError becomes false as a result of calling. /// /// True if the validation has taken effect. public virtual bool Validated() { IsValidated = true; HasError = false; return true; } /// /// Marks this context as not validated by the application. IsValidated and HasError become false as a result of calling. /// public virtual void Rejected() { IsValidated = false; HasError = false; } /// /// Marks this context as not validated by the application and assigns various error information properties. /// HasError becomes true and IsValidated becomes false as a result of calling. /// /// Assigned to the Error property public void SetError(string error) { SetError(error, null); } /// /// Marks this context as not validated by the application and assigns various error information properties. /// HasError becomes true and IsValidated becomes false as a result of calling. /// /// Assigned to the Error property /// Assigned to the ErrorDescription property public void SetError(string error, string errorDescription) { SetError(error, errorDescription, null); } /// /// Marks this context as not validated by the application and assigns various error information properties. /// HasError becomes true and IsValidated becomes false as a result of calling. /// /// Assigned to the Error property /// Assigned to the ErrorDescription property /// Assigned to the ErrorUri property [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "2#", Justification = "error_uri is a string value in the protocol")] public void SetError(string error, string errorDescription, string errorUri) { Error = error; ErrorDescription = errorDescription; ErrorUri = errorUri; Rejected(); HasError = true; } } }