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

Commit b3a35b9

Browse files
committed
Lots of StyleCop work, and one bug fix (can you find it? <g>)
1 parent 8ed398b commit b3a35b9

File tree

69 files changed

+1288
-318
lines changed

Some content is hidden

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

69 files changed

+1288
-318
lines changed

Settings.StyleCop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<AnalyzerSettings>
5757
<CollectionProperty Name="Hungarian">
5858
<Value>ax</Value>
59+
<Value>iv</Value>
5960
<Value>op</Value>
6061
<Value>rp</Value>
6162
<Value>sp</Value>

samples/OAuthConsumer/SampleWcf2.aspx.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using OAuthConsumer.SampleServiceProvider;
1616

1717
public partial class SampleWcf2 : System.Web.UI.Page {
18-
private static InMemoryClientTokenManager TokenManager = new InMemoryClientTokenManager();
18+
private static InMemoryClientTokenManager tokenManager = new InMemoryClientTokenManager();
1919

2020
private static IAuthorizationState Authorization {
2121
get { return (AuthorizationState)HttpContext.Current.Session["Authorization"]; }
@@ -44,7 +44,7 @@ where item.Selected
4444

4545
var client = CreateClient();
4646
string clientState;
47-
var response = client.PrepareRequestUserAuthorization(TokenManager.NewAuthorization(scope, out clientState));
47+
var response = client.PrepareRequestUserAuthorization(tokenManager.NewAuthorization(scope, out clientState));
4848
response.ClientState = clientState;
4949
client.Channel.Send(response);
5050
}
@@ -75,9 +75,24 @@ protected void getFavoriteSites_Click(object sender, EventArgs e) {
7575
}
7676
}
7777

78+
private static WebServerClient CreateClient() {
79+
var authServerDescription = new AuthorizationServerDescription {
80+
TokenEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/token"),
81+
AuthorizationEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/auth"),
82+
};
83+
84+
var client = new WebServerClient(authServerDescription) {
85+
ClientIdentifier = "sampleconsumer",
86+
ClientSecret = "samplesecret",
87+
TokenManager = tokenManager,
88+
};
89+
90+
return client;
91+
}
92+
7893
private T CallService<T>(Func<DataApiClient, T> predicate) {
7994
DataApiClient client = new DataApiClient();
80-
//var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest);
95+
////var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest);
8196
if (Authorization == null) {
8297
throw new InvalidOperationException("No access token!");
8398
}
@@ -93,18 +108,5 @@ private T CallService<T>(Func<DataApiClient, T> predicate) {
93108
return predicate(client);
94109
}
95110
}
96-
97-
private static WebServerClient CreateClient() {
98-
var authServerDescription = new AuthorizationServerDescription {
99-
TokenEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/token"),
100-
AuthorizationEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/auth"),
101-
};
102-
var client = new WebServerClient(authServerDescription) {
103-
ClientIdentifier = "sampleconsumer",
104-
ClientSecret = "samplesecret",
105-
TokenManager = TokenManager,
106-
};
107-
return client;
108-
}
109111
}
110112
}

samples/OAuthConsumer/SignInWithTwitter.aspx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected void Page_Load(object sender, EventArgs e) {
3333
}
3434

3535
protected void signInButton_Click(object sender, ImageClickEventArgs e) {
36-
TwitterConsumer.StartSignInWithTwitter(forceLoginCheckbox.Checked).Send();
36+
TwitterConsumer.StartSignInWithTwitter(this.forceLoginCheckbox.Checked).Send();
3737
}
3838
}
3939
}
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Windows;
6-
using System.Windows.Controls;
7-
using System.Windows.Data;
8-
using System.Windows.Documents;
9-
using System.Windows.Input;
10-
using System.Windows.Media;
11-
using System.Windows.Media.Imaging;
12-
using System.Windows.Shapes;
13-
using DotNetOpenAuth.OAuthWrap;
14-
using System.Diagnostics.Contracts;
15-
using System.Windows.Navigation;
16-
17-
namespace DotNetOpenAuth.Samples.OAuthConsumerWpf {
1+
namespace DotNetOpenAuth.Samples.OAuthConsumerWpf {
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics.Contracts;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
using System.Windows.Documents;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Shapes;
16+
using DotNetOpenAuth.OAuthWrap;
17+
1818
/// <summary>
1919
/// Interaction logic for Authorize2.xaml
2020
/// </summary>
@@ -34,7 +34,7 @@ internal Authorize2(UserAgentClient client) {
3434
public IAuthorizationState Authorization { get; set; }
3535

3636
private void webBrowser_Navigating(object sender, System.Windows.Forms.WebBrowserNavigatingEventArgs e) {
37-
locationChanged(e.Url);
37+
this.locationChanged(e.Url);
3838
}
3939

4040
private void locationChanged(Uri location) {
@@ -46,12 +46,11 @@ private void locationChanged(Uri location) {
4646
}
4747

4848
private void webBrowser_Navigated(object sender, System.Windows.Forms.WebBrowserNavigatedEventArgs e) {
49-
locationChanged(e.Url);
49+
this.locationChanged(e.Url);
5050
}
5151

5252
private void webBrowser_LocationChanged(object sender, EventArgs e) {
53-
locationChanged(webBrowser.Url);
53+
this.locationChanged(webBrowser.Url);
5454
}
55-
5655
}
5756
}

samples/OAuthConsumerWpf/MainWindow.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private void wrapBeginButton_Click(object sender, RoutedEventArgs e) {
224224
var address = new Uri(wrapResourceUrlBox.Text);
225225
address = new Uri(wrapResourceUrlBox.Text + (string.IsNullOrEmpty(address.Query) ? "?" : string.Empty) + "access_token=" + Uri.EscapeDataString(authorizePopup.Authorization.AccessToken));
226226
var request = (HttpWebRequest)WebRequest.Create(address);
227-
227+
228228
// This method tacks on the Authorization header
229229
client.AuthorizeRequest(request, authorizePopup.Authorization);
230230

@@ -240,7 +240,6 @@ private void wrapBeginButton_Click(object sender, RoutedEventArgs e) {
240240
} catch (DotNetOpenAuth.Messaging.ProtocolException ex) {
241241
MessageBox.Show(this, ex.Message);
242242
}
243-
244243
}
245244
}
246245
}

samples/OAuthServiceProvider/Code/Global.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Global : HttpApplication {
2222
/// </summary>
2323
public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOpenAuth.OAuthServiceProvider");
2424

25+
public static WebServerAuthorizationServer AuthorizationServer = new WebServerAuthorizationServer(new OAuth2AuthorizationServer());
26+
2527
/// <summary>
2628
/// Gets the transaction-protected database connection for the current request.
2729
/// </summary>
@@ -58,8 +60,6 @@ public static WebServerRequest PendingOAuth2Authorization
5860
set { HttpContext.Current.Session["authrequest"] = value; }
5961
}
6062

61-
public static WebServerAuthorizationServer AuthorizationServer = new WebServerAuthorizationServer(new OAuth2AuthorizationServer());
62-
6363
private static DataClassesDataContext dataContextSimple {
6464
get {
6565
if (HttpContext.Current != null) {

samples/OAuthServiceProvider/Code/OAuth2AuthorizationServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
using DotNetOpenAuth.OAuthWrap.ChannelElements;
1212

1313
internal class OAuth2AuthorizationServer : IAuthorizationServer {
14-
private static readonly byte[] secret;
14+
internal static readonly RSAParameters AsymmetricKey;
1515

16-
internal static readonly RSAParameters asymmetricKey;
16+
private static readonly byte[] secret;
1717

1818
private readonly INonceStore nonceStore = new DatabaseNonceStore();
1919

@@ -23,7 +23,7 @@ static OAuth2AuthorizationServer() {
2323
secret = new byte[16];
2424
crypto.GetBytes(secret);
2525

26-
asymmetricKey = new RSACryptoServiceProvider().ExportParameters(true);
26+
AsymmetricKey = new RSACryptoServiceProvider().ExportParameters(true);
2727
}
2828

2929
#region Implementation of IAuthorizationServer
@@ -37,7 +37,7 @@ public DotNetOpenAuth.Messaging.Bindings.INonceStore VerificationCodeNonceStore
3737
}
3838

3939
public RSAParameters AccessTokenSigningPrivateKey {
40-
get { return asymmetricKey; }
40+
get { return AsymmetricKey; }
4141
}
4242

4343
public IConsumerDescription GetClient(string clientIdentifier) {

samples/OAuthServiceProvider/Code/OAuthAuthorizationManager.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
using System.ServiceModel;
88
using System.ServiceModel.Channels;
99
using System.ServiceModel.Security;
10-
using DotNetOpenAuth;
1110
using DotNetOpenAuth.OAuth;
12-
using DotNetOpenAuth.OAuthWrap;
1311
using DotNetOpenAuth.OAuth.ChannelElements;
12+
using DotNetOpenAuth.OAuthWrap;
1413

1514
/// <summary>
1615
/// A WCF extension to authenticate incoming messages using OAuth.
@@ -28,7 +27,7 @@ protected override bool CheckAccessCore(OperationContext operationContext) {
2827
Uri requestUri = operationContext.RequestContext.RequestMessage.Properties["OriginalHttpRequestUri"] as Uri;
2928

3029
try {
31-
var principal = VerifyOAuth2(httpDetails, requestUri);
30+
var principal = this.VerifyOAuth2(httpDetails, requestUri);
3231
if (principal != null) {
3332
var policy = new OAuthPrincipalAuthorizationPolicy(principal);
3433
var policies = new List<IAuthorizationPolicy> {
@@ -77,8 +76,8 @@ private OAuthPrincipal VerifyOAuth2(HttpRequestMessageProperty httpDetails, Uri
7776
// we use the same public/private key.
7877
var resourceServer = new ResourceServer(
7978
new StandardAccessTokenAnalyzer(
80-
OAuth2AuthorizationServer.asymmetricKey,
81-
OAuth2AuthorizationServer.asymmetricKey));
79+
OAuth2AuthorizationServer.AsymmetricKey,
80+
OAuth2AuthorizationServer.AsymmetricKey));
8281

8382
string username, scope;
8483
var error = resourceServer.VerifyAccess(new DotNetOpenAuth.Messaging.HttpRequestInfo(httpDetails, requestUri), out username, out scope);

samples/OAuthServiceProvider/Members/Authorize.aspx.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ protected void Page_Load(object sender, EventArgs e) {
2929
} else {
3030
ITokenContainingMessage pendingToken = Global.PendingOAuthAuthorization;
3131
var token = Global.DataContext.OAuthTokens.Single(t => t.Token == pendingToken.Token);
32-
desiredAccessLabel.Text = token.Scope;
33-
consumerLabel.Text = Global.TokenManager.GetConsumerForToken(token.Token).ConsumerKey;
32+
this.desiredAccessLabel.Text = token.Scope;
33+
this.consumerLabel.Text = Global.TokenManager.GetConsumerForToken(token.Token).ConsumerKey;
3434

3535
// Generate an unpredictable secret that goes to the user agent and must come back
3636
// with authorization to guarantee the user interacted with this page rather than
@@ -52,7 +52,7 @@ protected void allowAccessButton_Click(object sender, EventArgs e) {
5252
this.AuthorizationSecret = null; // clear one time use secret
5353
var pending = Global.PendingOAuthAuthorization;
5454
Global.AuthorizePendingRequestToken();
55-
multiView.ActiveViewIndex = 1;
55+
this.multiView.ActiveViewIndex = 1;
5656

5757
ServiceProvider sp = new ServiceProvider(Constants.SelfDescription, Global.TokenManager);
5858
var response = sp.PrepareAuthorizationResponse(pending);

samples/OAuthServiceProvider/Members/Authorize2.aspx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Security.Cryptography;
56
using System.Web;
67
using System.Web.UI;
78
using System.Web.UI.WebControls;
8-
using System.Security.Cryptography;
99
using Code;
1010

1111
public partial class Authorize2 : System.Web.UI.Page {

0 commit comments

Comments
 (0)