diff options
19 files changed, 134 insertions, 29 deletions
diff --git a/src/DotNetOpenAuth.AspNet.Test/Settings.StyleCop b/src/DotNetOpenAuth.AspNet.Test/Settings.StyleCop new file mode 100644 index 0000000..ae8997c --- /dev/null +++ b/src/DotNetOpenAuth.AspNet.Test/Settings.StyleCop @@ -0,0 +1,48 @@ +<StyleCopSettings Version="4.3"> + <Analyzers> + <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.DocumentationRules"> + <Rules> + <Rule Name="ElementsMustBeDocumented"> + <RuleSettings> + <BooleanProperty Name="Enabled">False</BooleanProperty> + </RuleSettings> + </Rule> + <Rule Name="EnumerationItemsMustBeDocumented"> + <RuleSettings> + <BooleanProperty Name="Enabled">False</BooleanProperty> + </RuleSettings> + </Rule> + </Rules> + <AnalyzerSettings /> + </Analyzer> + <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.LayoutRules"> + <Rules> + <Rule Name="SingleLineCommentMustBePrecededByBlankLine"> + <RuleSettings> + <BooleanProperty Name="Enabled">False</BooleanProperty> + </RuleSettings> + </Rule> + </Rules> + <AnalyzerSettings /> + </Analyzer> + <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules"> + <AnalyzerSettings> + <CollectionProperty Name="Hungarian"> + <Value>op</Value> + <Value>rp</Value> + <Value>v</Value> + </CollectionProperty> + </AnalyzerSettings> + </Analyzer> + <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.MaintainabilityRules"> + <Rules> + <Rule Name="FieldsMustBePrivate"> + <RuleSettings> + <BooleanProperty Name="Enabled">False</BooleanProperty> + </RuleSettings> + </Rule> + </Rules> + <AnalyzerSettings /> + </Analyzer> + </Analyzers> +</StyleCopSettings>
\ No newline at end of file diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs index 9979d97..9757f30 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs @@ -16,7 +16,7 @@ namespace DotNetOpenAuth.AspNet.Clients { /// <summary> /// The dot net open auth web consumer. /// </summary> - public class DotNetOpenAuthWebConsumer : IOAuthWebWorker { + public class DotNetOpenAuthWebConsumer : IOAuthWebWorker, IDisposable { #region Constants and Fields /// <summary> @@ -90,5 +90,28 @@ namespace DotNetOpenAuth.AspNet.Clients { } #endregion + + #region IDisposable members + + /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + /// <filterpriority>2</filterpriority> + public void Dispose() { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + #endregion + + /// <summary> + /// Releases unmanaged and - optionally - managed resources + /// </summary> + /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> + protected virtual void Dispose(bool disposing) { + if (disposing) { + this._webConsumer.Dispose(); + } + } } } diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs index bae3f82..4152f0a 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs @@ -6,6 +6,7 @@ namespace DotNetOpenAuth.AspNet.Clients { using System; + using System.Diagnostics.CodeAnalysis; using System.Web; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth; @@ -50,6 +51,7 @@ namespace DotNetOpenAuth.AspNet.Clients { /// <param name="tokenManager"> /// The token Manager. /// </param> + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "I don't know how to ensure this rule is followed given this API")] protected OAuthClient( string providerName, ServiceProviderDescription serviceDescription, IConsumerTokenManager tokenManager) : this(providerName, new DotNetOpenAuthWebConsumer(serviceDescription, tokenManager)) {} diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs index 66a6a95..01318b8 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs @@ -79,8 +79,8 @@ namespace DotNetOpenAuth.AspNet.Clients { string userId = response.ExtraData["user_id"]; string userName = response.ExtraData["screen_name"]; - string profileRequestUrl = "http://api.twitter.com/1/users/show.xml?user_id=" - + MessagingUtilities.EscapeUriDataStringRfc3986(userId); + var profileRequestUrl = new Uri("http://api.twitter.com/1/users/show.xml?user_id=" + + MessagingUtilities.EscapeUriDataStringRfc3986(userId)); var profileEndpoint = new MessageReceivingEndpoint(profileRequestUrl, HttpDeliveryMethods.GetRequest); HttpWebRequest request = this.WebWorker.PrepareAuthorizedRequest(profileEndpoint, accessToken); diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs index 54661b2..2d12202 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs @@ -7,6 +7,7 @@ namespace DotNetOpenAuth.AspNet.Clients { using System; using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Net; using System.Web; using DotNetOpenAuth.Messaging; @@ -14,6 +15,7 @@ namespace DotNetOpenAuth.AspNet.Clients { /// <summary> /// The facebook client. /// </summary> + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Facebook", Justification = "Brand name")] public sealed class FacebookClient : OAuth2Client { #region Constants and Fields diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs index 53c2797..9ad3eff 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs @@ -7,6 +7,7 @@ namespace DotNetOpenAuth.AspNet.Clients { using System; using System.ComponentModel; + using System.Diagnostics.CodeAnalysis; using System.Runtime.Serialization; /// <summary> @@ -17,6 +18,7 @@ namespace DotNetOpenAuth.AspNet.Clients { /// </remarks> [DataContract] [EditorBrowsable(EditorBrowsableState.Never)] + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Facebook", Justification = "Brand name")] public class FacebookGraphData { #region Public Properties diff --git a/src/DotNetOpenAuth.AspNet/Properties/AssemblyInfo.cs b/src/DotNetOpenAuth.AspNet/Properties/AssemblyInfo.cs index dac3fa4..6640257 100644 --- a/src/DotNetOpenAuth.AspNet/Properties/AssemblyInfo.cs +++ b/src/DotNetOpenAuth.AspNet/Properties/AssemblyInfo.cs @@ -4,9 +4,9 @@ // </copyright> //----------------------------------------------------------------------- - - +using System; using System.Reflection; +using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -21,6 +21,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en-US")] +[assembly: CLSCompliant(true)] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/src/DotNetOpenAuth.Core/Messaging/Channel.cs b/src/DotNetOpenAuth.Core/Messaging/Channel.cs index 2e4da38..16e39d3 100644 --- a/src/DotNetOpenAuth.Core/Messaging/Channel.cs +++ b/src/DotNetOpenAuth.Core/Messaging/Channel.cs @@ -602,6 +602,7 @@ namespace DotNetOpenAuth.Messaging { /// Gets the HTTP context for the current HTTP request. /// </summary> /// <returns>An HttpContextBase instance.</returns> + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Allocates memory")] protected internal virtual HttpContextBase GetHttpContext() { Requires.ValidState(HttpContext.Current != null, MessagingStrings.HttpContextRequired); return new HttpContextWrapper(HttpContext.Current); @@ -644,6 +645,22 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> + /// Applies message prescribed HTTP response headers to an outgoing web response. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="response">The HTTP response.</param> + protected static void ApplyMessageTemplate(IMessage message, OutgoingWebResponse response) { + Requires.NotNull(message, "message"); + var httpMessage = message as IHttpDirectResponse; + if (httpMessage != null) { + response.Status = httpMessage.HttpStatusCode; + foreach (string headerName in httpMessage.Headers) { + response.Headers.Add(headerName, httpMessage.Headers[headerName]); + } + } + } + + /// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> @@ -1044,22 +1061,6 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> - /// Applies message prescribed HTTP response headers to an outgoing web response. - /// </summary> - /// <param name="message">The message.</param> - /// <param name="response">The HTTP response.</param> - protected void ApplyMessageTemplate(IMessage message, OutgoingWebResponse response) { - Requires.NotNull(message, "message"); - var httpMessage = message as IHttpDirectResponse; - if (httpMessage != null) { - response.Status = httpMessage.HttpStatusCode; - foreach (string headerName in httpMessage.Headers) { - response.Headers.Add(headerName, httpMessage.Headers[headerName]); - } - } - } - - /// <summary> /// Prepares to send a request to the Service Provider as the query string in a GET request. /// </summary> /// <param name="requestMessage">The message to be transmitted to the ServiceProvider.</param> diff --git a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs index ace3777..b04c67e 100644 --- a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs +++ b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs @@ -224,7 +224,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements { Headers = new System.Net.WebHeaderCollection(), }; - this.ApplyMessageTemplate(response, encodedResponse); + ApplyMessageTemplate(response, encodedResponse); return encodedResponse; } diff --git a/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.Designer.cs b/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.Designer.cs index c05a4b8..c06a134 100644 --- a/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.Designer.cs +++ b/src/DotNetOpenAuth.OAuth2.Client.UI/OAuth2/ClientAuthorizationView.Designer.cs @@ -1,4 +1,6 @@ namespace DotNetOpenAuth.OAuth2 { + using System.Diagnostics.CodeAnalysis; + partial class ClientAuthorizationView { /// <summary> /// Required designer variable. @@ -22,6 +24,7 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> + [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification = "I don't see a problem here.")] private void InitializeComponent() { this.webBrowser1 = new System.Windows.Forms.WebBrowser(); this.SuspendLayout(); diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs index cfbc886..c29d167 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs @@ -58,7 +58,7 @@ namespace DotNetOpenAuth.OAuth2 { Callback = returnTo, }; - return this.RequestUserAuthorization(authorization); + return this.RequestUserAuthorization(authorization, state: state); } /// <summary> @@ -118,12 +118,11 @@ namespace DotNetOpenAuth.OAuth2 { EndUserAuthorizationSuccessAccessTokenResponse accessTokenSuccess; EndUserAuthorizationSuccessAuthCodeResponse authCodeSuccess; - EndUserAuthorizationFailedResponse failure; if ((accessTokenSuccess = response as EndUserAuthorizationSuccessAccessTokenResponse) != null) { UpdateAuthorizationWithResponse(authorizationState, accessTokenSuccess); } else if ((authCodeSuccess = response as EndUserAuthorizationSuccessAuthCodeResponse) != null) { this.UpdateAuthorizationWithResponse(authorizationState, authCodeSuccess); - } else if ((failure = response as EndUserAuthorizationFailedResponse) != null) { + } else if (response is EndUserAuthorizationFailedResponse) { authorizationState.Delete(); return null; } diff --git a/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj b/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj index 0a2a8ff..438a21d 100644 --- a/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj +++ b/src/DotNetOpenAuth.OAuth2/DotNetOpenAuth.OAuth2.csproj @@ -18,6 +18,7 @@ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> </PropertyGroup> <ItemGroup> + <Compile Include="GlobalSuppressions.cs" /> <Compile Include="OAuth2\AuthorizationState.cs" /> <Compile Include="OAuth2\ChannelElements\AccessRequestBindingElement.cs" /> <Compile Include="OAuth2\ChannelElements\AccessToken.cs" /> diff --git a/src/DotNetOpenAuth.OAuth2/GlobalSuppressions.cs b/src/DotNetOpenAuth.OAuth2/GlobalSuppressions.cs new file mode 100644 index 0000000..b91bb2e --- /dev/null +++ b/src/DotNetOpenAuth.OAuth2/GlobalSuppressions.cs @@ -0,0 +1,19 @@ +//----------------------------------------------------------------------- +// <copyright file="GlobalSuppressions.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. +// +// To add a suppression to this file, right-click the message in the +// Error List, point to "Suppress Message(s)", and click +// "In Project Suppression File". +// You do not need to add suppressions to this file manually. + +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase.#DotNetOpenAuth.OAuth2.Messages.IAccessTokenRequest.ClientAuthenticated", Justification = "By design")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "DotNetOpenAuth.OAuth2.Messages.AccessTokenRequestBase.#DotNetOpenAuth.OAuth2.Messages.IAccessTokenRequest.Scope", Justification = "By design")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationImplicitRequest.#DotNetOpenAuth.OAuth2.Messages.IAccessTokenRequest.ClientAuthenticated", Justification = "By design")] diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs index 0e6aa47..6717717 100644 --- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs +++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs @@ -56,7 +56,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements { /// </remarks> protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) { var webResponse = new OutgoingWebResponse(); - this.ApplyMessageTemplate(response, webResponse); + ApplyMessageTemplate(response, webResponse); string json = this.SerializeAsJson(response); webResponse.SetResponse(json, new ContentType(JsonEncoded)); return webResponse; diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs index 052da8e..947c044 100644 --- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs +++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2ResourceServerChannel.cs @@ -106,7 +106,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements { ErrorUtilities.VerifyInternal(unauthorizedResponse != null, "Only unauthorized responses are expected."); // First initialize based on the specifics within the message. - this.ApplyMessageTemplate(response, webResponse); + ApplyMessageTemplate(response, webResponse); if (!(response is IHttpDirectResponse)) { webResponse.Status = HttpStatusCode.Unauthorized; } diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessProtectedResourceRequest.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessProtectedResourceRequest.cs index 6cf8919..dbfe46b 100644 --- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessProtectedResourceRequest.cs +++ b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/AccessProtectedResourceRequest.cs @@ -62,7 +62,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// Always "bearer". /// </value> [MessagePart("token_type", IsRequired = true)] - internal string TokenType { + internal static string TokenType { get { return Protocol.AccessTokenTypes.Bearer; } } diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs index 1d9618b..ef0010e 100644 --- a/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs +++ b/src/DotNetOpenAuth.OAuth2/OAuth2/Messages/EndUserAuthorizationSuccessResponseBase.cs @@ -7,6 +7,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { using System; using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Security.Cryptography; @@ -59,6 +60,7 @@ namespace DotNetOpenAuth.OAuth2.Messages { /// Gets or sets the scope of the <see cref="AccessToken"/> if one is given; otherwise the scope of the authorization code. /// </summary> /// <value>The scope.</value> + [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "By design")] public ICollection<string> Scope { get; protected set; } /// <summary> diff --git a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs index 357c02d..6b88b3f 100644 --- a/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs +++ b/src/DotNetOpenAuth.OpenId/OpenId/ChannelElements/OpenIdChannel.cs @@ -181,7 +181,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements { byte[] keyValueEncoding = KeyValueFormEncoding.GetBytes(fields); OutgoingWebResponse preparedResponse = new OutgoingWebResponse(); - this.ApplyMessageTemplate(response, preparedResponse); + ApplyMessageTemplate(response, preparedResponse); preparedResponse.Headers.Add(HttpResponseHeader.ContentType, KeyValueFormContentType); preparedResponse.OriginalMessage = response; preparedResponse.ResponseStream = new MemoryStream(keyValueEncoding); diff --git a/tools/DotNetOpenAuth.Product.props b/tools/DotNetOpenAuth.Product.props index 90ece0c..7be814c 100644 --- a/tools/DotNetOpenAuth.Product.props +++ b/tools/DotNetOpenAuth.Product.props @@ -77,6 +77,7 @@ http://opensource.org/licenses/ms-pl.html </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)' == 'CodeAnalysis' "> + <DebugSymbols>true</DebugSymbols> <RunCodeAnalysis>true</RunCodeAnalysis> </PropertyGroup> |