//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OAuth2.Messages { using System; using System.Net; using Messaging; /// /// A response from the Authorization Server to the Client to indicate that a /// request for an access token renewal failed, probably due to an invalid /// refresh token. /// /// /// This message type is shared by the Web App, Rich App, and Username/Password profiles. /// internal class AccessTokenFailedResponse : MessageBase, IHttpDirectResponse { /// /// A value indicating whether this error response is in result to a request that had invalid client credentials which were supplied in the HTTP Authorization header. /// private readonly bool invalidClientCredentialsInAuthorizationHeader; /// /// The headers to include in the response. /// private readonly WebHeaderCollection headers = new WebHeaderCollection(); /// /// Initializes a new instance of the class. /// /// The faulty request. internal AccessTokenFailedResponse(AccessTokenRequestBase request) : base(request) { } /// /// Initializes a new instance of the class. /// /// The faulty request. /// A value indicating whether this error response is in result to a request that had invalid client credentials which were supplied in the HTTP Authorization header. internal AccessTokenFailedResponse(AccessTokenRequestBase request, bool invalidClientCredentialsInAuthorizationHeader) : base(request) { this.invalidClientCredentialsInAuthorizationHeader = invalidClientCredentialsInAuthorizationHeader; } /// /// Initializes a new instance of the class. /// /// The protocol version. internal AccessTokenFailedResponse(Version version = null) : base(version ?? Protocol.Default.Version) { } #region IHttpDirectResponse Members /// /// Gets the HTTP status code that the direct response should be sent with. /// HttpStatusCode IHttpDirectResponse.HttpStatusCode { get { return this.invalidClientCredentialsInAuthorizationHeader ? HttpStatusCode.Unauthorized : HttpStatusCode.BadRequest; } } /// /// Gets the HTTP headers to add to the response. /// /// May be an empty collection, but must not be null. public WebHeaderCollection Headers { get { return this.headers; } } #endregion /// /// Gets or sets the error. /// /// One of the values given in . [MessagePart(Protocol.error, IsRequired = true)] internal string Error { get; set; } /// /// Gets or sets a human readable description of the error. /// /// Human-readable text providing additional information, used to assist in the understanding and resolution of the error that occurred. [MessagePart(Protocol.error_description, IsRequired = false)] internal string ErrorDescription { get; set; } /// /// Gets or sets the location of the web page that describes the error and possible resolution. /// /// A URI identifying a human-readable web page with information about the error, used to provide the end-user with additional information about the error. [MessagePart(Protocol.error_uri, IsRequired = false)] internal Uri ErrorUri { get; set; } } }