//----------------------------------------------------------------------- // // 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.Messaging; using DotNetOpenAuth.OAuth2.ChannelElements; /// /// A request from a Client to an Authorization Server to exchange the user's username and password for an access token. /// internal class AccessTokenResourceOwnerPasswordCredentialsRequest : ScopedAccessTokenRequest, IAuthorizationCarryingRequest, IAuthorizationDescription { /// /// Initializes a new instance of the class. /// /// The access token endpoint. /// The protocol version. internal AccessTokenResourceOwnerPasswordCredentialsRequest(Uri accessTokenEndpoint, Version version) : base(accessTokenEndpoint, version) { } #region IAuthorizationCarryingRequest members /// /// Gets the authorization that the code or token describes. /// IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription { get { return this.CredentialsValidated ? this : null; } } #endregion #region IAuthorizationDescription Members /// /// Gets the date this authorization was established or the token was issued. /// /// A date/time expressed in UTC. DateTime IAuthorizationDescription.UtcIssued { get { return DateTime.UtcNow; } } /// /// Gets the name on the account whose data on the resource server is accessible using this authorization. /// string IAuthorizationDescription.User { get { return this.RequestingUserName; } } /// /// Gets the scope of operations the client is allowed to invoke. /// HashSet IAuthorizationDescription.Scope { get { return this.Scope; } } #endregion /// /// Gets the username of the authorizing user, when applicable. /// /// /// A non-empty string; or null when no user has authorized this access token. /// public override string UserName { get { return base.UserName ?? this.RequestingUserName; } } /// /// Gets the type of the grant. /// /// The type of the grant. internal override GrantType GrantType { get { return Messages.GrantType.Password; } } /// /// Gets or sets the user's account username. /// /// The username on the user's account. [MessagePart(Protocol.username, IsRequired = true)] internal string RequestingUserName { get; set; } /// /// Gets or sets the user's password. /// /// The password. [MessagePart(Protocol.password, IsRequired = true, IsSecuritySensitive = true)] internal string Password { get; set; } /// /// Gets or sets a value indicating whether the resource owner's credentials have been validated at the authorization server. /// internal bool CredentialsValidated { get; set; } } }