diff options
Diffstat (limited to 'src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessResponse.cs')
-rw-r--r-- | src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessResponse.cs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessResponse.cs b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessResponse.cs index 8a90572..6d4ce40 100644 --- a/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessResponse.cs +++ b/src/DotNetOpenAuth/OAuth2/Messages/EndUserAuthorizationSuccessResponse.cs @@ -15,7 +15,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// to indicate that user authorization was granted, and to return the user /// to the Client where they started their experience. /// </summary> - internal class EndUserAuthorizationSuccessResponse : MessageBase, IMessageWithClientState { + internal class EndUserAuthorizationSuccessResponse : MessageBase, IMessageWithClientState, ITokenCarryingRequest { /// <summary> /// Initializes a new instance of the <see cref="EndUserAuthorizationSuccessResponse"/> class. /// </summary> @@ -39,7 +39,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { ((IMessageWithClientState)this).ClientState = request.ClientState; } - [MessagePart(Protocol.code, AllowEmpty = false, IsRequired = false)] + [MessagePart(Protocol.code, AllowEmpty = false, IsRequired = true)] // TODO: this isn't required when the access_token part is present. internal string AuthorizationCode { get; set; } [MessagePart(Protocol.access_token, AllowEmpty = false, IsRequired = false)] @@ -73,5 +73,43 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// Gets or sets the authorizing user's account name. /// </summary> internal string AuthorizingUsername { get; set; } + + #region ITokenCarryingRequest Members + + string ITokenCarryingRequest.CodeOrToken { + get { return this.AuthorizationCode; } + set { this.AuthorizationCode = value;} + } + + CodeOrTokenType ITokenCarryingRequest.CodeOrTokenType { + get { return CodeOrTokenType.AuthorizationCode; } + } + + IAuthorizationDescription ITokenCarryingRequest.AuthorizationDescription { get; set; } + + #endregion + + /// <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( + !string.IsNullOrEmpty(this.AuthorizationCode) || !string.IsNullOrEmpty(this.AccessToken), + MessagingStrings.RequiredParametersMissing, + this.GetType().Name, + string.Join(", ", new string[] { Protocol.code,Protocol.access_token})); + } } } |