diff options
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.Client')
13 files changed, 37 insertions, 58 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.Client/Configuration/OAuth2ClientSection.cs b/src/DotNetOpenAuth.OAuth2.Client/Configuration/OAuth2ClientSection.cs index 3bb6ffc..d0c27c9 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/Configuration/OAuth2ClientSection.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/Configuration/OAuth2ClientSection.cs @@ -7,7 +7,7 @@ namespace DotNetOpenAuth.Configuration { using System; using System.Configuration; - using System.Diagnostics.Contracts; + using Validation; /// <summary> /// Represents the <oauth2/client> section in the host's .config file. @@ -34,7 +34,6 @@ namespace DotNetOpenAuth.Configuration { /// </summary> internal static OAuth2ClientSection Configuration { get { - Contract.Ensures(Contract.Result<OAuth2ClientSection>() != null); return (OAuth2ClientSection)ConfigurationManager.GetSection(SectionName) ?? new OAuth2ClientSection(); } } @@ -46,14 +45,13 @@ namespace DotNetOpenAuth.Configuration { [PositiveTimeSpanValidator] internal TimeSpan MaxAuthorizationTime { get { - Contract.Ensures(Contract.Result<TimeSpan>() > TimeSpan.Zero); TimeSpan result = (TimeSpan)this[MaxAuthorizationTimePropertyName]; - Contract.Assume(result > TimeSpan.Zero); // our PositiveTimeSpanValidator should take care of this + Assumes.True(result > TimeSpan.Zero); // our PositiveTimeSpanValidator should take care of this return result; } set { - Requires.InRange(value > TimeSpan.Zero, "value"); + Requires.Range(value > TimeSpan.Zero, "value"); this[MaxAuthorizationTimePropertyName] = value; } } diff --git a/src/DotNetOpenAuth.OAuth2.Client/DotNetOpenAuth.OAuth2.Client.csproj b/src/DotNetOpenAuth.OAuth2.Client/DotNetOpenAuth.OAuth2.Client.csproj index e595df2..475ed3f 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/DotNetOpenAuth.OAuth2.Client.csproj +++ b/src/DotNetOpenAuth.OAuth2.Client/DotNetOpenAuth.OAuth2.Client.csproj @@ -61,6 +61,15 @@ <LastGenOutput>ClientStrings.Designer.cs</LastGenOutput> </EmbeddedResource> </ItemGroup> + <ItemGroup> + <Reference Include="Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\packages\Validation.2.0.0.12319\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath> + </Reference> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.targets" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " /> diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/BearerTokenHttpMessageHandler.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/BearerTokenHttpMessageHandler.cs index 6b2e937..8c802ff 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/BearerTokenHttpMessageHandler.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/BearerTokenHttpMessageHandler.cs @@ -15,6 +15,7 @@ namespace DotNetOpenAuth.OAuth2 { using System.Threading; using System.Threading.Tasks; using DotNetOpenAuth.Messaging; + using Validation; /// <summary> /// An <see cref="HttpMessageHandler"/> that applies a bearer token to each outbound HTTP request. @@ -41,7 +42,7 @@ namespace DotNetOpenAuth.OAuth2 { : base(innerHandler) { Requires.NotNull(client, "client"); Requires.NotNull(authorization, "authorization"); - Requires.True(!string.IsNullOrEmpty(authorization.AccessToken), "authorization.AccessToken"); + Requires.That(!string.IsNullOrEmpty(authorization.AccessToken), "authorization.AccessToken", "AccessToken must be non-empty"); this.Client = client; this.Authorization = authorization; } diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ChannelElements/OAuth2ClientChannel.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ChannelElements/OAuth2ClientChannel.cs index b0cdb4b..cf57618 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ChannelElements/OAuth2ClientChannel.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ChannelElements/OAuth2ClientChannel.cs @@ -8,7 +8,6 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements { using System; using System.Collections.Generic; using System.Collections.Specialized; - using System.Diagnostics.Contracts; using System.Net; using System.Web; using System.Xml; diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientBase.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientBase.cs index e9c952d..b2178e9 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientBase.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientBase.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OAuth2 { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Net; @@ -21,6 +20,7 @@ namespace DotNetOpenAuth.OAuth2 { using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth2.ChannelElements; using DotNetOpenAuth.OAuth2.Messages; + using Validation; /// <summary> /// A base class for common OAuth Client behaviors. @@ -134,7 +134,7 @@ namespace DotNetOpenAuth.OAuth2 { public void AuthorizeRequest(WebHeaderCollection requestHeaders, IAuthorizationState authorization) { Requires.NotNull(requestHeaders, "requestHeaders"); Requires.NotNull(authorization, "authorization"); - Requires.True(!string.IsNullOrEmpty(authorization.AccessToken), "authorization"); + Requires.That(!string.IsNullOrEmpty(authorization.AccessToken), "authorization", "AccessToken required."); ErrorUtilities.VerifyProtocol(!authorization.AccessTokenExpirationUtc.HasValue || authorization.AccessTokenExpirationUtc >= DateTime.UtcNow || authorization.RefreshToken != null, ClientStrings.AuthorizationExpired); if (authorization.AccessTokenExpirationUtc.HasValue && authorization.AccessTokenExpirationUtc.Value < DateTime.UtcNow) { @@ -186,7 +186,7 @@ namespace DotNetOpenAuth.OAuth2 { /// </remarks> public bool RefreshAuthorization(IAuthorizationState authorization, TimeSpan? skipIfUsefulLifeExceeds = null) { Requires.NotNull(authorization, "authorization"); - Requires.True(!string.IsNullOrEmpty(authorization.RefreshToken), "authorization"); + Requires.That(!string.IsNullOrEmpty(authorization.RefreshToken), "authorization", "RefreshToken required."); if (skipIfUsefulLifeExceeds.HasValue && authorization.AccessTokenExpirationUtc.HasValue) { TimeSpan usefulLifeRemaining = authorization.AccessTokenExpirationUtc.Value - DateTime.UtcNow; @@ -223,7 +223,6 @@ namespace DotNetOpenAuth.OAuth2 { public IAuthorizationState GetScopedAccessToken(string refreshToken, HashSet<string> scope) { Requires.NotNullOrEmpty(refreshToken, "refreshToken"); Requires.NotNull(scope, "scope"); - Contract.Ensures(Contract.Result<IAuthorizationState>() != null); var request = new AccessTokenRefreshRequestC(this.AuthorizationServer) { ClientIdentifier = this.ClientIdentifier, @@ -377,8 +376,8 @@ namespace DotNetOpenAuth.OAuth2 { /// <returns>A fractional number no greater than 1. Could be negative if the access token has already expired.</returns> private static double ProportionalLifeRemaining(IAuthorizationState authorization) { Requires.NotNull(authorization, "authorization"); - Requires.True(authorization.AccessTokenIssueDateUtc.HasValue, "authorization"); - Requires.True(authorization.AccessTokenExpirationUtc.HasValue, "authorization"); + Requires.That(authorization.AccessTokenIssueDateUtc.HasValue, "authorization", "AccessTokenIssueDateUtc required"); + Requires.That(authorization.AccessTokenExpirationUtc.HasValue, "authorization", "AccessTokenExpirationUtc required"); // Calculate what % of the total life this access token has left. TimeSpan totalLifetime = authorization.AccessTokenExpirationUtc.Value - authorization.AccessTokenIssueDateUtc.Value; diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientCredentialApplicator.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientCredentialApplicator.cs index 0677f5a..39ba1cb 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientCredentialApplicator.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientCredentialApplicator.cs @@ -12,6 +12,7 @@ namespace DotNetOpenAuth.OAuth2 { using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth2.Messages; + using Validation; /// <summary> /// A base class for extensions that apply client authentication to messages for the authorization server in specific ways. diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/IClientAuthorizationTracker.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/IClientAuthorizationTracker.cs index 73b7a44..d42248a 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/IClientAuthorizationTracker.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/IClientAuthorizationTracker.cs @@ -6,12 +6,11 @@ namespace DotNetOpenAuth.OAuth2 { using System; - using System.Diagnostics.Contracts; + using Validation; /// <summary> /// A token manager implemented by some clients to assist in tracking authorization state. /// </summary> - [ContractClass(typeof(IClientAuthorizationTrackerContract))] public interface IClientAuthorizationTracker { /// <summary> /// Gets the state of the authorization for a given callback URL and client state. @@ -21,33 +20,4 @@ namespace DotNetOpenAuth.OAuth2 { /// <returns>The authorization state; may be <c>null</c> if no authorization state matches.</returns> IAuthorizationState GetAuthorizationState(Uri callbackUrl, string clientState); } - - /// <summary> - /// Contract class for the <see cref="IClientAuthorizationTracker"/> interface. - /// </summary> - [ContractClassFor(typeof(IClientAuthorizationTracker))] - internal abstract class IClientAuthorizationTrackerContract : IClientAuthorizationTracker { - /// <summary> - /// Prevents a default instance of the <see cref="IClientAuthorizationTrackerContract"/> class from being created. - /// </summary> - private IClientAuthorizationTrackerContract() { - } - - #region IClientTokenManager Members - - /// <summary> - /// Gets the state of the authorization for a given callback URL and client state. - /// </summary> - /// <param name="callbackUrl">The callback URL.</param> - /// <param name="clientState">State of the client stored at the beginning of an authorization request.</param> - /// <returns> - /// The authorization state; may be <c>null</c> if no authorization state matches. - /// </returns> - IAuthorizationState IClientAuthorizationTracker.GetAuthorizationState(Uri callbackUrl, string clientState) { - Requires.NotNull(callbackUrl, "callbackUrl"); - throw new NotImplementedException(); - } - - #endregion - } } diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/AccessTokenAuthorizationCodeRequestC.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/AccessTokenAuthorizationCodeRequestC.cs index ebfb2e8..861c8cd 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/AccessTokenAuthorizationCodeRequestC.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/AccessTokenAuthorizationCodeRequestC.cs @@ -9,6 +9,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { using System.Collections.Generic; using System.Linq; using System.Text; + using Validation; /// <summary> /// A request from a Client to an Authorization Server to exchange an authorization code for an access token, diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/EndUserAuthorizationRequestC.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/EndUserAuthorizationRequestC.cs index 7c06897..b388f0c 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/EndUserAuthorizationRequestC.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/Messages/EndUserAuthorizationRequestC.cs @@ -9,6 +9,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { using System.Collections.Generic; using System.Linq; using System.Text; + using Validation; /// <summary> /// A message sent by a web application Client to the AuthorizationServer @@ -24,8 +25,8 @@ namespace DotNetOpenAuth.OAuth2.Messages { internal EndUserAuthorizationRequestC(AuthorizationServerDescription authorizationServer) : base(authorizationServer.AuthorizationEndpoint, authorizationServer.Version) { Requires.NotNull(authorizationServer, "authorizationServer"); - Requires.True(authorizationServer.Version != null, "authorizationServer"); - Requires.True(authorizationServer.AuthorizationEndpoint != null, "authorizationServer"); + Requires.That(authorizationServer.Version != null, "authorizationServer", "requires Version"); + Requires.That(authorizationServer.AuthorizationEndpoint != null, "authorizationServer", "requires AuthorizationEndpoint"); } } } diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs index edde2a9..dcb3826 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs @@ -7,13 +7,13 @@ namespace DotNetOpenAuth.OAuth2 { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Linq; using System.Text; using System.Web; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth2.Messages; + using Validation; /// <summary> /// The OAuth client for the user-agent flow, providing services for installed apps @@ -103,7 +103,7 @@ namespace DotNetOpenAuth.OAuth2 { /// </returns> public Uri RequestUserAuthorization(IAuthorizationState authorization, bool implicitResponseType = false, string state = null) { Requires.NotNull(authorization, "authorization"); - Requires.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier)); + RequiresEx.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier)); var request = this.PrepareRequestUserAuthorization(authorization, implicitResponseType, state); return this.Channel.PrepareResponse(request).GetDirectUriRequest(this.Channel); @@ -172,7 +172,7 @@ namespace DotNetOpenAuth.OAuth2 { /// </returns> internal EndUserAuthorizationRequest PrepareRequestUserAuthorization(IAuthorizationState authorization, bool implicitResponseType = false, string state = null) { Requires.NotNull(authorization, "authorization"); - Requires.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier)); + RequiresEx.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier)); if (authorization.Callback == null) { authorization.Callback = new Uri("http://localhost/"); diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs index 879e4e3..63d96e1 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs @@ -7,7 +7,6 @@ namespace DotNetOpenAuth.OAuth2 { using System; using System.Collections.Generic; - using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Net; @@ -18,6 +17,7 @@ namespace DotNetOpenAuth.OAuth2 { using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth2.Messages; + using Validation; /// <summary> /// An OAuth 2.0 consumer designed for web applications. @@ -89,9 +89,8 @@ namespace DotNetOpenAuth.OAuth2 { /// <returns>The authorization request.</returns> public OutgoingWebResponse PrepareRequestUserAuthorization(IAuthorizationState authorization) { Requires.NotNull(authorization, "authorization"); - Requires.ValidState(authorization.Callback != null || (HttpContext.Current != null && HttpContext.Current.Request != null), MessagingStrings.HttpContextRequired); - Requires.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier), Strings.RequiredPropertyNotYetPreset, "ClientIdentifier"); - Contract.Ensures(Contract.Result<OutgoingWebResponse>() != null); + RequiresEx.ValidState(authorization.Callback != null || (HttpContext.Current != null && HttpContext.Current.Request != null), MessagingStrings.HttpContextRequired); + RequiresEx.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier), Strings.RequiredPropertyNotYetPreset, "ClientIdentifier"); if (authorization.Callback == null) { authorization.Callback = this.Channel.GetRequestFromContext().GetPublicFacingUrl() @@ -136,8 +135,8 @@ namespace DotNetOpenAuth.OAuth2 { /// <param name="request">The incoming HTTP request that may carry an authorization response.</param> /// <returns>The authorization state that contains the details of the authorization.</returns> public IAuthorizationState ProcessUserAuthorization(HttpRequestBase request = null) { - Requires.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier), Strings.RequiredPropertyNotYetPreset, "ClientIdentifier"); - Requires.ValidState(this.ClientCredentialApplicator != null, Strings.RequiredPropertyNotYetPreset, "ClientCredentialApplicator"); + RequiresEx.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier), Strings.RequiredPropertyNotYetPreset, "ClientIdentifier"); + RequiresEx.ValidState(this.ClientCredentialApplicator != null, Strings.RequiredPropertyNotYetPreset, "ClientCredentialApplicator"); if (request == null) { request = this.Channel.GetRequestFromContext(); diff --git a/src/DotNetOpenAuth.OAuth2.Client/Properties/AssemblyInfo.cs b/src/DotNetOpenAuth.OAuth2.Client/Properties/AssemblyInfo.cs index 397b35d..29900ab 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/Properties/AssemblyInfo.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/Properties/AssemblyInfo.cs @@ -7,7 +7,6 @@ // We DON'T put an AssemblyVersionAttribute in here because it is generated in the build. using System; -using System.Diagnostics.Contracts; using System.Net; using System.Reflection; using System.Resources; @@ -31,8 +30,6 @@ using System.Web.UI; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("7d73990c-47c0-4256-9f20-a893add9e289")] -[assembly: ContractVerification(true)] - #if StrongNameSigned // See comment at top of this file. We need this so that strong-naming doesn't // keep this assembly from being useful to shared host (medium trust) web sites. diff --git a/src/DotNetOpenAuth.OAuth2.Client/packages.config b/src/DotNetOpenAuth.OAuth2.Client/packages.config new file mode 100644 index 0000000..10eec89 --- /dev/null +++ b/src/DotNetOpenAuth.OAuth2.Client/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Validation" version="2.0.0.12319" targetFramework="net40" /> +</packages>
\ No newline at end of file |