summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DotNetOpenAuth/OAuthWrap/Messages/ClientCredentials/ClientCredentialsRequest.cs29
-rw-r--r--src/DotNetOpenAuth/OAuthWrap/Messages/UsernameAndPassword/UserNamePasswordRequest.cs63
-rw-r--r--src/DotNetOpenAuth/OAuthWrap/Protocol.cs8
3 files changed, 83 insertions, 17 deletions
diff --git a/src/DotNetOpenAuth/OAuthWrap/Messages/ClientCredentials/ClientCredentialsRequest.cs b/src/DotNetOpenAuth/OAuthWrap/Messages/ClientCredentials/ClientCredentialsRequest.cs
index 9ebbdd1..5de3498 100644
--- a/src/DotNetOpenAuth/OAuthWrap/Messages/ClientCredentials/ClientCredentialsRequest.cs
+++ b/src/DotNetOpenAuth/OAuthWrap/Messages/ClientCredentials/ClientCredentialsRequest.cs
@@ -10,6 +10,8 @@ namespace DotNetOpenAuth.OAuthWrap.Messages {
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuthWrap.ChannelElements;
+ using DotNetOpenAuth.OAuthWrap.Messages.WebServer;
/// <summary>
/// A request for an access token for a client application that has its
@@ -18,7 +20,7 @@ namespace DotNetOpenAuth.OAuthWrap.Messages {
/// <remarks>
/// This is somewhat analogous to 2-legged OAuth.
/// </remarks>
- internal class ClientCredentialsRequest : MessageBase {
+ internal class ClientCredentialsRequest : MessageBase, IAccessTokenRequest, IOAuthDirectResponseFormat {
/// <summary>
/// Initializes a new instance of the <see cref="ClientCredentialsRequest"/> class.
/// </summary>
@@ -33,15 +35,25 @@ namespace DotNetOpenAuth.OAuthWrap.Messages {
/// Gets or sets the account name.
/// </summary>
/// <value>The name on the account.</value>
- [MessagePart(Protocol.wrap_name, IsRequired = true, AllowEmpty = false)]
- internal string Name { get; set; }
+ [MessagePart(Protocol.client_id, IsRequired = true, AllowEmpty = false)]
+ public string ClientIdentifier { get; internal set; }
/// <summary>
/// Gets or sets the user's password.
/// </summary>
/// <value>The password.</value>
- [MessagePart(Protocol.wrap_password, IsRequired = true, AllowEmpty = false)]
- internal string Password { get; set; }
+ [MessagePart(Protocol.client_secret, IsRequired = true, AllowEmpty = false)]
+ public string ClientSecret { get; internal set; }
+
+ /// <summary>
+ /// Gets or sets the type of the secret.
+ /// </summary>
+ /// <value>The type of the secret.</value>
+ /// <remarks>
+ /// OPTIONAL. The access token secret type as described by Section 5.3 (Cryptographic Tokens Requests). If omitted, the authorization server will issue a bearer token (an access token without a matching secret) as described by Section 5.2 (Bearer Token Requests).
+ /// </remarks>
+ [MessagePart(Protocol.secret_type, IsRequired = false, AllowEmpty = false)]
+ public string SecretType { get; set; }
/// <summary>
/// Gets or sets an optional authorization scope as defined by the Authorization Server.
@@ -49,6 +61,13 @@ namespace DotNetOpenAuth.OAuthWrap.Messages {
[MessagePart(Protocol.scope, IsRequired = false, AllowEmpty = true)]
internal string Scope { get; set; }
+ ResponseFormat IOAuthDirectResponseFormat.Format {
+ get { return this.Format.HasValue ? this.Format.Value : ResponseFormat.Json; }
+ }
+
+ [MessagePart(Protocol.format, Encoder = typeof(ResponseFormatEncoder))]
+ private ResponseFormat? Format { get; set; }
+
/// <summary>
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
diff --git a/src/DotNetOpenAuth/OAuthWrap/Messages/UsernameAndPassword/UserNamePasswordRequest.cs b/src/DotNetOpenAuth/OAuthWrap/Messages/UsernameAndPassword/UserNamePasswordRequest.cs
index 7ce570a..297f480 100644
--- a/src/DotNetOpenAuth/OAuthWrap/Messages/UsernameAndPassword/UserNamePasswordRequest.cs
+++ b/src/DotNetOpenAuth/OAuthWrap/Messages/UsernameAndPassword/UserNamePasswordRequest.cs
@@ -7,48 +7,78 @@
namespace DotNetOpenAuth.OAuthWrap.Messages {
using System;
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuthWrap.ChannelElements;
+ using DotNetOpenAuth.OAuthWrap.Messages.WebServer;
/// <summary>
- /// A request for a delegation code in exchnage for a user's confidential
+ /// A request for a delegation code in exchange 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 UserNamePasswordRequest : MessageBase {
+ internal class UserNamePasswordRequest : MessageBase, IAccessTokenRequest, IOAuthDirectResponseFormat {
+ [MessagePart(Protocol.type, IsRequired = true)]
+ private const string Type = "username";
+
/// <summary>
/// Initializes a new instance of the <see cref="UserNamePasswordRequest"/> class.
/// </summary>
- /// <param name="authorizationServer">The authorization server.</param>
+ /// <param name="tokenEndpoint">The authorization server.</param>
/// <param name="version">The version.</param>
- internal UserNamePasswordRequest(Uri authorizationServer, Version version)
- : base(version, MessageTransport.Direct, authorizationServer) {
+ internal UserNamePasswordRequest(Uri tokenEndpoint, Version version)
+ : base(version, MessageTransport.Direct, tokenEndpoint) {
this.HttpMethods = HttpDeliveryMethods.PostRequest;
}
/// <summary>
+ /// Initializes a new instance of the <see cref="UserNamePasswordRequest"/> class.
+ /// </summary>
+ /// <param name="authorizationServer">The authorization server.</param>
+ internal UserNamePasswordRequest(AuthorizationServerDescription authorizationServer)
+ : this(authorizationServer.TokenEndpoint, authorizationServer.Version) {
+ Contract.Requires<ArgumentNullException>(authorizationServer != null);
+ Contract.Requires<ArgumentException>(authorizationServer.Version != null);
+ Contract.Requires<ArgumentException>(authorizationServer.TokenEndpoint != null);
+
+ // We prefer URL encoding of the data.
+ this.Format = ResponseFormat.Form;
+ }
+
+ /// <summary>
/// Gets or sets the client identifier previously obtained from the Authorization Server.
/// </summary>
/// <value>The client identifier.</value>
[MessagePart(Protocol.client_id, IsRequired = true, AllowEmpty = false)]
- internal string ClientIdentifier { get; set; }
+ public string ClientIdentifier { get; internal set; }
+
+ /// <summary>
+ /// Gets or sets the client secret.
+ /// </summary>
+ /// <value>The client secret.</value>
+ /// <remarks>
+ /// REQUIRED. The client secret as described in Section 3.1 (Client Credentials). OPTIONAL if no client secret was issued.
+ /// </remarks>
+ [MessagePart(Protocol.client_secret, IsRequired = false, AllowEmpty = true)]
+ public string ClientSecret { get; internal set; }
/// <summary>
/// Gets or sets the user's account username.
/// </summary>
/// <value>The username on the user's account.</value>
- [MessagePart(Protocol.wrap_username, IsRequired = true, AllowEmpty = false)]
+ [MessagePart(Protocol.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.wrap_password, IsRequired = true, AllowEmpty = false)]
+ [MessagePart(Protocol.password, IsRequired = true, AllowEmpty = true)]
internal string Password { get; set; }
/// <summary>
@@ -73,6 +103,23 @@ namespace DotNetOpenAuth.OAuthWrap.Messages {
internal string Scope { get; set; }
/// <summary>
+ /// Gets or sets the type of the secret.
+ /// </summary>
+ /// <value>The type of the secret.</value>
+ /// <remarks>
+ /// OPTIONAL. The access token secret type as described by Section 5.3 (Cryptographic Tokens Requests). If omitted, the authorization server will issue a bearer token (an access token without a matching secret) as described by Section 5.2 (Bearer Token Requests).
+ /// </remarks>
+ [MessagePart(Protocol.secret_type, IsRequired = false, AllowEmpty = false)]
+ public string SecretType { get; set; }
+
+ ResponseFormat IOAuthDirectResponseFormat.Format {
+ get { return this.Format.HasValue ? this.Format.Value : ResponseFormat.Json; }
+ }
+
+ [MessagePart(Protocol.format, Encoder = typeof(ResponseFormatEncoder))]
+ private ResponseFormat? Format { get; set; }
+
+ /// <summary>
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
/// </summary>
diff --git a/src/DotNetOpenAuth/OAuthWrap/Protocol.cs b/src/DotNetOpenAuth/OAuthWrap/Protocol.cs
index 08329b9..5249875 100644
--- a/src/DotNetOpenAuth/OAuthWrap/Protocol.cs
+++ b/src/DotNetOpenAuth/OAuthWrap/Protocol.cs
@@ -144,14 +144,14 @@ namespace DotNetOpenAuth.OAuthWrap {
internal const string expired_delegation_code = "expired_delegation_code";
/// <summary>
- /// The "wrap_username" string.
+ /// The "username" string.
/// </summary>
- internal const string wrap_username = "wrap_username";
+ internal const string username = "username";
/// <summary>
- /// The "wrap_password" string.
+ /// The "password" string.
/// </summary>
- internal const string wrap_password = "wrap_password";
+ internal const string password = "password";
/// <summary>
/// The "wrap_name" string.