diff options
Diffstat (limited to 'src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppAccessTokenRequest.cs')
-rw-r--r-- | src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppAccessTokenRequest.cs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppAccessTokenRequest.cs b/src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppAccessTokenRequest.cs new file mode 100644 index 0000000..904207e --- /dev/null +++ b/src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppAccessTokenRequest.cs @@ -0,0 +1,90 @@ +//----------------------------------------------------------------------- +// <copyright file="WebAppAccessTokenRequest.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.OAuthWrap.Messages { + using System; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OAuthWrap.ChannelElements; + using System.Diagnostics.Contracts; + + /// <summary> + /// A message sent by the Client directly to the Authorization Server to exchange + /// the verification code for an Access Token. + /// </summary> + /// <remarks> + /// Used by the Web App (and Rich App?) profiles. + /// </remarks> + internal class WebAppAccessTokenRequest : MessageBase { + /// <summary> + /// Initializes a new instance of the <see cref="WebAppAccessTokenRequest"/> class. + /// </summary> + /// <param name="accessTokenEndpoint">The Authorization Server's access token endpoint URL.</param> + /// <param name="version">The version.</param> + internal WebAppAccessTokenRequest(Uri accessTokenEndpoint, Version version) + : base(version, MessageTransport.Direct, accessTokenEndpoint) { + this.HttpMethods = HttpDeliveryMethods.PostRequest; + } + + /// <summary> + /// Initializes a new instance of the <see cref="WebAppAccessTokenRequest"/> class. + /// </summary> + /// <param name="authorizationServer">The authorization server.</param> + internal WebAppAccessTokenRequest(AuthorizationServerDescription authorizationServer) + : this(authorizationServer.AccessTokenEndpoint, authorizationServer.Version) { + Contract.Requires<ArgumentNullException>(authorizationServer != null); + Contract.Requires<ArgumentException>(authorizationServer.Version != null); + Contract.Requires<ArgumentException>(authorizationServer.AccessTokenEndpoint != null); + } + + /// <summary> + /// Gets or sets the identifier by which this client is known to the Authorization Server. + /// </summary> + /// <value>The client identifier.</value> + [MessagePart(Protocol.wrap_client_id, IsRequired = true, AllowEmpty = false)] + internal string ClientIdentifier { get; set; } + + /// <summary> + /// Gets or sets the client secret. + /// </summary> + /// <value>The client secret.</value> + [MessagePart(Protocol.wrap_client_secret, IsRequired = true, AllowEmpty = false)] + internal string ClientSecret { get; set; } + + /// <summary> + /// Gets or sets the verification code previously communicated to the Client + /// in <see cref="WebAppSuccessResponse.VerificationCode"/>. + /// </summary> + /// <value>The verification code.</value> + [MessagePart(Protocol.wrap_verification_code, IsRequired = true, AllowEmpty = false)] + internal string VerificationCode { get; set; } + + /// <summary> + /// Gets or sets the callback URL used in <see cref="WebAppRequest.Callback"/> + /// </summary> + /// <value> + /// The Callback URL used to obtain the Verification Code. + /// </value> + [MessagePart(Protocol.wrap_callback, IsRequired = true, AllowEmpty = false)] + internal Uri Callback { get; set; } + + /// <summary> + /// Checks the message state for conformity to the protocol specification + /// and throws an exception if the message is invalid. + /// </summary> + /// <remarks> + /// <para>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.</para> + /// <para>Note that this property should <i>not</i> check signatures or perform any state checks + /// outside this scope of this particular message.</para> + /// </remarks> + /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception> + protected override void EnsureValidMessage() { + base.EnsureValidMessage(); + ErrorUtilities.VerifyProtocol(this.Recipient.IsTransportSecure(), OAuthWrapStrings.HttpsRequired); + } + } +} |