summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2.ClientAuthorization
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-04-25 06:21:30 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2012-04-25 06:21:30 -0700
commitd10db64d32f10c9514918541542af3bbf5889fca (patch)
tree34a338c26072e142c50e59e119a8b10551ed1524 /src/DotNetOpenAuth.OAuth2.ClientAuthorization
parentbf30c08cce5b18f6dc1679be8e4e610819efa9a7 (diff)
downloadDotNetOpenAuth-d10db64d32f10c9514918541542af3bbf5889fca.zip
DotNetOpenAuth-d10db64d32f10c9514918541542af3bbf5889fca.tar.gz
DotNetOpenAuth-d10db64d32f10c9514918541542af3bbf5889fca.tar.bz2
Authorization Server hosts now instantiate their own AccessTokens rather than just parameters.
AccessTokens are now serialized via a virtual method on that instance. Fixes #38, I think.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.ClientAuthorization')
-rw-r--r--src/DotNetOpenAuth.OAuth2.ClientAuthorization/DotNetOpenAuth.OAuth2.ClientAuthorization.csproj2
-rw-r--r--src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/AccessTokenParameters.cs102
-rw-r--r--src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRequestBase.cs28
-rw-r--r--src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenResult.cs43
-rw-r--r--src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs7
-rw-r--r--src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/IAccessTokenRequestInternal.cs7
6 files changed, 51 insertions, 138 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/DotNetOpenAuth.OAuth2.ClientAuthorization.csproj b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/DotNetOpenAuth.OAuth2.ClientAuthorization.csproj
index 3fe6e27..4a0e344 100644
--- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/DotNetOpenAuth.OAuth2.ClientAuthorization.csproj
+++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/DotNetOpenAuth.OAuth2.ClientAuthorization.csproj
@@ -18,7 +18,6 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
- <Compile Include="OAuth2\AccessTokenParameters.cs" />
<Compile Include="OAuth2\ChannelElements\EndUserAuthorizationResponseTypeEncoder.cs" />
<Compile Include="OAuth2\ChannelElements\GrantTypeEncoder.cs" />
<Compile Include="OAuth2\ChannelElements\OAuth2ChannelBase.cs" />
@@ -35,6 +34,7 @@
<Compile Include="OAuth2\Messages\AccessTokenRefreshRequest.cs" />
<Compile Include="OAuth2\Messages\AccessTokenRequestBase.cs" />
<Compile Include="OAuth2\Messages\AccessTokenResourceOwnerPasswordCredentialsRequest.cs" />
+ <Compile Include="OAuth2\Messages\AccessTokenResult.cs" />
<Compile Include="OAuth2\Messages\AccessTokenSuccessResponse.cs" />
<Compile Include="OAuth2\Messages\AuthenticatedClientRequestBase.cs" />
<Compile Include="OAuth2\Messages\EndUserAuthorizationFailedResponse.cs" />
diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/AccessTokenParameters.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/AccessTokenParameters.cs
deleted file mode 100644
index 8f383cd..0000000
--- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/AccessTokenParameters.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="AccessTokenParameters.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2 {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
-
- /// <summary>
- /// Describes the parameters to be fed into creating a response to an access token request.
- /// </summary>
- public class AccessTokenParameters : IDisposable {
- /// <summary>
- /// Initializes a new instance of the <see cref="AccessTokenParameters"/> class.
- /// </summary>
- public AccessTokenParameters() {
- this.IncludeRefreshToken = true;
- this.AccessTokenLifetime = TimeSpan.FromHours(1);
- this.ExtraClaims = new Dictionary<string, string>();
- }
-
- /// <summary>
- /// Gets or sets the access token lifetime.
- /// </summary>
- /// <value>
- /// A positive timespan.
- /// </value>
- /// <remarks>
- /// Note that within this lifetime, authorization <i>may</i> not be revokable.
- /// Short lifetimes are recommended (e.g. one hour), particularly when the client is not authenticated or
- /// the resources to which access is being granted are sensitive.
- /// </remarks>
- public TimeSpan AccessTokenLifetime { get; set; }
-
- /// <summary>
- /// Gets or sets the crypto service provider with the asymmetric private key to use for signing access tokens.
- /// </summary>
- /// <returns>A crypto service provider instance that contains the private key.</returns>
- /// <value>Must not be null, and must contain the private key.</value>
- /// <remarks>
- /// The public key in the private/public key pair will be used by the resource
- /// servers to validate that the access token is minted by a trusted authorization server.
- /// </remarks>
- public RSACryptoServiceProvider AccessTokenSigningKey { get; set; }
-
- /// <summary>
- /// Gets or sets the key to encrypt the access token.
- /// </summary>
- public RSACryptoServiceProvider ResourceServerEncryptionKey { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether to provide the client with a refresh token, when applicable.
- /// </summary>
- /// <value>The default value is <c>true</c>.</value>
- /// <remarks>>
- /// The refresh token will never be provided when this value is false.
- /// The refresh token <em>may</em> be provided when this value is true.
- /// </remarks>
- public bool IncludeRefreshToken { get; set; }
-
- /// <summary>
- /// Gets or sets a dictionary of additional claims to include in the <see cref="AccessToken"/>.
- /// </summary>
- public IDictionary<string, string> ExtraClaims { get; set; }
-
- #region Implementation of IDisposable
-
- /// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- /// </summary>
- /// <filterpriority>2</filterpriority>
- public void Dispose() {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected virtual void Dispose(bool disposing) {
- if (disposing) {
- if (this.ResourceServerEncryptionKey != null) {
- IDisposable value = this.ResourceServerEncryptionKey;
- value.Dispose();
- }
-
- if (this.AccessTokenSigningKey != null) {
- IDisposable value = this.AccessTokenSigningKey;
- value.Dispose();
- }
- }
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRequestBase.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRequestBase.cs
index c2ab347..e6bbc34 100644
--- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRequestBase.cs
+++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRequestBase.cs
@@ -16,7 +16,7 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// <summary>
/// A message sent from the client to the authorization server to exchange a previously obtained grant for an access token.
/// </summary>
- public abstract class AccessTokenRequestBase : AuthenticatedClientRequestBase, IAccessTokenRequestInternal, IDisposable {
+ public abstract class AccessTokenRequestBase : AuthenticatedClientRequestBase, IAccessTokenRequestInternal {
/// <summary>
/// Initializes a new instance of the <see cref="AccessTokenRequestBase"/> class.
/// </summary>
@@ -43,12 +43,9 @@ namespace DotNetOpenAuth.OAuth2.Messages {
public bool ClientAuthenticated { get; internal set; }
/// <summary>
- /// Gets or sets the access token creation parameters.
+ /// Gets or sets the result of calling the authorization server host's access token creation method.
/// </summary>
- /// <remarks>
- /// This property's value is set by a binding element in the OAuth 2 channel.
- /// </remarks>
- AccessTokenParameters IAccessTokenRequestInternal.AccessTokenCreationParameters { get; set; }
+ AccessTokenResult IAccessTokenRequestInternal.AccessTokenResult { get; set; }
/// <summary>
/// Gets the type of the grant.
@@ -63,25 +60,6 @@ namespace DotNetOpenAuth.OAuth2.Messages {
protected abstract HashSet<string> RequestedScope { get; }
/// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- /// </summary>
- public void Dispose() {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected virtual void Dispose(bool disposing) {
- IAccessTokenRequestInternal self = this;
- if (self.AccessTokenCreationParameters != null) {
- self.AccessTokenCreationParameters.Dispose();
- }
- }
-
- /// <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.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenResult.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenResult.cs
new file mode 100644
index 0000000..11e486b
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenResult.cs
@@ -0,0 +1,43 @@
+//-----------------------------------------------------------------------
+// <copyright file="AccessTokenResult.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth2 {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Security.Cryptography;
+ using System.Text;
+
+ /// <summary>
+ /// Describes the parameters to be fed into creating a response to an access token request.
+ /// </summary>
+ public class AccessTokenResult {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="AccessTokenResult"/> class.
+ /// </summary>
+ /// <param name="accessToken">The access token to include in this result.</param>
+ public AccessTokenResult(AccessToken accessToken) {
+ Requires.NotNull(accessToken, "accessToken");
+ this.AllowRefreshToken = true;
+ this.AccessToken = accessToken;
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether to provide the client with a refresh token, when applicable.
+ /// </summary>
+ /// <value>The default value is <c>true</c>.</value>
+ /// <remarks>>
+ /// The refresh token will never be provided when this value is false.
+ /// The refresh token <em>may</em> be provided when this value is true.
+ /// </remarks>
+ public bool AllowRefreshToken { get; set; }
+
+ /// <summary>
+ /// Gets the access token.
+ /// </summary>
+ public AccessToken AccessToken { get; private set; }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs
index 661e2ae..4b662cd 100644
--- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs
+++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs
@@ -43,12 +43,9 @@ namespace DotNetOpenAuth.OAuth2.Messages {
}
/// <summary>
- /// Gets or sets the access token creation parameters.
+ /// Gets or sets the result of calling the authorization server host's access token creation method.
/// </summary>
- /// <remarks>
- /// This property's value is set by a binding element in the OAuth 2 channel.
- /// </remarks>
- AccessTokenParameters IAccessTokenRequestInternal.AccessTokenCreationParameters { get; set; }
+ AccessTokenResult IAccessTokenRequestInternal.AccessTokenResult { get; set; }
/// <summary>
/// Gets a value indicating whether the client requesting the access token has authenticated itself.
diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/IAccessTokenRequestInternal.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/IAccessTokenRequestInternal.cs
index e218462..44af074 100644
--- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/IAccessTokenRequestInternal.cs
+++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/IAccessTokenRequestInternal.cs
@@ -15,11 +15,8 @@ namespace DotNetOpenAuth.OAuth2.Messages {
/// </summary>
public interface IAccessTokenRequestInternal : IAccessTokenRequest {
/// <summary>
- /// Gets or sets the access token creation parameters.
+ /// Gets or sets the result of calling the authorization server host's access token creation method.
/// </summary>
- /// <remarks>
- /// This property's value is set by a binding element in the OAuth 2 channel.
- /// </remarks>
- AccessTokenParameters AccessTokenCreationParameters { get; set; }
+ AccessTokenResult AccessTokenResult { get; set; }
}
}