diff options
Diffstat (limited to 'src')
10 files changed, 308 insertions, 15 deletions
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj index 95b1cfd..5a0de45 100644 --- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj +++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj @@ -512,13 +512,18 @@ <Compile Include="SimpleAuth\ChannelElements\SimpleAuthMessageFactory.cs" /> <Compile Include="SimpleAuth\ChannelElements\UriOrOutOfBandEncoding.cs" /> <Compile Include="SimpleAuth\ConsumerBase.cs" /> - <Compile Include="SimpleAuth\Messages\AccessTokenWithDelegationCodeFailedResponse.cs" /> - <Compile Include="SimpleAuth\Messages\AccessTokenWithDelegationCodeSuccessResponse.cs" /> + <Compile Include="SimpleAuth\Messages\AccessTokenFailedResponse.cs" /> + <Compile Include="SimpleAuth\Messages\AccessTokenSuccessResponse.cs" /> + <Compile Include="SimpleAuth\Messages\AccessTokenWithConsumerNamePasswordRequest.cs" /> + <Compile Include="SimpleAuth\Messages\AccessTokenWithSamlRequest.cs" /> <Compile Include="SimpleAuth\Messages\MessageBase.cs" /> <Compile Include="SimpleAuth\Messages\AccessTokenWithDelegationCodeRequest.cs" /> <Compile Include="SimpleAuth\Messages\UserAuthorizationInUserAgentDeniedResponse.cs" /> <Compile Include="SimpleAuth\Messages\UserAuthorizationInUserAgentRequest.cs" /> <Compile Include="SimpleAuth\Messages\UserAuthorizationInUserAgentGrantedResponse.cs" /> + <Compile Include="SimpleAuth\Messages\UserAuthorizationViaUsernamePasswordFailedResponse.cs" /> + <Compile Include="SimpleAuth\Messages\UserAuthorizationViaUsernamePasswordRequest.cs" /> + <Compile Include="SimpleAuth\Messages\UserAuthorizationViaUsernamePasswordSuccessResponse.cs" /> <Compile Include="SimpleAuth\Protocol.cs" /> <Compile Include="SimpleAuth\SimpleAuthStrings.Designer.cs"> <AutoGen>True</AutoGen> diff --git a/src/DotNetOpenAuth/SimpleAuth/ChannelElements/SimpleAuthMessageFactory.cs b/src/DotNetOpenAuth/SimpleAuth/ChannelElements/SimpleAuthMessageFactory.cs index fea103d..9128d3b 100644 --- a/src/DotNetOpenAuth/SimpleAuth/ChannelElements/SimpleAuthMessageFactory.cs +++ b/src/DotNetOpenAuth/SimpleAuth/ChannelElements/SimpleAuthMessageFactory.cs @@ -45,6 +45,18 @@ namespace DotNetOpenAuth.SimpleAuth.ChannelElements { return new AccessTokenWithDelegationCodeRequest(recipient.Location, version); } + if (fields.ContainsKey(Protocol.sa_name)) { + return new AccessTokenWithConsumerNamePasswordRequest(version); + } + + if (fields.ContainsKey(Protocol.sa_username)) { + return new UserAuthorizationViaUsernamePasswordRequest(version); + } + + if (fields.ContainsKey(Protocol.sa_saml)) { + return new AccessTokenWithSamlRequest(version); + } + if (fields.ContainsKey(Protocol.sa_delegation_code)) { return new UserAuthorizationInUserAgentGrantedResponse(recipient.Location, version); } @@ -72,9 +84,18 @@ namespace DotNetOpenAuth.SimpleAuth.ChannelElements { var accessTokenRequest = request as AccessTokenWithDelegationCodeRequest; if (accessTokenRequest != null) { if (fields.ContainsKey(Protocol.sa_token)) { - return new AccessTokenWithDelegationCodeSuccessResponse(accessTokenRequest); + return new AccessTokenSuccessResponse(accessTokenRequest); + } else { + return new AccessTokenFailedResponse(accessTokenRequest); + } + } + + var userAuthorization = request as UserAuthorizationViaUsernamePasswordRequest; + if (userAuthorization != null) { + if (fields.ContainsKey(Protocol.sa_delegation_code)) { + return new UserAuthorizationViaUsernamePasswordSuccessResponse(userAuthorization); } else { - return new AccessTokenWithDelegationCodeFailedResponse(accessTokenRequest); + return new UserAuthorizationViaUsernamePasswordFailedResponse(userAuthorization); } } diff --git a/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithDelegationCodeFailedResponse.cs b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenFailedResponse.cs index 1676083..7139beb 100644 --- a/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithDelegationCodeFailedResponse.cs +++ b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenFailedResponse.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------- -// <copyright file="AccessTokenWithDelegationCodeFailedResponse.cs" company="Andrew Arnott"> +// <copyright file="AccessTokenFailedResponse.cs" company="Andrew Arnott"> // Copyright (c) Andrew Arnott. All rights reserved. // </copyright> //----------------------------------------------------------------------- @@ -15,12 +15,12 @@ namespace DotNetOpenAuth.SimpleAuth.Messages { /// The direct response message that may contain the reason the access token /// was NOT returned from the Token Issuer to the Consumer. /// </summary> - internal class AccessTokenWithDelegationCodeFailedResponse : MessageBase { + internal class AccessTokenFailedResponse : MessageBase { /// <summary> - /// Initializes a new instance of the <see cref="AccessTokenWithDelegationCodeFailedResponse"/> class. + /// Initializes a new instance of the <see cref="AccessTokenFailedResponse"/> class. /// </summary> /// <param name="request">The request.</param> - internal AccessTokenWithDelegationCodeFailedResponse(AccessTokenWithDelegationCodeRequest request) + internal AccessTokenFailedResponse(AccessTokenWithDelegationCodeRequest request) : base(request) { } diff --git a/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithDelegationCodeSuccessResponse.cs b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenSuccessResponse.cs index 7c807a7..ff7d827 100644 --- a/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithDelegationCodeSuccessResponse.cs +++ b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenSuccessResponse.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------- -// <copyright file="AccessTokenWithDelegationCodeSuccessResponse.cs" company="Andrew Arnott"> +// <copyright file="AccessTokenSuccessResponse.cs" company="Andrew Arnott"> // Copyright (c) Andrew Arnott. All rights reserved. // </copyright> //----------------------------------------------------------------------- @@ -12,12 +12,20 @@ namespace DotNetOpenAuth.SimpleAuth.Messages { /// The direct response message that contains the access token from the Token Issuer /// to the Consumer. /// </summary> - internal class AccessTokenWithDelegationCodeSuccessResponse : MessageBase { + internal class AccessTokenSuccessResponse : MessageBase { /// <summary> - /// Initializes a new instance of the <see cref="AccessTokenWithDelegationCodeSuccessResponse"/> class. + /// Initializes a new instance of the <see cref="AccessTokenSuccessResponse"/> class. /// </summary> /// <param name="request">The request.</param> - internal AccessTokenWithDelegationCodeSuccessResponse(AccessTokenWithDelegationCodeRequest request) + internal AccessTokenSuccessResponse(AccessTokenWithDelegationCodeRequest request) + : base(request) { + } + + /// <summary> + /// Initializes a new instance of the <see cref="AccessTokenSuccessResponse"/> class. + /// </summary> + /// <param name="request">The request.</param> + internal AccessTokenSuccessResponse(AccessTokenWithConsumerNamePasswordRequest request) : base(request) { } diff --git a/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithConsumerNamePasswordRequest.cs b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithConsumerNamePasswordRequest.cs new file mode 100644 index 0000000..e749319 --- /dev/null +++ b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithConsumerNamePasswordRequest.cs @@ -0,0 +1,41 @@ +//----------------------------------------------------------------------- +// <copyright file="AccessTokenWithConsumerNamePasswordRequest.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.SimpleAuth.Messages { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using DotNetOpenAuth.Messaging; + + /// <summary> + /// A request for an access token for a consumer application that has its + /// own (non-user affiliated) consumer name and password. + /// </summary> + internal class AccessTokenWithConsumerNamePasswordRequest : MessageBase { + /// <summary> + /// Initializes a new instance of the <see cref="AccessTokenWithConsumerNamePasswordRequest"/> class. + /// </summary> + /// <param name="version">The version.</param> + internal AccessTokenWithConsumerNamePasswordRequest(Version version) + : base(version) { + } + + /// <summary> + /// Gets or sets the account name. + /// </summary> + /// <value>The consumer name.</value> + [MessagePart(Protocol.sa_name, IsRequired = true, AllowEmpty = false)] + public string Name { get; set; } + + /// <summary> + /// Gets or sets the account password. + /// </summary> + /// <value>The password.</value> + [MessagePart(Protocol.sa_password, IsRequired = true, AllowEmpty = true)] + public string Password { get; set; } + } +} diff --git a/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithSamlRequest.cs b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithSamlRequest.cs new file mode 100644 index 0000000..489097e --- /dev/null +++ b/src/DotNetOpenAuth/SimpleAuth/Messages/AccessTokenWithSamlRequest.cs @@ -0,0 +1,45 @@ +//----------------------------------------------------------------------- +// <copyright file="AccessTokenWithSamlRequest.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.SimpleAuth.Messages { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using DotNetOpenAuth.Messaging; + + /// <summary> + /// A request for an access token for a consumer application that can + /// issue a SAML assertion to prove its identity. + /// </summary> + internal class AccessTokenWithSamlRequest : MessageBase { + /// <summary> + /// Initializes a new instance of the <see cref="AccessTokenWithSamlRequest"/> class. + /// </summary> + /// <param name="version">The version.</param> + internal AccessTokenWithSamlRequest(Version version) + : base(version) { + } + + /// <summary> + /// Gets or sets the SAML token. + /// </summary> + /// <value>A SAML token serialized as an XML document.</value> + [MessagePart(Protocol.sa_saml, IsRequired = true, AllowEmpty = false)] + public string Saml { get; set; } + + /// <summary> + /// Gets or sets the SWT. + /// </summary> + /// <value>The SWT (TODO: what is that?).</value> + /// <remarks> + /// The spec says that the SWT parameter is required for certain scenarios, + /// so we mark it as optional here since the scenario may or may not apply. + /// </remarks> + [MessagePart(Protocol.sa_swt, IsRequired = false, AllowEmpty = false)] + public string Swt { get; set; } + } +} diff --git a/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordFailedResponse.cs b/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordFailedResponse.cs new file mode 100644 index 0000000..a0a778d --- /dev/null +++ b/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordFailedResponse.cs @@ -0,0 +1,38 @@ +//----------------------------------------------------------------------- +// <copyright file="UserAuthorizationViaUsernamePasswordFailedResponse.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.SimpleAuth.Messages { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using DotNetOpenAuth.Messaging; + + /// <summary> + /// A response from the Token Issuer to the Consumer to indicate that a + /// request for a delegation code failed, probably due to an invalid + /// username and password. + /// </summary> + internal class UserAuthorizationViaUsernamePasswordFailedResponse : MessageBase { + /// <summary> + /// Initializes a new instance of the <see cref="UserAuthorizationViaUsernamePasswordFailedResponse"/> class. + /// </summary> + /// <param name="request">The request.</param> + internal UserAuthorizationViaUsernamePasswordFailedResponse(UserAuthorizationViaUsernamePasswordRequest request) + : base(request) { + } + + /// <summary> + /// Gets or sets the error reason. + /// </summary> + /// <value> + /// The reason for the failure. Among other values, it may be <c>null</c> + /// or invalid_user_credentials. + /// </value> + [MessagePart(Protocol.sa_error_reason, IsRequired = false, AllowEmpty = true)] + internal string ErrorReason { get; set; } + } +} diff --git a/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordRequest.cs b/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordRequest.cs new file mode 100644 index 0000000..68986b7 --- /dev/null +++ b/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordRequest.cs @@ -0,0 +1,76 @@ +//----------------------------------------------------------------------- +// <copyright file="UserAuthorizationViaUsernamePasswordRequest.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.SimpleAuth.Messages { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using DotNetOpenAuth.Messaging; + + /// <summary> + /// A request for a delegation code in exchnage for a user's confidential + /// username and password. + /// </summary> + /// <remarks> + /// After this request has been sent, the consumer application MUST discard + /// the confidential user credentials and use the delegation code going forward. + /// </remarks> + internal class UserAuthorizationViaUsernamePasswordRequest : MessageBase { + /// <summary> + /// Initializes a new instance of the <see cref="UserAuthorizationViaUsernamePasswordRequest"/> class. + /// </summary> + /// <param name="version">The version.</param> + internal UserAuthorizationViaUsernamePasswordRequest(Version version) + : base(version) { + } + + /// <summary> + /// Gets or sets the consumer key. + /// </summary> + /// <value>The consumer key.</value> + [MessagePart(Protocol.sa_consumer_key, IsRequired = true, AllowEmpty = false)] + internal string ConsumerKey { get; set; } + + /// <summary> + /// Gets or sets the consumer secret. + /// </summary> + /// <value>The consumer secret.</value> + [MessagePart(Protocol.sa_consumer_secret, IsRequired = true, AllowEmpty = false)] + internal string ConsumerSecret { get; set; } + + /// <summary> + /// Gets or sets the username. + /// </summary> + /// <value>The name of the user.</value> + [MessagePart(Protocol.sa_username, IsRequired = true, AllowEmpty = false)] + internal string UserName { get; set; } + + /// <summary> + /// Gets or sets the user's password. + /// </summary> + /// <value>The password.</value> + [MessagePart(Protocol.sa_password, IsRequired = true, AllowEmpty = false)] + internal string Password { 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(), SimpleAuthStrings.HttpsRequired); + } + } +} diff --git a/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordSuccessResponse.cs b/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordSuccessResponse.cs new file mode 100644 index 0000000..4ded3e2 --- /dev/null +++ b/src/DotNetOpenAuth/SimpleAuth/Messages/UserAuthorizationViaUsernamePasswordSuccessResponse.cs @@ -0,0 +1,37 @@ +//----------------------------------------------------------------------- +// <copyright file="UserAuthorizationViaUsernamePasswordSuccessResponse.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.SimpleAuth.Messages { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using DotNetOpenAuth.Messaging; + + /// <summary> + /// A response from the Token Issuer to the Consumer containing a delegation code + /// that the Consumer should use to obtain an access token. + /// </summary> + internal class UserAuthorizationViaUsernamePasswordSuccessResponse : MessageBase { + /// <summary> + /// Initializes a new instance of the <see cref="UserAuthorizationViaUsernamePasswordSuccessResponse"/> class. + /// </summary> + /// <param name="request">The request.</param> + internal UserAuthorizationViaUsernamePasswordSuccessResponse(UserAuthorizationViaUsernamePasswordRequest request) + : base(request) { + } + + /// <summary> + /// Gets or sets the delegation code. + /// </summary> + /// <value> + /// The long-lived credential assigned by the Token Issuer to this Consumer for + /// use in accessing the authorizing user's protected resources. + /// </value> + [MessagePart(Protocol.sa_delegation_code, IsRequired = true, AllowEmpty = true)] + internal string DelegationCode { get; set; } + } +} diff --git a/src/DotNetOpenAuth/SimpleAuth/Protocol.cs b/src/DotNetOpenAuth/SimpleAuth/Protocol.cs index ef6a4d0..0653c87 100644 --- a/src/DotNetOpenAuth/SimpleAuth/Protocol.cs +++ b/src/DotNetOpenAuth/SimpleAuth/Protocol.cs @@ -7,9 +7,6 @@ namespace DotNetOpenAuth.SimpleAuth { using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; /// <summary> /// Protocol constants for Simple Auth. @@ -79,5 +76,30 @@ namespace DotNetOpenAuth.SimpleAuth { /// The "expired_delegation_code" string. /// </summary> internal const string expired_delegation_code = "expired_delegation_code"; + + /// <summary> + /// The "sa_username" string. + /// </summary> + internal const string sa_username = "sa_username"; + + /// <summary> + /// The "sa_password" string. + /// </summary> + internal const string sa_password = "sa_password"; + + /// <summary> + /// The "sa_name" string. + /// </summary> + internal const string sa_name = "sa_name"; + + /// <summary> + /// The "sa_SAML" string. + /// </summary> + internal const string sa_saml = "sa_SAML"; + + /// <summary> + /// The "sa_SWT" string. + /// </summary> + internal const string sa_swt = "sa_SWT"; } } |