diff options
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.Client/OAuth2')
8 files changed, 21 insertions, 13 deletions
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/ClientBase.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientBase.cs index e9c952d..a21c597 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientBase.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/ClientBase.cs @@ -21,6 +21,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 +135,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 +187,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; @@ -377,8 +378,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..bf16aff 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/IClientAuthorizationTracker.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/IClientAuthorizationTracker.cs @@ -7,6 +7,7 @@ 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. 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..3a9529c 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs @@ -14,6 +14,7 @@ namespace DotNetOpenAuth.OAuth2 { 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 +104,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 +173,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..491048a 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs @@ -18,6 +18,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,8 +90,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"); + RequiresEx.ValidState(authorization.Callback != null || (HttpContext.Current != null && HttpContext.Current.Request != null), MessagingStrings.HttpContextRequired); + RequiresEx.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier), Strings.RequiredPropertyNotYetPreset, "ClientIdentifier"); Contract.Ensures(Contract.Result<OutgoingWebResponse>() != null); if (authorization.Callback == null) { @@ -136,8 +137,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(); |