//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth2.Messages {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Configuration;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2.ChannelElements;
///
/// A message sent from the client to the authorization server to exchange a previously obtained grant for an access token.
///
public abstract class AccessTokenRequestBase : AuthenticatedClientRequestBase, IAccessTokenRequestInternal, IDisposable {
///
/// Initializes a new instance of the class.
///
/// The Authorization Server's access token endpoint URL.
/// The version.
protected AccessTokenRequestBase(Uri tokenEndpoint, Version version)
: base(tokenEndpoint, version) {
this.HttpMethods = HttpDeliveryMethods.PostRequest;
}
///
/// Gets the scope of operations the client is allowed to invoke.
///
HashSet IAccessTokenRequest.Scope {
get { return this.RequestedScope; }
}
///
/// Gets a value indicating whether the client requesting the access token has authenticated itself.
///
///
/// Always true, because of our base class.
///
public bool ClientAuthenticated { get; internal set; }
///
/// Gets or sets the access token creation parameters.
///
///
/// This property's value is set by a binding element in the OAuth 2 channel.
///
AccessTokenParameters IAccessTokenRequestInternal.AccessTokenCreationParameters { get; set; }
///
/// Gets the type of the grant.
///
/// The type of the grant.
[MessagePart(Protocol.grant_type, IsRequired = true, Encoder = typeof(GrantTypeEncoder))]
internal abstract GrantType GrantType { get; }
///
/// Gets the scope of operations the client is allowed to invoke.
///
protected abstract HashSet RequestedScope { get; }
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Releases unmanaged and - optionally - managed resources
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing) {
IAccessTokenRequestInternal self = this;
if (self.AccessTokenCreationParameters != null) {
self.AccessTokenCreationParameters.Dispose();
}
}
///
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
///
///
/// Some messages have required fields, or combinations of fields that must relate to each other
/// in specialized ways. After deserializing a message, this method checks the state of the
/// message to see if it conforms to the protocol.
/// Note that this property should not check signatures or perform any state checks
/// outside this scope of this particular message.
///
/// Thrown if the message is invalid.
protected override void EnsureValidMessage() {
base.EnsureValidMessage();
ErrorUtilities.VerifyProtocol(
DotNetOpenAuthSection.Messaging.RelaxSslRequirements || this.Recipient.IsTransportSecure(),
OAuthStrings.HttpsRequired);
}
}
}