//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth2.Messages {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using DotNetOpenAuth.Configuration;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2.ChannelElements;
using Validation;
///
/// A message sent by a web application Client to the AuthorizationServer
/// via the user agent to obtain authorization from the user and prepare
/// to issue an access token to the client if permission is granted.
///
[Serializable]
public class EndUserAuthorizationRequest : MessageBase {
///
/// Gets the grant type that the client expects of the authorization server.
///
/// Always . Other response types are not supported.
[MessagePart(Protocol.response_type, IsRequired = true, Encoder = typeof(EndUserAuthorizationResponseTypeEncoder))]
private const EndUserAuthorizationResponseType ResponseTypeConst = EndUserAuthorizationResponseType.AuthorizationCode;
///
/// Initializes a new instance of the class.
///
/// The Authorization Server's user authorization URL to direct the user to.
/// The protocol version.
protected EndUserAuthorizationRequest(Uri authorizationEndpoint, Version version)
: base(version, MessageTransport.Indirect, authorizationEndpoint) {
Requires.NotNull(authorizationEndpoint, "authorizationEndpoint");
Requires.NotNull(version, "version");
this.HttpMethods = HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.PostRequest;
this.Scope = new HashSet(OAuthUtilities.ScopeStringComparer);
}
///
/// Gets the grant type that the client expects of the authorization server.
///
public virtual EndUserAuthorizationResponseType ResponseType {
get { return ResponseTypeConst; }
}
///
/// Gets or sets the identifier by which this client is known to the Authorization Server.
///
[MessagePart(Protocol.client_id, IsRequired = true)]
public string ClientIdentifier { get; set; }
///
/// Gets or sets the callback URL.
///
///
/// An absolute URL to which the Authorization Server will redirect the User back after
/// the user has approved the authorization request.
///
///
/// REQUIRED unless a redirection URI has been established between the client and authorization server via other means. An absolute URI to which the authorization server will redirect the user-agent to when the end-user authorization step is completed. The authorization server MAY require the client to pre-register their redirection URI. The redirection URI MUST NOT include a query component as defined by [RFC3986] (Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005.) section 3 if the state parameter is present.
///
[MessagePart(Protocol.redirect_uri, IsRequired = false)]
public Uri Callback { get; set; }
///
/// Gets or sets state of the client that should be sent back with the authorization response.
///
///
/// An opaque value that Clients can use to maintain state associated with this request.
///
///
/// This data is proprietary to the client and should be considered an opaque string to the
/// authorization server.
///
[MessagePart(Protocol.state, IsRequired = false)]
public string ClientState { get; set; }
///
/// Gets the scope of access being requested.
///
/// The scope of the access request expressed as a list of space-delimited strings. The value of the scope parameter is defined by the authorization server. If the value contains multiple space-delimited strings, their order does not matter, and each string adds an additional access range to the requested scope.
[MessagePart(Protocol.scope, IsRequired = false, Encoder = typeof(ScopeEncoder))]
public HashSet Scope { get; private set; }
///
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
///
/// Thrown if the message is invalid.
protected override void EnsureValidMessage() {
base.EnsureValidMessage();
ErrorUtilities.VerifyProtocol(
DotNetOpenAuthSection.Messaging.RelaxSslRequirements || this.Recipient.IsTransportSecure(),
OAuthStrings.HttpsRequired);
ErrorUtilities.VerifyProtocol(this.Callback == null || this.Callback.IsAbsoluteUri, this, OAuthStrings.AbsoluteUriRequired, Protocol.redirect_uri);
}
}
}