diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-03-16 23:10:44 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-03-16 23:10:44 -0700 |
commit | 719337e7465118c21aa89727c3dbba93e7a192a1 (patch) | |
tree | 669c394869e79872c5c1ffd686be28f92d80f7e0 /src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2 | |
parent | 1068d8217e19c6ac300a1077e13c2b1dae01bc4b (diff) | |
download | DotNetOpenAuth-719337e7465118c21aa89727c3dbba93e7a192a1.zip DotNetOpenAuth-719337e7465118c21aa89727c3dbba93e7a192a1.tar.gz DotNetOpenAuth-719337e7465118c21aa89727c3dbba93e7a192a1.tar.bz2 |
A bunch more moving of OAuth2 classes between assemblies.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2')
7 files changed, 244 insertions, 40 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/AccessTokenParameters.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/AccessTokenParameters.cs new file mode 100644 index 0000000..a214f20 --- /dev/null +++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/AccessTokenParameters.cs @@ -0,0 +1,80 @@ +//----------------------------------------------------------------------- +// <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); + } + + /// <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 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; } + + #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(); + } + } + } + + #endregion + } +} diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/ClientType.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/ClientType.cs new file mode 100644 index 0000000..9e8ed2a --- /dev/null +++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/ClientType.cs @@ -0,0 +1,47 @@ +//----------------------------------------------------------------------- +// <copyright file="ClientType.cs" company="Outercurve Foundation"> +// Copyright (c) Outercurve Foundation. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.OAuth2 { + /// <summary> + /// OAuth 2 Client types + /// </summary> + /// <remarks> + /// <para>Based on their ability to + /// authenticate securely with the authorization server (i.e. ability to + /// maintain the confidentiality of their client credentials).</para> + /// <para>The client type designation is based on the authorization server's + /// definition of secure authentication and its acceptable exposure + /// levels of client credentials.</para> + /// <para>The authorization server SHOULD NOT make assumptions about the client + /// type, nor accept the type information provided by the client + /// developer without first establishing trust.</para> + /// <para>A client application consisting of multiple components, each with its + /// own client type (e.g. a distributed client with both a confidential + /// server-based component and a public browser-based component), MUST + /// register each component separately as a different client to ensure + /// proper handling by the authorization server. The authorization + /// server MAY provider tools to manage such complex clients through a + /// single administration interface.</para> + /// </remarks> + public enum ClientType { + /// <summary> + /// Clients capable of maintaining the confidentiality of their + /// credentials (e.g. client implemented on a secure server with + /// restricted access to the client credentials), or capable of secure + /// client authentication using other means. + /// </summary> + Confidential, + + /// <summary> + /// Clients incapable of maintaining the confidentiality of their + /// credentials (e.g. clients executing on the device used by the + /// resource owner such as an installed native application or a web + /// browser-based application), and incapable of secure client + /// authentication via any other means. + /// </summary> + Public, + } +} diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/IClientDescription.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/IClientDescription.cs new file mode 100644 index 0000000..d30151b --- /dev/null +++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/IClientDescription.cs @@ -0,0 +1,113 @@ +//----------------------------------------------------------------------- +// <copyright file="IClientDescription.cs" company="Outercurve Foundation"> +// Copyright (c) Outercurve Foundation. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.OAuth2 { + using System; + using System.Collections.Generic; + using System.Diagnostics.Contracts; + + /// <summary> + /// A description of a client from an Authorization Server's point of view. + /// </summary> + [ContractClass(typeof(IClientDescriptionContract))] + public interface IClientDescription { + /// <summary> + /// Gets the client secret. + /// </summary> + string Secret { get; } + + /// <summary> + /// Gets the callback to use when an individual authorization request + /// does not include an explicit callback URI. + /// </summary> + /// <value>An absolute URL; or <c>null</c> if none is registered.</value> + Uri DefaultCallback { get; } + + /// <summary> + /// Gets the type of the client. + /// </summary> + ClientType ClientType { get; } + + /// <summary> + /// Determines whether a callback URI included in a client's authorization request + /// is among those allowed callbacks for the registered client. + /// </summary> + /// <param name="callback">The absolute URI the client has requested the authorization result be received at.</param> + /// <returns> + /// <c>true</c> if the callback URL is allowable for this client; otherwise, <c>false</c>. + /// </returns> + /// <remarks> + /// <para> + /// At the point this method is invoked, the identity of the client has <em>not</em> + /// been confirmed. To avoid open redirector attacks, the alleged client's identity + /// is used to lookup a list of allowable callback URLs to make sure that the callback URL + /// the actual client is requesting is one of the expected ones. + /// </para> + /// <para> + /// From OAuth 2.0 section 2.1: + /// The authorization server SHOULD require the client to pre-register + /// their redirection URI or at least certain components such as the + /// scheme, host, port and path. If a redirection URI was registered, + /// the authorization server MUST compare any redirection URI received at + /// the authorization endpoint with the registered URI. + /// </para> + /// </remarks> + bool IsCallbackAllowed(Uri callback); + } + + /// <summary> + /// Contract class for the <see cref="IClientDescription"/> interface. + /// </summary> + [ContractClassFor(typeof(IClientDescription))] + internal abstract class IClientDescriptionContract : IClientDescription { + #region IClientDescription Members + + /// <summary> + /// Gets the client secret. + /// </summary> + /// <value></value> + string IClientDescription.Secret { + get { throw new NotImplementedException(); } + } + + /// <summary> + /// Gets the type of the client. + /// </summary> + ClientType IClientDescription.ClientType { + get { throw new NotImplementedException(); } + } + + /// <summary> + /// Gets the callback to use when an individual authorization request + /// does not include an explicit callback URI. + /// </summary> + /// <value> + /// An absolute URL; or <c>null</c> if none is registered. + /// </value> + Uri IClientDescription.DefaultCallback { + get { + Contract.Ensures(Contract.Result<Uri>() == null || Contract.Result<Uri>().IsAbsoluteUri); + throw new NotImplementedException(); + } + } + + /// <summary> + /// Determines whether a callback URI included in a client's authorization request + /// is among those allowed callbacks for the registered client. + /// </summary> + /// <param name="callback">The requested callback URI.</param> + /// <returns> + /// <c>true</c> if the callback is allowed; otherwise, <c>false</c>. + /// </returns> + bool IClientDescription.IsCallbackAllowed(Uri callback) { + Requires.NotNull(callback, "callback"); + Requires.True(callback.IsAbsoluteUri, "callback"); + throw new NotImplementedException(); + } + + #endregion + } +} diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs index 6afb617..b8c9ede 100644 --- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs +++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenAuthorizationCodeRequest.cs @@ -24,20 +24,11 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// </summary> /// <param name="tokenEndpoint">The Authorization Server's access token endpoint URL.</param> /// <param name="version">The version.</param> - internal AccessTokenAuthorizationCodeRequest(Uri tokenEndpoint, Version version) + protected AccessTokenAuthorizationCodeRequest(Uri tokenEndpoint, Version version) : base(tokenEndpoint, version) { } /// <summary> - /// Initializes a new instance of the <see cref="AccessTokenAuthorizationCodeRequest"/> class. - /// </summary> - /// <param name="authorizationServer">The authorization server.</param> - internal AccessTokenAuthorizationCodeRequest(AuthorizationServerDescription authorizationServer) - : this(authorizationServer.TokenEndpoint, authorizationServer.Version) { - Requires.NotNull(authorizationServer, "authorizationServer"); - } - - /// <summary> /// Gets the type of the grant. /// </summary> /// <value>The type of the grant.</value> diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRefreshRequest.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRefreshRequest.cs index 80ebdfd..685f697 100644 --- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRefreshRequest.cs +++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/AccessTokenRefreshRequest.cs @@ -20,19 +20,11 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// </summary> /// <param name="tokenEndpoint">The token endpoint.</param> /// <param name="version">The version.</param> - internal AccessTokenRefreshRequest(Uri tokenEndpoint, Version version) + protected AccessTokenRefreshRequest(Uri tokenEndpoint, Version version) : base(tokenEndpoint, version) { } /// <summary> - /// Initializes a new instance of the <see cref="AccessTokenRefreshRequest"/> class. - /// </summary> - /// <param name="authorizationServer">The authorization server.</param> - internal AccessTokenRefreshRequest(AuthorizationServerDescription authorizationServer) - : this(authorizationServer.TokenEndpoint, authorizationServer.Version) { - } - - /// <summary> /// Gets or sets the refresh token. /// </summary> /// <value>The refresh token.</value> diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs index d97750b..661e2ae 100644 --- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs +++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationImplicitRequest.cs @@ -31,19 +31,11 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// </summary> /// <param name="authorizationEndpoint">The Authorization Server's user authorization URL to direct the user to.</param> /// <param name="version">The protocol version.</param> - internal EndUserAuthorizationImplicitRequest(Uri authorizationEndpoint, Version version) + protected EndUserAuthorizationImplicitRequest(Uri authorizationEndpoint, Version version) : base(authorizationEndpoint, version) { } /// <summary> - /// Initializes a new instance of the <see cref="EndUserAuthorizationImplicitRequest"/> class. - /// </summary> - /// <param name="authorizationServer">The authorization server.</param> - internal EndUserAuthorizationImplicitRequest(AuthorizationServerDescription authorizationServer) - : this(authorizationServer.AuthorizationEndpoint, authorizationServer.Version) { - } - - /// <summary> /// Gets the grant type that the client expects of the authorization server. /// </summary> public override EndUserAuthorizationResponseType ResponseType { diff --git a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationRequest.cs b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationRequest.cs index 45fa049..f229cf9 100644 --- a/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationRequest.cs +++ b/src/DotNetOpenAuth.OAuth2.ClientAuthorization/OAuth2/Messages/EndUserAuthorizationRequest.cs @@ -32,7 +32,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// </summary> /// <param name="authorizationEndpoint">The Authorization Server's user authorization URL to direct the user to.</param> /// <param name="version">The protocol version.</param> - internal EndUserAuthorizationRequest(Uri authorizationEndpoint, Version version) + protected EndUserAuthorizationRequest(Uri authorizationEndpoint, Version version) : base(version, MessageTransport.Indirect, authorizationEndpoint) { Requires.NotNull(authorizationEndpoint, "authorizationEndpoint"); Requires.NotNull(version, "version"); @@ -41,17 +41,6 @@ namespace DotNetOpenAuth.OAuth2.Messages { } /// <summary> - /// Initializes a new instance of the <see cref="EndUserAuthorizationRequest"/> class. - /// </summary> - /// <param name="authorizationServer">The authorization server.</param> - internal EndUserAuthorizationRequest(AuthorizationServerDescription authorizationServer) - : this(authorizationServer.AuthorizationEndpoint, authorizationServer.Version) { - Requires.NotNull(authorizationServer, "authorizationServer"); - Requires.True(authorizationServer.Version != null, "authorizationServer"); - Requires.True(authorizationServer.AuthorizationEndpoint != null, "authorizationServer"); - } - - /// <summary> /// Gets the grant type that the client expects of the authorization server. /// </summary> public virtual EndUserAuthorizationResponseType ResponseType { |