Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit 049482b

Browse files
committed
FxCop fixes.
1 parent 6cab4fb commit 049482b

63 files changed

Lines changed: 690 additions & 541 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

projecttemplates/RelyingPartyLogic/OAuthAuthorizationServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public bool CanBeAutoApproved(EndUserAuthorizationRequest authorizationRequest)
9898
// NEVER issue an auto-approval to a client that would end up getting an access token immediately
9999
// (without a client secret), as that would allow ANY client to spoof an approved client's identity
100100
// and obtain unauthorized access to user data.
101-
if (authorizationRequest.ResponseType == EndUserAuthorizationResponseType.AuthorizationCode) {
101+
if (EndUserAuthorizationRequest.ResponseType == EndUserAuthorizationResponseTypes.AuthorizationCode) {
102102
// Never issue auto-approval if the client secret is blank, since that too makes it easy to spoof
103103
// a client's identity and obtain unauthorized access.
104104
var requestingClient = Database.DataContext.Clients.First(c => c.ClientIdentifier == authorizationRequest.ClientIdentifier);

samples/OAuthAuthorizationServer/Code/OAuth2AuthorizationServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public bool CanBeAutoApproved(EndUserAuthorizationRequest authorizationRequest)
5353
// NEVER issue an auto-approval to a client that would end up getting an access token immediately
5454
// (without a client secret), as that would allow ANY client to spoof an approved client's identity
5555
// and obtain unauthorized access to user data.
56-
if (authorizationRequest.ResponseType == EndUserAuthorizationResponseType.AuthorizationCode) {
56+
if (EndUserAuthorizationRequest.ResponseType == EndUserAuthorizationResponseTypes.AuthorizationCode) {
5757
// Never issue auto-approval if the client secret is blank, since that too makes it easy to spoof
5858
// a client's identity and obtain unauthorized access.
5959
var requestingClient = MvcApplication.DataContext.Clients.First(c => c.ClientIdentifier == authorizationRequest.ClientIdentifier);
Lines changed: 134 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,137 @@
1-
namespace OAuthClient {
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Globalization;
5-
using System.Linq;
6-
using System.Net;
7-
using System.ServiceModel;
8-
using System.ServiceModel.Channels;
9-
using System.ServiceModel.Security;
10-
using System.Web;
11-
using System.Web.UI;
12-
using System.Web.UI.WebControls;
13-
using DotNetOpenAuth.OAuth2;
14-
15-
using SampleResourceServer;
16-
17-
public partial class SampleWcf2 : System.Web.UI.Page {
18-
/// <summary>
19-
/// The OAuth 2.0 client object to use to obtain authorization and authorize outgoing HTTP requests.
20-
/// </summary>
21-
private static readonly WebServerClient Client;
22-
23-
/// <summary>
24-
/// The details about the sample OAuth-enabled WCF service that this sample client calls into.
25-
/// </summary>
26-
private static AuthorizationServerDescription authServerDescription = new AuthorizationServerDescription {
27-
TokenEndpoint = new Uri("http://localhost:50172/OAuth/Token"),
28-
AuthorizationEndpoint = new Uri("http://localhost:50172/OAuth/Authorize"),
29-
};
30-
31-
/// <summary>
32-
/// Initializes static members of the <see cref="SampleWcf2"/> class.
33-
/// </summary>
34-
static SampleWcf2() {
35-
Client = new WebServerClient(authServerDescription, "sampleconsumer", "samplesecret");
36-
}
37-
38-
/// <summary>
39-
/// Gets or sets the authorization details for the logged in user.
40-
/// </summary>
41-
/// <value>The authorization details.</value>
42-
/// <remarks>
43-
/// Because this is a sample, we simply store the authorization information in memory with the user session.
44-
/// A real web app should store at least the access and refresh tokens in this object in a database associated with the user.
45-
/// </remarks>
46-
private static IAuthorizationState Authorization {
47-
get { return (AuthorizationState)HttpContext.Current.Session["Authorization"]; }
48-
set { HttpContext.Current.Session["Authorization"] = value; }
49-
}
50-
51-
protected void Page_Load(object sender, EventArgs e) {
52-
if (!IsPostBack) {
53-
// Check to see if we're receiving a end user authorization response.
54-
var authorization = Client.ProcessUserAuthorization();
55-
if (authorization != null) {
56-
// We are receiving an authorization response. Store it and associate it with this user.
57-
Authorization = authorization;
58-
Response.Redirect(Request.Path); // get rid of the /?code= parameter
59-
}
60-
}
61-
62-
if (Authorization != null) {
63-
// Indicate to the user that we have already obtained authorization on some of these.
64-
foreach (var li in this.scopeList.Items.OfType<ListItem>().Where(li => Authorization.Scope.Contains(li.Value))) {
65-
li.Selected = true;
66-
}
67-
this.authorizationLabel.Text = "Authorization received!";
68-
if (Authorization.AccessTokenExpirationUtc.HasValue) {
1+
namespace OAuthClient {
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Net;
7+
using System.ServiceModel;
8+
using System.ServiceModel.Channels;
9+
using System.ServiceModel.Security;
10+
using System.Web;
11+
using System.Web.UI;
12+
using System.Web.UI.WebControls;
13+
using DotNetOpenAuth.OAuth2;
14+
15+
using SampleResourceServer;
16+
17+
public partial class SampleWcf2 : System.Web.UI.Page {
18+
/// <summary>
19+
/// The OAuth 2.0 client object to use to obtain authorization and authorize outgoing HTTP requests.
20+
/// </summary>
21+
private static readonly WebServerClient Client;
22+
23+
/// <summary>
24+
/// The details about the sample OAuth-enabled WCF service that this sample client calls into.
25+
/// </summary>
26+
private static AuthorizationServerDescription authServerDescription = new AuthorizationServerDescription {
27+
TokenEndpoint = new Uri("http://localhost:50172/OAuth/Token"),
28+
AuthorizationEndpoint = new Uri("http://localhost:50172/OAuth/Authorize"),
29+
};
30+
31+
/// <summary>
32+
/// Initializes static members of the <see cref="SampleWcf2"/> class.
33+
/// </summary>
34+
static SampleWcf2() {
35+
Client = new WebServerClient(authServerDescription, "sampleconsumer", "samplesecret");
36+
}
37+
38+
/// <summary>
39+
/// Gets or sets the authorization details for the logged in user.
40+
/// </summary>
41+
/// <value>The authorization details.</value>
42+
/// <remarks>
43+
/// Because this is a sample, we simply store the authorization information in memory with the user session.
44+
/// A real web app should store at least the access and refresh tokens in this object in a database associated with the user.
45+
/// </remarks>
46+
private static IAuthorizationState Authorization {
47+
get { return (AuthorizationState)HttpContext.Current.Session["Authorization"]; }
48+
set { HttpContext.Current.Session["Authorization"] = value; }
49+
}
50+
51+
protected void Page_Load(object sender, EventArgs e) {
52+
if (!IsPostBack) {
53+
// Check to see if we're receiving a end user authorization response.
54+
var authorization = Client.ProcessUserAuthorization();
55+
if (authorization != null) {
56+
// We are receiving an authorization response. Store it and associate it with this user.
57+
Authorization = authorization;
58+
Response.Redirect(Request.Path); // get rid of the /?code= parameter
59+
}
60+
}
61+
62+
if (Authorization != null) {
63+
// Indicate to the user that we have already obtained authorization on some of these.
64+
foreach (var li in this.scopeList.Items.OfType<ListItem>().Where(li => Authorization.Scope.Contains(li.Value))) {
65+
li.Selected = true;
66+
}
67+
this.authorizationLabel.Text = "Authorization received!";
68+
if (Authorization.AccessTokenExpirationUtc.HasValue) {
6969
TimeSpan timeLeft = Authorization.AccessTokenExpirationUtc.Value - DateTime.UtcNow;
70-
this.authorizationLabel.Text += string.Format(CultureInfo.CurrentCulture, " (access token expires in {0} minutes)", Math.Round(timeLeft.TotalMinutes, 1));
71-
}
72-
}
73-
74-
this.getNameButton.Enabled = this.getAgeButton.Enabled = this.getFavoriteSites.Enabled = Authorization != null;
75-
}
76-
77-
protected void getAuthorizationButton_Click(object sender, EventArgs e) {
78-
string[] scopes = (from item in this.scopeList.Items.OfType<ListItem>()
79-
where item.Selected
80-
select item.Value).ToArray();
81-
82-
Client.RequestUserAuthorization(scopes);
83-
}
84-
85-
protected void getNameButton_Click(object sender, EventArgs e) {
86-
try {
87-
this.nameLabel.Text = CallService(client => client.GetName());
88-
} catch (SecurityAccessDeniedException) {
89-
this.nameLabel.Text = "Access denied!";
90-
}
91-
}
92-
93-
protected void getAgeButton_Click(object sender, EventArgs e) {
94-
try {
95-
int? age = CallService(client => client.GetAge());
96-
this.ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available";
97-
} catch (SecurityAccessDeniedException) {
98-
this.ageLabel.Text = "Access denied!";
99-
}
100-
}
101-
102-
protected void getFavoriteSites_Click(object sender, EventArgs e) {
103-
try {
104-
string[] favoriteSites = CallService(client => client.GetFavoriteSites());
105-
this.favoriteSitesLabel.Text = string.Join(", ", favoriteSites);
106-
} catch (SecurityAccessDeniedException) {
107-
this.favoriteSitesLabel.Text = "Access denied!";
108-
}
109-
}
110-
111-
private T CallService<T>(Func<DataApiClient, T> predicate) {
112-
if (Authorization == null) {
113-
throw new InvalidOperationException("No access token!");
114-
}
115-
116-
var wcfClient = new DataApiClient();
117-
118-
// Refresh the access token if it expires and if its lifetime is too short to be of use.
119-
if (Authorization.AccessTokenExpirationUtc.HasValue) {
120-
if (Client.RefreshToken(Authorization, TimeSpan.FromSeconds(30))) {
70+
this.authorizationLabel.Text += string.Format(CultureInfo.CurrentCulture, " (access token expires in {0} minutes)", Math.Round(timeLeft.TotalMinutes, 1));
71+
}
72+
}
73+
74+
this.getNameButton.Enabled = this.getAgeButton.Enabled = this.getFavoriteSites.Enabled = Authorization != null;
75+
}
76+
77+
protected void getAuthorizationButton_Click(object sender, EventArgs e) {
78+
string[] scopes = (from item in this.scopeList.Items.OfType<ListItem>()
79+
where item.Selected
80+
select item.Value).ToArray();
81+
82+
Client.RequestUserAuthorization(scopes);
83+
}
84+
85+
protected void getNameButton_Click(object sender, EventArgs e) {
86+
try {
87+
this.nameLabel.Text = CallService(client => client.GetName());
88+
} catch (SecurityAccessDeniedException) {
89+
this.nameLabel.Text = "Access denied!";
90+
}
91+
}
92+
93+
protected void getAgeButton_Click(object sender, EventArgs e) {
94+
try {
95+
int? age = CallService(client => client.GetAge());
96+
this.ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available";
97+
} catch (SecurityAccessDeniedException) {
98+
this.ageLabel.Text = "Access denied!";
99+
}
100+
}
101+
102+
protected void getFavoriteSites_Click(object sender, EventArgs e) {
103+
try {
104+
string[] favoriteSites = CallService(client => client.GetFavoriteSites());
105+
this.favoriteSitesLabel.Text = string.Join(", ", favoriteSites);
106+
} catch (SecurityAccessDeniedException) {
107+
this.favoriteSitesLabel.Text = "Access denied!";
108+
}
109+
}
110+
111+
private T CallService<T>(Func<DataApiClient, T> predicate) {
112+
if (Authorization == null) {
113+
throw new InvalidOperationException("No access token!");
114+
}
115+
116+
var wcfClient = new DataApiClient();
117+
118+
// Refresh the access token if it expires and if its lifetime is too short to be of use.
119+
if (Authorization.AccessTokenExpirationUtc.HasValue) {
120+
if (Client.RefreshToken(Authorization, TimeSpan.FromSeconds(30))) {
121121
TimeSpan timeLeft = Authorization.AccessTokenExpirationUtc.Value - DateTime.UtcNow;
122-
this.authorizationLabel.Text += string.Format(CultureInfo.CurrentCulture, " - just renewed for {0} more minutes)", Math.Round(timeLeft.TotalMinutes, 1));
123-
}
124-
}
125-
126-
var httpRequest = (HttpWebRequest)WebRequest.Create(wcfClient.Endpoint.Address.Uri);
127-
Client.AuthorizeRequest(httpRequest, Authorization.AccessToken);
128-
129-
var httpDetails = new HttpRequestMessageProperty();
130-
httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization];
131-
using (var scope = new OperationContextScope(wcfClient.InnerChannel)) {
132-
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails;
133-
return predicate(wcfClient);
134-
}
135-
}
136-
}
122+
this.authorizationLabel.Text += string.Format(CultureInfo.CurrentCulture, " - just renewed for {0} more minutes)", Math.Round(timeLeft.TotalMinutes, 1));
123+
}
124+
}
125+
126+
var httpRequest = (HttpWebRequest)WebRequest.Create(wcfClient.Endpoint.Address.Uri);
127+
ClientBase.AuthorizeRequest(httpRequest, Authorization.AccessToken);
128+
129+
var httpDetails = new HttpRequestMessageProperty();
130+
httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization];
131+
using (var scope = new OperationContextScope(wcfClient.InnerChannel)) {
132+
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails;
133+
return predicate(wcfClient);
134+
}
135+
}
136+
}
137137
}

src/DotNetOpenAuth.Test/Messaging/MessageSerializerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void SerializeDeserializeJson() {
6565

6666
var ms = new MemoryStream();
6767
var writer = JsonReaderWriterFactory.CreateJsonWriter(ms, Encoding.UTF8);
68-
serializer.Serialize(this.MessageDescriptions.GetAccessor(message), writer);
68+
MessageSerializer.Serialize(this.MessageDescriptions.GetAccessor(message), writer);
6969
writer.Flush();
7070

7171
string actual = Encoding.UTF8.GetString(ms.ToArray());
@@ -75,7 +75,7 @@ public void SerializeDeserializeJson() {
7575
ms.Position = 0;
7676
var deserialized = new Mocks.TestDirectedMessage();
7777
var reader = JsonReaderWriterFactory.CreateJsonReader(ms, XmlDictionaryReaderQuotas.Max);
78-
serializer.Deserialize(this.MessageDescriptions.GetAccessor(deserialized), reader);
78+
MessageSerializer.Deserialize(this.MessageDescriptions.GetAccessor(deserialized), reader);
7979
Assert.AreEqual(message.Age, deserialized.Age);
8080
Assert.AreEqual(message.EmptyMember, deserialized.EmptyMember);
8181
Assert.AreEqual(message.Location, deserialized.Location);
@@ -86,7 +86,7 @@ public void SerializeDeserializeJson() {
8686
[TestCase, ExpectedException(typeof(ArgumentNullException))]
8787
public void DeserializeNull() {
8888
var serializer = MessageSerializer.Get(typeof(Mocks.TestMessage));
89-
serializer.Deserialize(null, null);
89+
MessageSerializer.Deserialize(null, null);
9090
}
9191

9292
[TestCase]
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Dictionary>
3+
<Words>
4+
<!--
5+
This is a list of case-insensitive words that exist in the dictionary
6+
but you do not want to be recognized by IdentifiersShouldBeSpelledCorrectly.
7+
Do not add deprecated terms to this list, instead add these to the
8+
<Deprecated> section below.
9+
-->
10+
<Unrecognized>
11+
<!--<Word>cb</Word>-->
12+
</Unrecognized>
13+
<!--
14+
This is a list of case-insensitive words that do not exist in the dictionary
15+
but you still want to be considered as recognized by
16+
IdentifiersShouldBeSpelledCorrectly. Do not add compound words (e.g. 'FileName')
17+
to this list as this will cause CompoundWordsShouldBeBeCasedCorrectly to fire on
18+
usages of the compound word stating that they should be changed to their discrete equivalent
19+
(for example 'FileName' -> 'Filename').
20+
-->
21+
<Recognized>
22+
<Word>OAuth</Word>
23+
<!--<Word>cryptoKeyStore</Word>
24+
<Word>containingMessage</Word>
25+
<Word>httpRequestInfo</Word>
26+
<Word>faultedMessage</Word>
27+
<Word>keyStore</Word>
28+
<Word>authorizationServer</Word>
29+
<Word>bytesToSign</Word>
30+
<Word>clientCallback</Word>-->
31+
</Recognized>
32+
<Deprecated>
33+
<!--
34+
This is a list of deprecated terms with their preferred alternates and is
35+
used by UsePreferredTerms. The deprecated terms are case-insensitive,
36+
however, make sure to pascal-case the preferred alternates. If a word
37+
does not have a preferred alternate, simply leave it blank.
38+
-->
39+
<!--<Term PreferredAlternate="EnterpriseServices">complus</Term>-->
40+
</Deprecated>
41+
<Compound>
42+
<!--
43+
This is a list of discrete terms with their compound alternates and is used by
44+
CompoundWordsShouldBeCasedCorrectly. These are words that exist in the
45+
dictionary as discrete terms, however, should actually be cased as compound words.
46+
For example, 'Filename' exists in the dictionary and hence the spelling rules will
47+
not see it as unrecognized but its actual preferred usage is 'FileName'; adding it
48+
below causes CompoundWordsShouldBeCasedCorrectly to fire. The discrete terms are
49+
case-insensitive, however, be sure to pascal-case the compound alternates.
50+
Any discrete terms added below automatically get added to the list of discrete
51+
exceptions to prevent CompoundWordsShouldBeCasedCorrectly from firing both on the
52+
compound word (for example 'WhiteSpace') and its discrete alternate (for example
53+
'Whitespace').
54+
-->
55+
<Term CompoundAlternate="OAuth">oauth</Term>
56+
<!--<Term CompoundAlternate="DataBind">databind</Term>-->
57+
</Compound>
58+
<DiscreteExceptions>
59+
<!--
60+
This is a list of case-insensitive exceptions to the CompoundWordsShouldBeCasedCorrectly
61+
discrete term check. As this check works solely on the basis of whether two consecutive
62+
tokens exists in the dictionary, it can have a high false positive rate. For example,
63+
'onset' exists in the dictionary but the user probably intended it to be 'OnSet'.
64+
Adding this word below prevents this rule from firing telling the user to change 'OnSet'
65+
to 'Onset'.
66+
-->
67+
<Term>oauth</Term>
68+
<!--<Term>onset</Term>-->
69+
</DiscreteExceptions>
70+
</Words>
71+
</Dictionary>

src/DotNetOpenAuth/DotNetOpenAuth.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ http://opensource.org/licenses/ms-pl.html
860860
<ProductName>Windows Installer 3.1</ProductName>
861861
<Install>true</Install>
862862
</BootstrapperPackage>
863+
<CodeAnalysisDictionary Include="CodeAnalysisDictionary.xml" />
863864
<Content Include="DotNetOpenAuth.ico" />
864865
</ItemGroup>
865866
<ItemGroup>

0 commit comments

Comments
 (0)