diff options
39 files changed, 451 insertions, 30 deletions
diff --git a/src/DotNetOpenAuth/DotNetOpenAuthSL.csproj b/src/DotNetOpenAuth/DotNetOpenAuthSL.csproj index d7a5b43..dd27bff 100644 --- a/src/DotNetOpenAuth/DotNetOpenAuthSL.csproj +++ b/src/DotNetOpenAuth/DotNetOpenAuthSL.csproj @@ -55,7 +55,119 @@ <Reference Include="System.Windows.Browser" /> </ItemGroup> <ItemGroup> + <Compile Include="Logger.cs" /> + <Compile Include="Loggers\ILog.cs" /> + <Compile Include="Loggers\NoOpLogger.cs" /> + <Compile Include="Messaging\Bindings\ExpiredMessageException.cs" /> + <Compile Include="Messaging\Bindings\IExpiringProtocolMessage.cs" /> + <Compile Include="Messaging\Bindings\INonceStore.cs" /> + <Compile Include="Messaging\Bindings\InvalidSignatureException.cs" /> + <Compile Include="Messaging\Bindings\IReplayProtectedProtocolMessage.cs" /> + <Compile Include="Messaging\Bindings\ReplayedMessageException.cs" /> + <Compile Include="Messaging\Bindings\StandardExpirationBindingElement.cs" /> + <Compile Include="Messaging\Bindings\StandardReplayProtectionBindingElement.cs" /> + <Compile Include="Messaging\CachedDirectWebResponse.cs" /> + <Compile Include="Messaging\Channel.cs" /> + <Compile Include="Messaging\ChannelContract.cs" /> + <Compile Include="Messaging\ChannelEventArgs.cs" /> + <Compile Include="Messaging\DirectWebRequestOptions.cs" /> + <Compile Include="Messaging\EmptyDictionary.cs" /> + <Compile Include="Messaging\EmptyEnumerator.cs" /> + <Compile Include="Messaging\EmptyList.cs" /> + <Compile Include="Messaging\EnumerableCache.cs" /> + <Compile Include="Messaging\ErrorUtilities.cs" /> + <Compile Include="Messaging\HostErrorException.cs" /> + <Compile Include="Messaging\HttpDeliveryMethods.cs" /> + <Compile Include="Messaging\IChannelBindingElement.cs" /> + <Compile Include="Messaging\IDirectedProtocolMessage.cs" /> + <Compile Include="Messaging\IDirectResponseProtocolMessage.cs" /> + <Compile Include="Messaging\IDirectWebRequestHandler.cs" /> + <Compile Include="Messaging\IMessage.cs" /> + <Compile Include="Messaging\IMessageFactory.cs" /> + <Compile Include="Messaging\IMessageWithBinaryData.cs" /> + <Compile Include="Messaging\IMessageWithEvents.cs" /> + <Compile Include="Messaging\IncomingWebResponse.cs" /> + <Compile Include="Messaging\IncomingWebResponseContract.cs" /> + <Compile Include="Messaging\InternalErrorException.cs" /> + <Compile Include="Messaging\IProtocolMessage.cs" /> + <Compile Include="Messaging\ITamperProtectionChannelBindingElement.cs" /> + <Compile Include="Messaging\ITamperResistantProtocolMessage.cs" /> + <Compile Include="Messaging\MessagePartAttribute.cs" /> + <Compile Include="Messaging\MessageProtections.cs" /> + <Compile Include="Messaging\MessageReceivingEndpoint.cs" /> + <Compile Include="Messaging\MessageSerializer.cs" /> + <Compile Include="Messaging\MessageTransport.cs" /> + <Compile Include="Messaging\MessagingStrings.Designer.cs" /> + <Compile Include="Messaging\MessagingUtilities.cs" /> + <Compile Include="Messaging\MultipartPostPart.cs" /> + <Compile Include="Messaging\NetworkDirectWebResponse.cs" /> + <Compile Include="Messaging\ProtocolException.cs" /> + <Compile Include="Messaging\Reflection\IMessagePartEncoder.cs" /> + <Compile Include="Messaging\Reflection\IMessagePartNullEncoder.cs" /> + <Compile Include="Messaging\Reflection\IMessagePartOriginalEncoder.cs" /> + <Compile Include="Messaging\Reflection\MessageDescription.cs" /> + <Compile Include="Messaging\Reflection\MessageDescriptionCollection.cs" /> + <Compile Include="Messaging\Reflection\MessageDictionary.cs" /> + <Compile Include="Messaging\Reflection\MessagePart.cs" /> + <Compile Include="Messaging\Reflection\ValueMapping.cs" /> + <Compile Include="Messaging\StandardWebRequestHandler.cs" /> + <Compile Include="Messaging\UnprotectedMessageException.cs" /> + <Compile Include="Messaging\UntrustedWebRequestHandler.cs" /> + <Compile Include="OAuth\ChannelElements\HmacSha1SigningBindingElement.cs" /> + <Compile Include="OAuth\ChannelElements\IConsumerTokenManager.cs" /> + <Compile Include="OAuth\ChannelElements\IServiceProviderAccessToken.cs" /> + <Compile Include="OAuth\ChannelElements\IServiceProviderRequestToken.cs" /> + <Compile Include="OAuth\ChannelElements\ITamperResistantOAuthMessage.cs" /> + <Compile Include="OAuth\ChannelElements\ITokenGenerator.cs" /> + <Compile Include="OAuth\ChannelElements\ITokenManager.cs" /> + <Compile Include="OAuth\ChannelElements\OAuthChannel.cs" /> + <Compile Include="OAuth\ChannelElements\OAuthConsumerMessageFactory.cs" /> + <Compile Include="OAuth\ChannelElements\OAuthHttpMethodBindingElement.cs" /> + <Compile Include="OAuth\ChannelElements\OAuthIdentity.cs" /> + <Compile Include="OAuth\ChannelElements\OAuthPrincipal.cs" /> + <Compile Include="OAuth\ChannelElements\PlaintextSigningBindingElement.cs" /> + <Compile Include="OAuth\ChannelElements\SigningBindingElementBase.cs" /> + <Compile Include="OAuth\ChannelElements\SigningBindingElementBaseContract.cs" /> + <Compile Include="OAuth\ChannelElements\SigningBindingElementChain.cs" /> + <Compile Include="OAuth\ChannelElements\StandardTokenGenerator.cs" /> + <Compile Include="OAuth\ChannelElements\TokenType.cs" /> + <Compile Include="OAuth\ChannelElements\UriOrOobEncoding.cs" /> + <Compile Include="OAuth\ConsumerBase.cs" /> + <Compile Include="OAuth\ConsumerSecuritySettings.cs" /> + <Compile Include="OAuth\DesktopConsumer.cs" /> + <Compile Include="OAuth\Messages\AccessProtectedResourceRequest.cs" /> + <Compile Include="OAuth\Messages\AuthorizedTokenRequest.cs" /> + <Compile Include="OAuth\Messages\AuthorizedTokenResponse.cs" /> + <Compile Include="OAuth\Messages\ITokenContainingMessage.cs" /> + <Compile Include="OAuth\Messages\ITokenSecretContainingMessage.cs" /> + <Compile Include="OAuth\Messages\MessageBase.cs" /> + <Compile Include="OAuth\Messages\SignedMessageBase.cs" /> + <Compile Include="OAuth\Messages\UnauthorizedTokenRequest.cs" /> + <Compile Include="OAuth\Messages\UnauthorizedTokenResponse.cs" /> + <Compile Include="OAuth\Messages\UserAuthorizationRequest.cs" /> + <Compile Include="OAuth\Messages\UserAuthorizationResponse.cs" /> + <Compile Include="OAuth\OAuthStrings.Designer.cs" /> + <Compile Include="OAuth\Protocol.cs" /> + <Compile Include="OAuth\SecuritySettings.cs" /> + <Compile Include="OAuth\ServiceProviderDescription.cs" /> + <Compile Include="OAuth\WebConsumer.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="UriUtil.cs" /> + <Compile Include="Util.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="Messaging\Bindings\Bindings.cd" /> + <None Include="OAuth\ClassDiagram.cd" /> + <None Include="OAuth\Messages\OAuth Messages.cd" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Messaging\MessagingStrings.resx" /> + <EmbeddedResource Include="Messaging\MessagingStrings.sr.resx" /> + <EmbeddedResource Include="OAuth\OAuthStrings.resx" /> + <EmbeddedResource Include="OAuth\OAuthStrings.sr.resx" /> + </ItemGroup> + <ItemGroup> + <Folder Include="Configuration\" /> </ItemGroup> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" /> <ProjectExtensions> diff --git a/src/DotNetOpenAuth/Logger.cs b/src/DotNetOpenAuth/Logger.cs index 48007ed..12b6d0a 100644 --- a/src/DotNetOpenAuth/Logger.cs +++ b/src/DotNetOpenAuth/Logger.cs @@ -10,7 +10,9 @@ namespace DotNetOpenAuth { using System.Globalization; using DotNetOpenAuth.Loggers; using DotNetOpenAuth.Messaging; +#if !SILVERLIGHT using log4net.Core; +#endif /// <summary> /// A general logger for the entire DotNetOpenAuth library. @@ -177,7 +179,11 @@ namespace DotNetOpenAuth { /// <param name="name">The name of the log to initialize.</param> /// <returns>The <see cref="ILog"/> instance of the logger to use.</returns> private static ILog InitializeFacade(string name) { +#if !SILVERLIGHT ILog result = Log4NetLogger.Initialize(name) ?? TraceLogger.Initialize(name) ?? NoOpLogger.Initialize(); +#else + ILog result = NoOpLogger.Initialize(); +#endif return result; } } diff --git a/src/DotNetOpenAuth/Loggers/ILog.cs b/src/DotNetOpenAuth/Loggers/ILog.cs index 8094296..4445b79 100644 --- a/src/DotNetOpenAuth/Loggers/ILog.cs +++ b/src/DotNetOpenAuth/Loggers/ILog.cs @@ -27,8 +27,10 @@ namespace DotNetOpenAuth.Loggers { using System; using System.Reflection; +#if !SILVERLIGHT using log4net; using log4net.Core; +#endif /// <summary> /// The ILog interface is use by application to log messages into diff --git a/src/DotNetOpenAuth/Messaging/Bindings/ExpiredMessageException.cs b/src/DotNetOpenAuth/Messaging/Bindings/ExpiredMessageException.cs index 73ce289..7ba940d 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/ExpiredMessageException.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/ExpiredMessageException.cs @@ -12,7 +12,9 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// <summary> /// An exception thrown when a message is received that exceeds the maximum message age limit. /// </summary> +#if !SILVERLIGHT [Serializable] +#endif internal class ExpiredMessageException : ProtocolException { /// <summary> /// Initializes a new instance of the <see cref="ExpiredMessageException"/> class. @@ -24,6 +26,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { Contract.Requires<ArgumentException>(utcExpirationDate.Kind == DateTimeKind.Utc); } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="ExpiredMessageException"/> class. /// </summary> @@ -35,5 +38,6 @@ namespace DotNetOpenAuth.Messaging.Bindings { System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/Bindings/InvalidSignatureException.cs b/src/DotNetOpenAuth/Messaging/Bindings/InvalidSignatureException.cs index 28b7e96..d2e0584 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/InvalidSignatureException.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/InvalidSignatureException.cs @@ -10,7 +10,9 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// <summary> /// An exception thrown when a signed message does not pass signature validation. /// </summary> +#if !SILVERLIGHT [Serializable] +#endif internal class InvalidSignatureException : ProtocolException { /// <summary> /// Initializes a new instance of the <see cref="InvalidSignatureException"/> class. @@ -19,6 +21,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { public InvalidSignatureException(IProtocolMessage faultedMessage) : base(MessagingStrings.SignatureInvalid, faultedMessage) { } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="InvalidSignatureException"/> class. /// </summary> @@ -30,5 +33,6 @@ namespace DotNetOpenAuth.Messaging.Bindings { System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs b/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs index 6e64acc..e90a497 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/NonceMemoryStore.cs @@ -32,7 +32,11 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// <summary> /// A list of the consumed nonces. /// </summary> - private readonly SortedDictionary<DateTime, List<string>> usedNonces = new SortedDictionary<DateTime, List<string>>(); +#if !SILVERLIGHT + private readonly IDictionary<DateTime, List<string>> usedNonces = new SortedDictionary<DateTime, List<string>>(); +#else + private readonly IDictionary<DateTime, List<string>> usedNonces = new Dictionary<DateTime, List<string>>(); +#endif /// <summary> /// A lock object used around accesses to the <see cref="usedNonces"/> field. diff --git a/src/DotNetOpenAuth/Messaging/Bindings/ReplayedMessageException.cs b/src/DotNetOpenAuth/Messaging/Bindings/ReplayedMessageException.cs index 2b8df9d..dd81486 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/ReplayedMessageException.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/ReplayedMessageException.cs @@ -11,7 +11,9 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// An exception thrown when a message is received for the second time, signalling a possible /// replay attack. /// </summary> +#if !SILVERLIGHT [Serializable] +#endif internal class ReplayedMessageException : ProtocolException { /// <summary> /// Initializes a new instance of the <see cref="ReplayedMessageException"/> class. @@ -19,6 +21,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// <param name="faultedMessage">The replayed message.</param> public ReplayedMessageException(IProtocolMessage faultedMessage) : base(MessagingStrings.ReplayAttackDetected, faultedMessage) { } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="ReplayedMessageException"/> class. /// </summary> @@ -30,5 +33,6 @@ namespace DotNetOpenAuth.Messaging.Bindings { System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } +#endif + } } diff --git a/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs b/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs index 4396c16..407f18f 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/StandardExpirationBindingElement.cs @@ -6,7 +6,9 @@ namespace DotNetOpenAuth.Messaging.Bindings { using System; +#if !SILVERLIGHT using DotNetOpenAuth.Configuration; +#endif /// <summary> /// A message expiration enforcing binding element that supports messages @@ -42,7 +44,13 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// being discarded as too old. /// </summary> protected internal static TimeSpan MaximumMessageAge { - get { return Configuration.DotNetOpenAuthSection.Configuration.Messaging.MaximumMessageLifetime; } + get { +#if !SILVERLIGHT + return Configuration.DotNetOpenAuthSection.Configuration.Messaging.MaximumMessageLifetime; +#else + return TimeSpan.FromMinutes(13); +#endif + } } #region IChannelBindingElement Methods @@ -91,8 +99,13 @@ namespace DotNetOpenAuth.Messaging.Bindings { // Mitigate HMAC attacks (just guessing the signature until they get it) by // disallowing post-dated messages. +#if !SILVERLIGHT + TimeSpan maxClockSkew = DotNetOpenAuthSection.Configuration.Messaging.MaximumClockSkew; +#else + TimeSpan maxClockSkew = TimeSpan.FromMinutes(5); +#endif ErrorUtilities.VerifyProtocol( - creationDate <= DateTime.UtcNow + DotNetOpenAuthSection.Configuration.Messaging.MaximumClockSkew, + creationDate <= DateTime.UtcNow + maxClockSkew, MessagingStrings.MessageTimestampInFuture, creationDate); diff --git a/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs b/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs index bb56cfd..c9221ab 100644 --- a/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs +++ b/src/DotNetOpenAuth/Messaging/Bindings/StandardReplayProtectionBindingElement.cs @@ -31,19 +31,9 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// <summary> /// Initializes a new instance of the <see cref="StandardReplayProtectionBindingElement"/> class. /// </summary> - /// <param name="nonceStore">The store where nonces will be persisted and checked.</param> - internal StandardReplayProtectionBindingElement(INonceStore nonceStore) - : this(nonceStore, false) { - } - - /// <summary> - /// Initializes a new instance of the <see cref="StandardReplayProtectionBindingElement"/> class. - /// </summary> - /// <param name="nonceStore">The store where nonces will be persisted and checked.</param> + /// <param name="nonceStore">The store where nonces will be persisted and checked. Not required when only outgoing messages contain nonces.</param> /// <param name="allowEmptyNonces">A value indicating whether zero-length nonces will be allowed.</param> - internal StandardReplayProtectionBindingElement(INonceStore nonceStore, bool allowEmptyNonces) { - Contract.Requires<ArgumentNullException>(nonceStore != null); - + internal StandardReplayProtectionBindingElement(INonceStore nonceStore = null, bool allowEmptyNonces = false) { this.nonceStore = nonceStore; this.AllowZeroLengthNonce = allowEmptyNonces; } @@ -123,6 +113,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { IReplayProtectedProtocolMessage nonceMessage = message as IReplayProtectedProtocolMessage; if (nonceMessage != null && nonceMessage.Nonce != null) { ErrorUtilities.VerifyProtocol(nonceMessage.Nonce.Length > 0 || this.AllowZeroLengthNonce, MessagingStrings.InvalidNonceReceived); + ErrorUtilities.VerifyInternal(this.nonceStore != null, "Nonce store not set."); if (!this.nonceStore.StoreNonce(nonceMessage.NonceContext, nonceMessage.Nonce, nonceMessage.UtcCreationDate)) { Logger.OpenId.ErrorFormat("Replayed nonce detected ({0} {1}). Rejecting message.", nonceMessage.Nonce, nonceMessage.UtcCreationDate); diff --git a/src/DotNetOpenAuth/Messaging/CachedDirectWebResponse.cs b/src/DotNetOpenAuth/Messaging/CachedDirectWebResponse.cs index c9bc1d3..488de42 100644 --- a/src/DotNetOpenAuth/Messaging/CachedDirectWebResponse.cs +++ b/src/DotNetOpenAuth/Messaging/CachedDirectWebResponse.cs @@ -142,7 +142,11 @@ namespace DotNetOpenAuth.Messaging { } Encoding encoding = Encoding.UTF8; +#if !SILVERLIGHT this.Headers[HttpResponseHeader.ContentEncoding] = encoding.HeaderName; +#else + this.Headers["Content-Encoding"] = "UTF-8"; // encoding.HeaderName; // Silverlight lacks HttpResponseHeader.ContentEncoding +#endif this.responseStream = new MemoryStream(); StreamWriter writer = new StreamWriter(this.ResponseStream, encoding); writer.Write(body); diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs index 84dbe3c..a2d5047 100644 --- a/src/DotNetOpenAuth/Messaging/Channel.cs +++ b/src/DotNetOpenAuth/Messaging/Channel.cs @@ -15,11 +15,15 @@ namespace DotNetOpenAuth.Messaging { using System.IO; using System.Linq; using System.Net; +#if !SILVERLIGHT using System.Net.Cache; using System.Net.Mime; +#endif using System.Text; using System.Threading; +#if !SILVERLIGHT using System.Web; +#endif using DotNetOpenAuth.Messaging.Reflection; /// <summary> @@ -44,7 +48,11 @@ namespace DotNetOpenAuth.Messaging { /// URL-encoded series of key=value pairs. /// This includes the <see cref="PostEntityEncoding"/> character encoding. /// </summary> +#if !SILVERLIGHT protected internal static readonly ContentType HttpFormUrlEncodedContentType = new ContentType(HttpFormUrlEncoded) { CharSet = PostEntityEncoding.WebName }; +#else + protected internal static readonly string HttpFormUrlEncodedContentType = HttpFormUrlEncoded + "; charset=" + PostEntityEncoding.WebName; +#endif /// <summary> /// The maximum allowable size for a 301 Redirect response before we send @@ -114,10 +122,12 @@ namespace DotNetOpenAuth.Messaging { /// </summary> private IMessageFactory messageTypeProvider; +#if !SILVERLIGHT /// <summary> /// Backing store for the <see cref="CachePolicy"/> property. /// </summary> private RequestCachePolicy cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); +#endif /// <summary> /// Initializes a new instance of the <see cref="Channel"/> class. @@ -224,6 +234,7 @@ namespace DotNetOpenAuth.Messaging { get { return this.messageTypeProvider; } } +#if !SILVERLIGHT /// <summary> /// Gets or sets the cache policy to use for direct message requests. /// </summary> @@ -411,6 +422,7 @@ namespace DotNetOpenAuth.Messaging { return requestMessage; } +#endif /// <summary> /// Sends a direct message to a remote party and waits for the response. @@ -494,6 +506,7 @@ namespace DotNetOpenAuth.Messaging { return this.CreateHttpRequest(request); } +#if !SILVERLIGHT /// <summary> /// Queues a message for sending in the response stream where the fields /// are sent in the response stream in querystring style. @@ -506,6 +519,7 @@ namespace DotNetOpenAuth.Messaging { internal OutgoingWebResponse PrepareDirectResponseTestHook(IProtocolMessage response) { return this.PrepareDirectResponse(response); } +#endif /// <summary> /// Gets the protocol message that may be in the given HTTP response. @@ -529,6 +543,7 @@ namespace DotNetOpenAuth.Messaging { this.ProcessOutgoingMessage(message); } +#if !SILVERLIGHT /// <summary> /// Gets the current HTTP request being processed. /// </summary> @@ -549,6 +564,7 @@ namespace DotNetOpenAuth.Messaging { Contract.Assume(HttpContext.Current.Request.RawUrl != null); return new HttpRequestInfo(HttpContext.Current.Request); } +#endif /// <summary> /// Checks whether a given HTTP method is expected to include an entity body in its request. @@ -657,6 +673,7 @@ namespace DotNetOpenAuth.Messaging { protected virtual void OnReceivingDirectResponse(IncomingWebResponse response, IDirectResponseProtocolMessage message) { } +#if !SILVERLIGHT /// <summary> /// Gets the protocol message that may be embedded in the given HTTP request. /// </summary> @@ -684,6 +701,7 @@ namespace DotNetOpenAuth.Messaging { return (IDirectedProtocolMessage)this.Receive(fields, recipient); } +#endif /// <summary> /// Deserializes a dictionary of values into a message. @@ -712,6 +730,7 @@ namespace DotNetOpenAuth.Messaging { return message; } +#if !SILVERLIGHT /// <summary> /// Queues an indirect message for transmittal via the user agent. /// </summary> @@ -807,6 +826,7 @@ namespace DotNetOpenAuth.Messaging { return response; } } +#endif /// <summary> /// Gets the protocol message that may be in the given HTTP response. @@ -832,6 +852,7 @@ namespace DotNetOpenAuth.Messaging { throw new NotImplementedException(); } +#if !SILVERLIGHT /// <summary> /// Queues a message for sending in the response stream where the fields /// are sent in the response stream in querystring style. @@ -842,6 +863,7 @@ namespace DotNetOpenAuth.Messaging { /// This method implements spec OAuth V1.0 section 5.3. /// </remarks> protected abstract OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response); +#endif /// <summary> /// Prepares a message for transmit by applying signatures, nonces, etc. @@ -960,7 +982,9 @@ namespace DotNetOpenAuth.Messaging { var fields = messageAccessor.Serialize(); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(requestMessage.Recipient); +#if !SILVERLIGHT httpRequest.CachePolicy = this.CachePolicy; +#endif httpRequest.Method = "POST"; var requestMessageWithBinaryData = requestMessage as IMessageWithBinaryData; @@ -1171,7 +1195,8 @@ namespace DotNetOpenAuth.Messaging { elements.Where(element => element.Protection != MessageProtections.None)); bool wasLastProtectionPresent = true; - foreach (MessageProtections protectionKind in Enum.GetValues(typeof(MessageProtections))) { + var protections = new MessageProtections[] { MessageProtections.TamperProtection, MessageProtections.Expiration, MessageProtections.ReplayProtection }; + foreach (MessageProtections protectionKind in protections) { if (protectionKind == MessageProtections.None) { continue; } diff --git a/src/DotNetOpenAuth/Messaging/ChannelContract.cs b/src/DotNetOpenAuth/Messaging/ChannelContract.cs index 9b85d28..02dec1e 100644 --- a/src/DotNetOpenAuth/Messaging/ChannelContract.cs +++ b/src/DotNetOpenAuth/Messaging/ChannelContract.cs @@ -34,6 +34,7 @@ namespace DotNetOpenAuth.Messaging { throw new NotImplementedException(); } +#if !SILVERLIGHT /// <summary> /// Queues a message for sending in the response stream where the fields /// are sent in the response stream in querystring style. @@ -50,5 +51,6 @@ namespace DotNetOpenAuth.Messaging { Contract.Ensures(Contract.Result<OutgoingWebResponse>() != null); throw new NotImplementedException(); } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/EmptyDictionary.cs b/src/DotNetOpenAuth/Messaging/EmptyDictionary.cs index 9db5169..c4a9a42 100644 --- a/src/DotNetOpenAuth/Messaging/EmptyDictionary.cs +++ b/src/DotNetOpenAuth/Messaging/EmptyDictionary.cs @@ -15,7 +15,9 @@ namespace DotNetOpenAuth.Messaging { /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> +#if !SILVERLIGHT [Serializable] +#endif internal class EmptyDictionary<TKey, TValue> : IDictionary<TKey, TValue> { /// <summary> /// The singleton instance of the empty dictionary. diff --git a/src/DotNetOpenAuth/Messaging/EmptyList.cs b/src/DotNetOpenAuth/Messaging/EmptyList.cs index 68cdabd..b3c1ff4 100644 --- a/src/DotNetOpenAuth/Messaging/EmptyList.cs +++ b/src/DotNetOpenAuth/Messaging/EmptyList.cs @@ -13,7 +13,9 @@ namespace DotNetOpenAuth.Messaging { /// An empty, read-only list. /// </summary> /// <typeparam name="T">The type the list claims to include.</typeparam> +#if !SILVERLIGHT [Serializable] +#endif internal class EmptyList<T> : IList<T> { /// <summary> /// The singleton instance of the empty list. diff --git a/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs b/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs index 1807f54..a169c7d 100644 --- a/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs +++ b/src/DotNetOpenAuth/Messaging/ErrorUtilities.cs @@ -9,7 +9,9 @@ namespace DotNetOpenAuth.Messaging { using System.Diagnostics; using System.Diagnostics.Contracts; using System.Globalization; +#if !SILVERLIGHT using System.Web; +#endif /// <summary> /// A collection of error checking and reporting methods. @@ -150,6 +152,7 @@ namespace DotNetOpenAuth.Messaging { } } +#if !SILVERLIGHT /// <summary> /// Checks a condition and throws an <see cref="InfoCard.InformationCardException"/> /// if it evaluates to false. @@ -169,6 +172,7 @@ namespace DotNetOpenAuth.Messaging { throw new InfoCard.InformationCardException(errorMessage); } } +#endif /// <summary> /// Throws a <see cref="HostErrorException"/> if some <paramref name="condition"/> evaluates to false. @@ -371,6 +375,7 @@ namespace DotNetOpenAuth.Messaging { } } +#if !SILVERLIGHT /// <summary> /// Verifies that <see cref="HttpContext.Current"/> != <c>null</c>. /// </summary> @@ -381,5 +386,6 @@ namespace DotNetOpenAuth.Messaging { Contract.Ensures(HttpContext.Current.Request != null); ErrorUtilities.VerifyOperation(HttpContext.Current != null && HttpContext.Current.Request != null, MessagingStrings.HttpContextRequired); } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/HostErrorException.cs b/src/DotNetOpenAuth/Messaging/HostErrorException.cs index 81691b0..4cabd6c 100644 --- a/src/DotNetOpenAuth/Messaging/HostErrorException.cs +++ b/src/DotNetOpenAuth/Messaging/HostErrorException.cs @@ -22,7 +22,9 @@ namespace DotNetOpenAuth.Messaging { /// <para>It is an internal exception to assist in making it uncatchable.</para> /// </remarks> [SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "We don't want this exception to be catchable.")] +#if !SILVERLIGHT [Serializable] +#endif internal class HostErrorException : Exception { /// <summary> /// Initializes a new instance of the <see cref="HostErrorException"/> class. @@ -47,6 +49,7 @@ namespace DotNetOpenAuth.Messaging { : base(message, inner) { } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="HostErrorException"/> class. /// </summary> @@ -62,5 +65,6 @@ namespace DotNetOpenAuth.Messaging { System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/IncomingWebResponse.cs b/src/DotNetOpenAuth/Messaging/IncomingWebResponse.cs index 70b1032..81fb3f7 100644 --- a/src/DotNetOpenAuth/Messaging/IncomingWebResponse.cs +++ b/src/DotNetOpenAuth/Messaging/IncomingWebResponse.cs @@ -11,7 +11,9 @@ namespace DotNetOpenAuth.Messaging { using System.Globalization; using System.IO; using System.Net; +#if !SILVERLIGHT using System.Net.Mime; +#endif using System.Text; /// <summary> @@ -43,6 +45,7 @@ namespace DotNetOpenAuth.Messaging { Contract.Requires<ArgumentNullException>(response != null); this.RequestUri = requestUri; +#if !SILVERLIGHT if (!string.IsNullOrEmpty(response.ContentType)) { try { this.ContentType = new ContentType(response.ContentType); @@ -50,7 +53,12 @@ namespace DotNetOpenAuth.Messaging { Logger.Messaging.ErrorFormat("HTTP response to {0} included an invalid Content-Type header value: {1}", response.ResponseUri.AbsoluteUri, response.ContentType); } } +#else + this.ContentType = response.ContentType; +#endif +#if !SILVERLIGHT this.ContentEncoding = string.IsNullOrEmpty(response.ContentEncoding) ? DefaultContentEncoding : response.ContentEncoding; +#endif this.FinalUri = response.ResponseUri; this.Status = response.StatusCode; this.Headers = response.Headers; @@ -70,6 +78,7 @@ namespace DotNetOpenAuth.Messaging { this.RequestUri = requestUri; this.Status = statusCode; +#if !SILVERLIGHT if (!string.IsNullOrEmpty(contentType)) { try { this.ContentType = new ContentType(contentType); @@ -77,7 +86,12 @@ namespace DotNetOpenAuth.Messaging { Logger.Messaging.ErrorFormat("HTTP response to {0} included an invalid Content-Type header value: {1}", responseUri.AbsoluteUri, contentType); } } +#else + this.ContentType = contentType; +#endif +#if !SILVERLIGHT this.ContentEncoding = string.IsNullOrEmpty(contentEncoding) ? DefaultContentEncoding : contentEncoding; +#endif this.Headers = headers; this.FinalUri = responseUri; } @@ -85,12 +99,18 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// Gets the type of the content. /// </summary> +#if !SILVERLIGHT public ContentType ContentType { get; private set; } +#else + public string ContentType { get; private set; } +#endif +#if !SILVERLIGHT /// <summary> /// Gets the content encoding. /// </summary> public string ContentEncoding { get; private set; } +#endif /// <summary> /// Gets the URI of the initial request. @@ -138,7 +158,9 @@ namespace DotNetOpenAuth.Messaging { sb.AppendLine(string.Format(CultureInfo.CurrentCulture, "ResponseUri = {0}", this.FinalUri)); sb.AppendLine(string.Format(CultureInfo.CurrentCulture, "StatusCode = {0}", this.Status)); sb.AppendLine(string.Format(CultureInfo.CurrentCulture, "ContentType = {0}", this.ContentType)); +#if !SILVERLIGHT sb.AppendLine(string.Format(CultureInfo.CurrentCulture, "ContentEncoding = {0}", this.ContentEncoding)); +#endif sb.AppendLine("Headers:"); foreach (string header in this.Headers) { sb.AppendLine(string.Format(CultureInfo.CurrentCulture, "\t{0}: {1}", header, this.Headers[header])); diff --git a/src/DotNetOpenAuth/Messaging/InternalErrorException.cs b/src/DotNetOpenAuth/Messaging/InternalErrorException.cs index 32b44f2..f016822 100644 --- a/src/DotNetOpenAuth/Messaging/InternalErrorException.cs +++ b/src/DotNetOpenAuth/Messaging/InternalErrorException.cs @@ -17,7 +17,9 @@ namespace DotNetOpenAuth.Messaging { /// really an unexpected, potentially unrecoverable exception. /// </remarks> [SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "We want this to be internal so clients cannot catch it.")] +#if !SILVERLIGHT [Serializable] +#endif internal class InternalErrorException : Exception { /// <summary> /// Initializes a new instance of the <see cref="InternalErrorException"/> class. @@ -37,6 +39,7 @@ namespace DotNetOpenAuth.Messaging { /// <param name="inner">The inner exception.</param> public InternalErrorException(string message, Exception inner) : base(message, inner) { } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="InternalErrorException"/> class. /// </summary> @@ -52,5 +55,6 @@ namespace DotNetOpenAuth.Messaging { System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/MessagePartAttribute.cs b/src/DotNetOpenAuth/Messaging/MessagePartAttribute.cs index 22c660c..914a912 100644 --- a/src/DotNetOpenAuth/Messaging/MessagePartAttribute.cs +++ b/src/DotNetOpenAuth/Messaging/MessagePartAttribute.cs @@ -7,7 +7,9 @@ namespace DotNetOpenAuth.Messaging { using System; using System.Diagnostics; +#if !SILVERLIGHT using System.Net.Security; +#endif using System.Reflection; /// <summary> diff --git a/src/DotNetOpenAuth/Messaging/MessageProtections.cs b/src/DotNetOpenAuth/Messaging/MessageProtections.cs index c78c92f..e3633f0 100644 --- a/src/DotNetOpenAuth/Messaging/MessageProtections.cs +++ b/src/DotNetOpenAuth/Messaging/MessageProtections.cs @@ -43,4 +43,26 @@ namespace DotNetOpenAuth.Messaging { /// </summary> All = TamperProtection | Expiration | ReplayProtection, } + +#if SILVERLIGHT + /// <summary> + /// Indicates the security services requested for an authenticated stream. + /// </summary> + public enum ProtectionLevel { + /// <summary> + /// No protection required. + /// </summary> + None, + + /// <summary> + /// Message (part) should be signed. + /// </summary> + Sign, + + /// <summary> + /// Message (part) should be encrypted and signed. + /// </summary> + EncryptAndSign, + } +#endif }
\ No newline at end of file diff --git a/src/DotNetOpenAuth/Messaging/MessageReceivingEndpoint.cs b/src/DotNetOpenAuth/Messaging/MessageReceivingEndpoint.cs index e39a047..6244280 100644 --- a/src/DotNetOpenAuth/Messaging/MessageReceivingEndpoint.cs +++ b/src/DotNetOpenAuth/Messaging/MessageReceivingEndpoint.cs @@ -13,7 +13,9 @@ namespace DotNetOpenAuth.Messaging { /// An immutable description of a URL that receives messages. /// </summary> [DebuggerDisplay("{AllowedMethods} {Location}")] +#if !SILVERLIGHT [Serializable] +#endif public class MessageReceivingEndpoint { /// <summary> /// Initializes a new instance of the <see cref="MessageReceivingEndpoint"/> class. diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs index 7c25f73..bb6c931 100644 --- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs @@ -14,12 +14,16 @@ namespace DotNetOpenAuth.Messaging { using System.IO; using System.Linq; using System.Net; +#if !SILVERLIGHT using System.Net.Mime; +#endif using System.Security; using System.Security.Cryptography; using System.Text; +#if !SILVERLIGHT using System.Web; using System.Web.Mvc; +#endif using DotNetOpenAuth.Messaging.Reflection; /// <summary> @@ -63,6 +67,13 @@ namespace DotNetOpenAuth.Messaging { /// </summary> private static readonly string[] UriRfc3986CharsToEscape = new[] { "!", "*", "'", "(", ")" }; +#if SILVERLIGHT + /// <summary> + /// Characters used for hex escaping. + /// </summary> + private static char[] HexUpperChars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; +#endif + /// <summary> /// A set of escaping mappings that help secure a string from javscript execution. /// </summary> @@ -86,6 +97,7 @@ namespace DotNetOpenAuth.Messaging { { "=", @"\x3d" }, }; +#if !SILVERLIGHT /// <summary> /// Transforms an OutgoingWebResponse to an MVC-friendly ActionResult. /// </summary> @@ -133,6 +145,7 @@ namespace DotNetOpenAuth.Messaging { return uri; } } +#endif /// <summary> /// Sends a multipart HTTP POST request (useful for posting files). @@ -203,16 +216,22 @@ namespace DotNetOpenAuth.Messaging { Contract.Requires<ArgumentNullException>(requestHandler != null); Contract.Requires<ArgumentNullException>(parts != null); +#if !SILVERLIGHT Reporting.RecordFeatureUse("MessagingUtilities.PostMultipart"); +#endif parts = parts.CacheGeneratedResults(); string boundary = Guid.NewGuid().ToString(); string initialPartLeadingBoundary = string.Format(CultureInfo.InvariantCulture, "--{0}\r\n", boundary); string partLeadingBoundary = string.Format(CultureInfo.InvariantCulture, "\r\n--{0}\r\n", boundary); string finalTrailingBoundary = string.Format(CultureInfo.InvariantCulture, "\r\n--{0}--\r\n", boundary); +#if !SILVERLIGHT var contentType = new ContentType("multipart/form-data") { Boundary = boundary, CharSet = Channel.PostEntityEncoding.WebName, }; +#else + var contentType = "multipart/form-data; boundary=" + boundary + "; charset=" + Channel.PostEntityEncoding.WebName; +#endif request.Method = "POST"; request.ContentType = contentType.ToString(); @@ -334,6 +353,7 @@ namespace DotNetOpenAuth.Messaging { return result == 0; } +#if !SILVERLIGHT /// <summary> /// Adds a set of HTTP headers to an <see cref="HttpResponse"/> instance, /// taking care to set some headers to the appropriate properties of @@ -383,6 +403,7 @@ namespace DotNetOpenAuth.Messaging { } } } +#endif #if !CLR4 /// <summary> @@ -481,47 +502,57 @@ namespace DotNetOpenAuth.Messaging { case "Connection": break; // Keep-Alive controls this case "Content-Length": newRequest.ContentLength = request.ContentLength; break; case "Content-Type": newRequest.ContentType = request.ContentType; break; - case "Expect": newRequest.Expect = request.Expect; break; case "Host": break; // implicitly copied as part of the RequestUri + case "Proxy-Connection": break; // no property equivalent? + case "User-Agent": newRequest.UserAgent = request.UserAgent; break; +#if !SILVERLIGHT + case "Expect": newRequest.Expect = request.Expect; break; case "If-Modified-Since": newRequest.IfModifiedSince = request.IfModifiedSince; break; case "Keep-Alive": newRequest.KeepAlive = request.KeepAlive; break; - case "Proxy-Connection": break; // no property equivalent? case "Referer": newRequest.Referer = request.Referer; break; case "Transfer-Encoding": newRequest.TransferEncoding = request.TransferEncoding; break; - case "User-Agent": newRequest.UserAgent = request.UserAgent; break; +#endif default: newRequest.Headers[headerName] = request.Headers[headerName]; break; } } newRequest.AllowAutoRedirect = request.AllowAutoRedirect; newRequest.AllowWriteStreamBuffering = request.AllowWriteStreamBuffering; +#if !SILVERLIGHT newRequest.AuthenticationLevel = request.AuthenticationLevel; newRequest.AutomaticDecompression = request.AutomaticDecompression; newRequest.CachePolicy = request.CachePolicy; newRequest.ClientCertificates = request.ClientCertificates; newRequest.ConnectionGroupName = request.ConnectionGroupName; newRequest.ContinueDelegate = request.ContinueDelegate; +#endif newRequest.CookieContainer = request.CookieContainer; newRequest.Credentials = request.Credentials; +#if !SILVERLIGHT newRequest.ImpersonationLevel = request.ImpersonationLevel; newRequest.MaximumAutomaticRedirections = request.MaximumAutomaticRedirections; newRequest.MaximumResponseHeadersLength = request.MaximumResponseHeadersLength; newRequest.MediaType = request.MediaType; +#endif newRequest.Method = request.Method; +#if !SILVERLIGHT newRequest.Pipelined = request.Pipelined; newRequest.PreAuthenticate = request.PreAuthenticate; newRequest.ProtocolVersion = request.ProtocolVersion; newRequest.ReadWriteTimeout = request.ReadWriteTimeout; newRequest.SendChunked = request.SendChunked; newRequest.Timeout = request.Timeout; +#endif newRequest.UseDefaultCredentials = request.UseDefaultCredentials; +#if !SILVERLIGHT try { newRequest.Proxy = request.Proxy; newRequest.UnsafeAuthenticatedConnectionSharing = request.UnsafeAuthenticatedConnectionSharing; } catch (SecurityException) { Logger.Messaging.Warn("Unable to clone some HttpWebRequest properties due to partial trust."); } +#endif return newRequest; } @@ -687,6 +718,7 @@ namespace DotNetOpenAuth.Messaging { } } +#if !SILVERLIGHT /// <summary> /// Adds parameters to a query string, replacing parameters that /// match ones that already exist in the query string. @@ -718,6 +750,7 @@ namespace DotNetOpenAuth.Messaging { internal static MessageReceivingEndpoint GetRecipient(this HttpRequestInfo request) { return new MessageReceivingEndpoint(request.UrlBeforeRewriting, GetHttpDeliveryMethod(request.HttpMethod)); } +#endif /// <summary> /// Gets the <see cref="HttpDeliveryMethods"/> enum value for a given HTTP verb. @@ -779,6 +812,7 @@ namespace DotNetOpenAuth.Messaging { } } +#if !SILVERLIGHT /// <summary> /// Converts a <see cref="NameValueCollection"/> to an IDictionary<string, string>. /// </summary> @@ -829,6 +863,7 @@ namespace DotNetOpenAuth.Messaging { return dictionary; } +#endif /// <summary> /// Sorts the elements of a sequence in ascending order by using a specified comparer. @@ -924,7 +959,7 @@ namespace DotNetOpenAuth.Messaging { foreach (var pair in javascriptStaticStringEscaping) { builder.Replace(pair.Key, pair.Value); } - builder.Insert(0, '\''); + builder.Insert(0, "\'"); builder.Append('\''); return builder.ToString(); } @@ -951,13 +986,58 @@ namespace DotNetOpenAuth.Messaging { // Upgrade the escaping to RFC 3986, if necessary. for (int i = 0; i < UriRfc3986CharsToEscape.Length; i++) { +#if !SILVERLIGHT escaped.Replace(UriRfc3986CharsToEscape[i], Uri.HexEscape(UriRfc3986CharsToEscape[i][0])); +#else + escaped.Replace(UriRfc3986CharsToEscape[i], HexEscape(UriRfc3986CharsToEscape[i][0])); +#endif } // Return the fully-RFC3986-escaped string. return escaped.ToString(); } +#if SILVERLIGHT + /// <summary> + /// Parses a query string, similar to <see cref="HttpUtility.ParseQueryString"/>, which is missing from Silverlight. + /// </summary> + /// <param name="value">The query string to parse.</param> + /// <returns>A dictionary of the unescaped elements from the query string.</returns> + internal static IDictionary<string, string> ParseQueryString(string value) { + ErrorUtilities.VerifyArgumentNotNull(value, "value"); + var result = new Dictionary<string, string>(); + var pairs = from pair in value.TrimStart('?').Split('&') + let halves = pair.Split('=') + where halves.Length == 2 + let k = Uri.UnescapeDataString(halves[0]) + let v = Uri.UnescapeDataString(halves[1]) + select new KeyValuePair<string, string>(k, v); + foreach (var pair in pairs) { + string existingValue; + if (result.TryGetValue(pair.Key, out existingValue)) { + result[pair.Key] = existingValue + "," + pair.Value; + } else { + result.Add(pair.Key, pair.Value); + } + } + + return result; + } + + /// <summary> + /// Equivalent to <see cref="Uri.HexEscape"/>, which isn't available on Silverlight. + /// </summary> + /// <param name="ch">The character to escape.</param> + /// <returns>A 3-character string, beginning with "%".</returns> + private static string HexEscape(char ch) { + if (ch > '\x00ff') { + throw new ArgumentOutOfRangeException("ch"); + } + + return "%" + HexUpperChars[(ch & 240) >> 4] + HexUpperChars[ch & '\x000f']; + } +#endif + /// <summary> /// Ensures that UTC times are converted to local times. Unspecified kinds are unchanged. /// </summary> diff --git a/src/DotNetOpenAuth/Messaging/ProtocolException.cs b/src/DotNetOpenAuth/Messaging/ProtocolException.cs index fb9ec6d..7e15c90 100644 --- a/src/DotNetOpenAuth/Messaging/ProtocolException.cs +++ b/src/DotNetOpenAuth/Messaging/ProtocolException.cs @@ -14,7 +14,9 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// An exception to represent errors in the local or remote implementation of the protocol. /// </summary> +#if !SILVERLIGHT [Serializable] +#endif public class ProtocolException : Exception { /// <summary> /// Initializes a new instance of the <see cref="ProtocolException"/> class. @@ -49,6 +51,7 @@ namespace DotNetOpenAuth.Messaging { this.FaultedMessage = faultedMessage; } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="ProtocolException"/> class. /// </summary> @@ -62,12 +65,14 @@ namespace DotNetOpenAuth.Messaging { : base(info, context) { throw new NotImplementedException(); } +#endif /// <summary> /// Gets the message that caused the exception. /// </summary> internal IProtocolMessage FaultedMessage { get; private set; } +#if !SILVERLIGHT /// <summary> /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception. /// </summary> @@ -89,5 +94,6 @@ namespace DotNetOpenAuth.Messaging { base.GetObjectData(info, context); throw new NotImplementedException(); } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs b/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs index b876ec4..b8c5a3e 100644 --- a/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs +++ b/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs @@ -12,11 +12,15 @@ namespace DotNetOpenAuth.Messaging.Reflection { using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; +#if !SILVERLIGHT using System.Net.Security; +#endif using System.Reflection; using System.Xml; +#if !SILVERLIGHT using DotNetOpenAuth.Configuration; using DotNetOpenAuth.OpenId; +#endif /// <summary> /// Describes an individual member of a message and assists in its serialization. @@ -74,11 +78,13 @@ namespace DotNetOpenAuth.Messaging.Reflection { Contract.Assume(str != null); return bool.Parse(str); }; +#if !SILVERLIGHT Func<string, Identifier> safeIdentifier = str => { Contract.Assume(str != null); ErrorUtilities.VerifyFormat(str.Length > 0, MessagingStrings.NonEmptyStringExpected); return Identifier.Parse(str, true); }; +#endif Func<byte[], string> safeFromByteArray = bytes => { Contract.Assume(bytes != null); return Convert.ToBase64String(bytes); @@ -87,15 +93,19 @@ namespace DotNetOpenAuth.Messaging.Reflection { Contract.Assume(str != null); return Convert.FromBase64String(str); }; +#if !SILVERLIGHT Func<string, Realm> safeRealm = str => { Contract.Assume(str != null); return new Realm(str); }; +#endif Map<Uri>(uri => uri.AbsoluteUri, uri => uri.OriginalString, safeUri); Map<DateTime>(dt => XmlConvert.ToString(dt, XmlDateTimeSerializationMode.Utc), null, str => XmlConvert.ToDateTime(str, XmlDateTimeSerializationMode.Utc)); Map<byte[]>(safeFromByteArray, null, safeToByteArray); +#if !SILVERLIGHT Map<Realm>(realm => realm.ToString(), realm => realm.OriginalString, safeRealm); Map<Identifier>(id => id.SerializedString, id => id.OriginalString, safeIdentifier); +#endif Map<bool>(value => value.ToString().ToLowerInvariant(), null, safeBool); Map<CultureInfo>(c => c.Name, null, str => new CultureInfo(str)); Map<CultureInfo[]>(cs => string.Join(",", cs.Select(c => c.Name).ToArray()), null, str => str.Split(',').Select(s => new CultureInfo(s)).ToArray()); @@ -209,8 +219,12 @@ namespace DotNetOpenAuth.Messaging.Reflection { try { if (this.IsConstantValue) { string constantValue = this.GetValue(message); - var caseSensitivity = DotNetOpenAuthSection.Configuration.Messaging.Strict ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; - if (!string.Equals(constantValue, value, caseSensitivity)) { +#if !SILVERLIGHT + bool strict = DotNetOpenAuthSection.Configuration.Messaging.Strict; +#else + bool strict = true; +#endif + if (!string.Equals(constantValue, value, strict ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(string.Format( CultureInfo.CurrentCulture, MessagingStrings.UnexpectedMessagePartValueForConstant, diff --git a/src/DotNetOpenAuth/Messaging/UnprotectedMessageException.cs b/src/DotNetOpenAuth/Messaging/UnprotectedMessageException.cs index 2f21184..6c85711 100644 --- a/src/DotNetOpenAuth/Messaging/UnprotectedMessageException.cs +++ b/src/DotNetOpenAuth/Messaging/UnprotectedMessageException.cs @@ -11,7 +11,9 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// An exception thrown when messages cannot receive all the protections they require. /// </summary> +#if !SILVERLIGHT [Serializable] +#endif internal class UnprotectedMessageException : ProtocolException { /// <summary> /// Initializes a new instance of the <see cref="UnprotectedMessageException"/> class. @@ -22,6 +24,7 @@ namespace DotNetOpenAuth.Messaging { : base(string.Format(CultureInfo.CurrentCulture, MessagingStrings.InsufficientMessageProtection, faultedMessage.GetType().Name, faultedMessage.RequiredProtection, appliedProtection), faultedMessage) { } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="UnprotectedMessageException"/> class. /// </summary> @@ -33,5 +36,6 @@ namespace DotNetOpenAuth.Messaging { System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif } } diff --git a/src/DotNetOpenAuth/Messaging/UntrustedWebRequestHandler.cs b/src/DotNetOpenAuth/Messaging/UntrustedWebRequestHandler.cs index 838b7e8..4a0dbc5 100644 --- a/src/DotNetOpenAuth/Messaging/UntrustedWebRequestHandler.cs +++ b/src/DotNetOpenAuth/Messaging/UntrustedWebRequestHandler.cs @@ -13,9 +13,13 @@ namespace DotNetOpenAuth.Messaging { using System.Globalization; using System.IO; using System.Net; +#if !SILVERLIGHT using System.Net.Cache; +#endif using System.Text.RegularExpressions; +#if !SILVERLIGHT using DotNetOpenAuth.Configuration; +#endif using DotNetOpenAuth.Messaging; /// <summary> @@ -170,12 +174,14 @@ namespace DotNetOpenAuth.Messaging { /// </summary> public ICollection<Regex> BlacklistHostsRegex { get { return this.blacklistHostsRegex; } } +#if !SILVERLIGHT /// <summary> /// Gets the configuration for this class that is specified in the host's .config file. /// </summary> private static UntrustedWebRequestElement Configuration { get { return DotNetOpenAuthSection.Configuration.Messaging.UntrustedWebRequest; } } +#endif #region IDirectWebRequestHandler Members @@ -255,7 +261,7 @@ namespace DotNetOpenAuth.Messaging { // We have no copy of the post entity stream to repeat on our manually // cloned HttpWebRequest, so we have to bail. ErrorUtilities.VerifyProtocol(request.Method != "POST", MessagingStrings.UntrustedRedirectsOnPOSTNotSupported); - Uri redirectUri = new Uri(response.FinalUri, response.Headers[HttpResponseHeader.Location]); + Uri redirectUri = new Uri(response.FinalUri, response.Headers["Location"]); // HttpResponseHeader.Location isn't available in Silverlight request = request.Clone(redirectUri); } else { if (response.FinalUri != request.RequestUri) { @@ -460,9 +466,11 @@ namespace DotNetOpenAuth.Messaging { // Be careful to not try to change the HTTP headers that have already gone out. if (preparingPost || request.Method == "GET") { // Set/override a few properties of the request to apply our policies for untrusted requests. +#if !SILVERLIGHT request.ReadWriteTimeout = (int)this.ReadWriteTimeout.TotalMilliseconds; request.Timeout = (int)this.Timeout.TotalMilliseconds; request.KeepAlive = false; +#endif } // If SSL is required throughout, we cannot allow auto redirects because diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/HmacSha1SigningBindingElement.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/HmacSha1SigningBindingElement.cs index 53930bc..b067999 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/HmacSha1SigningBindingElement.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/HmacSha1SigningBindingElement.cs @@ -31,10 +31,15 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// This method signs the message per OAuth 1.0 section 9.2. /// </remarks> protected override string GetSignature(ITamperResistantOAuthMessage message) { +#if !SILVERLIGHT + Encoding encoding = Encoding.ASCII; +#else + Encoding encoding = Encoding.UTF8; +#endif string key = GetConsumerAndTokenSecretString(message); - HashAlgorithm hasher = new HMACSHA1(Encoding.ASCII.GetBytes(key)); + HashAlgorithm hasher = new HMACSHA1(encoding.GetBytes(key)); string baseString = ConstructSignatureBaseString(message, this.Channel.MessageDescriptions.GetAccessor(message)); - byte[] digest = hasher.ComputeHash(Encoding.ASCII.GetBytes(baseString)); + byte[] digest = hasher.ComputeHash(encoding.GetBytes(baseString)); return Convert.ToBase64String(digest); } diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs index f2d69f5..2edc91b 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs @@ -13,9 +13,13 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { using System.IO; using System.Linq; using System.Net; +#if !SILVERLIGHT using System.Net.Mime; +#endif using System.Text; +#if !SILVERLIGHT using System.Web; +#endif using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Messaging.Reflection; @@ -39,6 +43,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { new OAuthConsumerMessageFactory()) { } +#if !SILVERLIGHT /// <summary> /// Initializes a new instance of the <see cref="OAuthChannel"/> class. /// </summary> @@ -52,6 +57,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { tokenManager, new OAuthServiceProviderMessageFactory(tokenManager)) { } +#endif /// <summary> /// Initializes a new instance of the <see cref="OAuthChannel"/> class. @@ -109,6 +115,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { return this.CreateHttpRequest(request); } +#if !SILVERLIGHT /// <summary> /// Searches an incoming HTTP request for data that could be used to assemble /// a protocol request message. @@ -186,6 +193,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { return message; } +#endif /// <summary> /// Gets the protocol message that may be in the given HTTP response. @@ -196,7 +204,11 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// </returns> protected override IDictionary<string, string> ReadFromResponseCore(IncomingWebResponse response) { string body = response.GetResponseReader().ReadToEnd(); +#if !SILVERLIGHT return HttpUtility.ParseQueryString(body).ToDictionary(); +#else + return MessagingUtilities.ParseQueryString(body); +#endif } /// <summary> @@ -230,6 +242,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { return httpRequest; } +#if !SILVERLIGHT /// <summary> /// Queues a message for sending in the response stream where the fields /// are sent in the response stream in querystring style. @@ -258,6 +271,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { return encodedResponse; } +#endif /// <summary> /// Initializes the binding elements for the OAuth channel. @@ -274,10 +288,12 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { new StandardReplayProtectionBindingElement(store), }; +#if !SILVERLIGHT var spTokenManager = tokenManager as IServiceProviderTokenManager; if (spTokenManager != null) { bindingElements.Insert(0, new TokenHandlingBindingElement(spTokenManager)); } +#endif return bindingElements.ToArray(); } @@ -359,7 +375,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { } authorization.Length--; // remove trailing comma - httpRequest.Headers.Add(HttpRequestHeader.Authorization, authorization.ToString()); + httpRequest.Headers[HttpRequestHeader.Authorization] = authorization.ToString(); if (hasEntity) { // WARNING: We only set up the request stream for the caller if there is @@ -416,7 +432,11 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { ErrorUtilities.VerifyInternal(consumerKey == consumerTokenManager.ConsumerKey, "The token manager consumer key and the consumer key set earlier do not match!"); return consumerTokenManager.ConsumerSecret; } else { +#if !SILVERLIGHT return ((IServiceProviderTokenManager)this.TokenManager).GetConsumer(consumerKey).Secret; +#else + throw new NotSupportedException(); +#endif } } } diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthIdentity.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthIdentity.cs index 65bde20..6f6ce55 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthIdentity.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthIdentity.cs @@ -16,7 +16,9 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// Represents an OAuth consumer that is impersonating a known user on the system. /// </summary> [SuppressMessage("Microsoft.Interoperability", "CA1409:ComVisibleTypesShouldBeCreatable", Justification = "Not cocreatable.")] +#if !SILVERLIGHT [Serializable] +#endif [ComVisible(true)] public class OAuthIdentity : IIdentity { /// <summary> diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthPrincipal.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthPrincipal.cs index 025ef09..0582856 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthPrincipal.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthPrincipal.cs @@ -17,7 +17,9 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { /// Represents an OAuth consumer that is impersonating a known user on the system. /// </summary> [SuppressMessage("Microsoft.Interoperability", "CA1409:ComVisibleTypesShouldBeCreatable", Justification = "Not cocreatable.")] +#if !SILVERLIGHT [Serializable] +#endif [ComVisible(true)] public class OAuthPrincipal : IPrincipal { /// <summary> diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs index cb81139..167afbb 100644 --- a/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs +++ b/src/DotNetOpenAuth/OAuth/ChannelElements/SigningBindingElementBase.cs @@ -12,7 +12,9 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { using System.Globalization; using System.Linq; using System.Text; +#if !SILVERLIGHT using System.Web; +#endif using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Messaging.Reflection; @@ -186,8 +188,13 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { // In an outgoing message, the POST entity can only contain parameters if they were // in the message dictionary, so no need to pull out any parameters from there. if (message.Recipient.Query != null) { +#if !SILVERLIGHT NameValueCollection nvc = HttpUtility.ParseQueryString(message.Recipient.Query); foreach (string key in nvc) { +#else + IDictionary<string, string> nvc = MessagingUtilities.ParseQueryString(message.Recipient.Query); + foreach (string key in nvc.Keys) { +#endif string escapedKey = MessagingUtilities.EscapeUriDataStringRfc3986(key); string escapedValue = MessagingUtilities.EscapeUriDataStringRfc3986(nvc[key]); string existingValue; diff --git a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs index dddbe9e..4b90199 100644 --- a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs +++ b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs @@ -11,7 +11,9 @@ namespace DotNetOpenAuth.OAuth { using System.Diagnostics.Contracts; using System.Linq; using System.Net; +#if !SILVERLIGHT using DotNetOpenAuth.Configuration; +#endif using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.OAuth.ChannelElements; @@ -31,12 +33,15 @@ namespace DotNetOpenAuth.OAuth { Contract.Requires<ArgumentNullException>(tokenManager != null); ITamperProtectionChannelBindingElement signingElement = serviceDescription.CreateTamperProtectionElement(); - INonceStore store = new NonceMemoryStore(StandardExpirationBindingElement.MaximumMessageAge); - this.OAuthChannel = new OAuthChannel(signingElement, store, tokenManager); + this.OAuthChannel = new OAuthChannel(signingElement, null, tokenManager); this.ServiceProvider = serviceDescription; - this.SecuritySettings = DotNetOpenAuthSection.Configuration.OAuth.Consumer.SecuritySettings.CreateSecuritySettings(); +#if !SILVERLIGHT + this.SecuritySettings = DotNetOpenAuthSection.Configuration.OAuth.Consumer.SecuritySettings.CreateSecuritySettings(); Reporting.RecordFeatureAndDependencyUse(this, serviceDescription, tokenManager, null); +#else + this.SecuritySettings = new ConsumerSecuritySettings(); +#endif } /// <summary> diff --git a/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs b/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs index f9c1a94..fde9d60 100644 --- a/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs +++ b/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs @@ -30,6 +30,7 @@ namespace DotNetOpenAuth.OAuth { : base(serviceDescription, tokenManager) { } +#if !SILVERLIGHT /// <summary> /// Begins an OAuth authorization request. /// </summary> @@ -43,6 +44,7 @@ namespace DotNetOpenAuth.OAuth { OutgoingWebResponse response = this.Channel.PrepareResponse(message); return response.GetDirectUriRequest(this.Channel); } +#endif /// <summary> /// Exchanges a given request token for access token. diff --git a/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs b/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs index 1a0ba23..f40834c 100644 --- a/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs +++ b/src/DotNetOpenAuth/OAuth/Messages/MessageBase.cs @@ -17,7 +17,9 @@ namespace DotNetOpenAuth.OAuth.Messages { /// <summary> /// A base class for all OAuth messages. /// </summary> +#if !SILVERLIGHT [Serializable] +#endif public abstract class MessageBase : IDirectedProtocolMessage, IDirectResponseProtocolMessage { /// <summary> /// A store for extra name/value data pairs that are attached to this message. diff --git a/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationRequest.cs b/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationRequest.cs index a5823bb..ea1f994 100644 --- a/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationRequest.cs +++ b/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationRequest.cs @@ -15,7 +15,9 @@ namespace DotNetOpenAuth.OAuth.Messages { /// so the Service Provider can ask the user to authorize the Consumer's access to some /// protected resource(s). /// </summary> +#if !SILVERLIGHT [Serializable] +#endif public class UserAuthorizationRequest : MessageBase, ITokenContainingMessage { /// <summary> /// Initializes a new instance of the <see cref="UserAuthorizationRequest"/> class. diff --git a/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationResponse.cs b/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationResponse.cs index 73fddc7..4d38722 100644 --- a/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationResponse.cs +++ b/src/DotNetOpenAuth/OAuth/Messages/UserAuthorizationResponse.cs @@ -14,7 +14,9 @@ namespace DotNetOpenAuth.OAuth.Messages { /// <remarks> /// The class is sealed because extra parameters are determined by the callback URI provided by the Consumer. /// </remarks> +#if !SILVERLIGHT [Serializable] +#endif public sealed class UserAuthorizationResponse : MessageBase, ITokenContainingMessage { /// <summary> /// Initializes a new instance of the <see cref="UserAuthorizationResponse"/> class. diff --git a/src/DotNetOpenAuth/OAuth/WebConsumer.cs b/src/DotNetOpenAuth/OAuth/WebConsumer.cs index de37b80..e3bbfef 100644 --- a/src/DotNetOpenAuth/OAuth/WebConsumer.cs +++ b/src/DotNetOpenAuth/OAuth/WebConsumer.cs @@ -8,12 +8,16 @@ namespace DotNetOpenAuth.OAuth { using System; using System.Collections.Generic; using System.Diagnostics.Contracts; +#if !SILVERLIGHT using System.Web; +#endif using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth.ChannelElements; using DotNetOpenAuth.OAuth.Messages; +#if !SILVERLIGHT using DotNetOpenAuth.OpenId.Extensions.OAuth; using DotNetOpenAuth.OpenId.RelyingParty; +#endif /// <summary> /// A website or application that uses OAuth to access the Service Provider on behalf of the User. @@ -32,6 +36,7 @@ namespace DotNetOpenAuth.OAuth { : base(serviceDescription, tokenManager) { } +#if !SILVERLIGHT /// <summary> /// Begins an OAuth authorization request and redirects the user to the Service Provider /// to provide that authorization. Upon successful authorization, the user is redirected @@ -45,6 +50,7 @@ namespace DotNetOpenAuth.OAuth { Uri callback = this.Channel.GetRequestFromContext().UrlBeforeRewriting.StripQueryArgumentsWithPrefix(Protocol.ParameterPrefix); return this.PrepareRequestUserAuthorization(callback, null, null); } +#endif /// <summary> /// Prepares an OAuth message that begins an authorization request that will @@ -62,6 +68,7 @@ namespace DotNetOpenAuth.OAuth { return this.PrepareRequestUserAuthorization(callback, requestParameters, redirectParameters, out token); } +#if !SILVERLIGHT /// <summary> /// Processes an incoming authorization-granted message from an SP and obtains an access token. /// </summary> @@ -151,5 +158,6 @@ namespace DotNetOpenAuth.OAuth { return null; } } +#endif } } diff --git a/src/DotNetOpenAuth/UriUtil.cs b/src/DotNetOpenAuth/UriUtil.cs index 819c406..9915575 100644 --- a/src/DotNetOpenAuth/UriUtil.cs +++ b/src/DotNetOpenAuth/UriUtil.cs @@ -11,9 +11,12 @@ namespace DotNetOpenAuth { using System.Diagnostics.Contracts; using System.Linq; using System.Text.RegularExpressions; +#if !SILVERLIGHT using System.Web; using System.Web.UI; +#endif using DotNetOpenAuth.Messaging; + using System.Collections.Generic; /// <summary> /// Utility methods for working with URIs. @@ -35,7 +38,11 @@ namespace DotNetOpenAuth { return false; } +#if !SILVERLIGHT NameValueCollection nvc = HttpUtility.ParseQueryString(uri.Query); +#else + IDictionary<string, string> nvc = MessagingUtilities.ParseQueryString(uri.Query); +#endif Contract.Assume(nvc != null); // BCL return nvc.Keys.OfType<string>().Any(key => key.StartsWith(prefix, StringComparison.Ordinal)); } @@ -81,6 +88,7 @@ namespace DotNetOpenAuth { } } +#if !SILVERLIGHT /// <summary> /// Validates that a URL will be resolvable at runtime. /// </summary> @@ -113,5 +121,6 @@ namespace DotNetOpenAuth { } } } +#endif } } diff --git a/src/DotNetOpenAuth/Util.cs b/src/DotNetOpenAuth/Util.cs index 0317c4d..6669e8b 100644 --- a/src/DotNetOpenAuth/Util.cs +++ b/src/DotNetOpenAuth/Util.cs @@ -11,10 +11,12 @@ namespace DotNetOpenAuth { using System.Net; using System.Reflection; using System.Text; +#if !SILVERLIGHT using System.Web; using System.Web.UI; using DotNetOpenAuth.Configuration; +#endif using DotNetOpenAuth.Messaging; /// <summary> @@ -27,10 +29,12 @@ namespace DotNetOpenAuth { /// </summary> internal const string DefaultNamespace = "DotNetOpenAuth"; +#if !SILVERLIGHT /// <summary> /// The web.config file-specified provider of web resource URLs. /// </summary> private static IEmbeddedResourceRetrieval embeddedResourceRetrieval = DotNetOpenAuthSection.Configuration.EmbeddedResourceRetrievalProvider.CreateInstance(null, false); +#endif /// <summary> /// Gets a human-readable description of the library name and version, including @@ -162,6 +166,7 @@ namespace DotNetOpenAuth { }); } +#if !SILVERLIGHT /// <summary> /// Gets the web resource URL from a Page or <see cref="IEmbeddedResourceRetrieval"/> object. /// </summary> @@ -187,6 +192,7 @@ namespace DotNetOpenAuth { string.Join(", ", new string[] { typeof(Page).FullName, typeof(IEmbeddedResourceRetrieval).FullName }))); } } +#endif /// <summary> /// Manages an individual deferred ToString call. |