summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth/Consumer.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-09-30 07:42:12 -0700
committerAndrew <andrewarnott@gmail.com>2008-10-02 07:33:57 -0700
commit08a2ca3fdbe337ba11575cf7893ab547536bb4e2 (patch)
tree450764d5a45091de0683d3f164a7efaa6164b22d /src/DotNetOAuth/Consumer.cs
parent5cbd5d7edb994f874b265ed2e7c43f0bcd27b6ac (diff)
downloadDotNetOpenAuth-08a2ca3fdbe337ba11575cf7893ab547536bb4e2.zip
DotNetOpenAuth-08a2ca3fdbe337ba11575cf7893ab547536bb4e2.tar.gz
DotNetOpenAuth-08a2ca3fdbe337ba11575cf7893ab547536bb4e2.tar.bz2
Split up the two OAuth message type providers into Consumer and Service Provider classes so they could actually work correctly..
Added Try methods to read messages that might not be there without throwing exceptions.
Diffstat (limited to 'src/DotNetOAuth/Consumer.cs')
-rw-r--r--src/DotNetOAuth/Consumer.cs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/DotNetOAuth/Consumer.cs b/src/DotNetOAuth/Consumer.cs
index bc50d1f..3be3f6c 100644
--- a/src/DotNetOAuth/Consumer.cs
+++ b/src/DotNetOAuth/Consumer.cs
@@ -33,7 +33,7 @@ namespace DotNetOAuth {
this.WebRequestHandler = new StandardWebRequestHandler();
ITamperProtectionChannelBindingElement signingElement = serviceDescription.CreateTamperProtectionElement();
INonceStore store = new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge);
- this.Channel = new OAuthChannel(signingElement, store, new OAuthMessageTypeProvider(tokenManager), this.WebRequestHandler);
+ this.Channel = new OAuthChannel(signingElement, store, new OAuthConsumerMessageTypeProvider(tokenManager), this.WebRequestHandler);
this.ServiceProvider = serviceDescription;
this.TokenManager = tokenManager;
}
@@ -103,21 +103,24 @@ namespace DotNetOAuth {
/// <summary>
/// Processes an incoming authorization-granted message from an SP and obtains an access token.
/// </summary>
- /// <returns>The access token.</returns>
+ /// <returns>The access token, or null if no incoming authorization message was recognized.</returns>
public string ProcessUserAuthorization() {
- var authorizationMessage = this.Channel.ReadFromRequest<DirectUserToConsumerMessage>();
-
- // Exchange request token for access token.
- string requestTokenSecret = this.TokenManager.GetTokenSecret(authorizationMessage.RequestToken);
- var requestAccess = new RequestAccessTokenMessage(this.ServiceProvider.AccessTokenEndpoint) {
- RequestToken = authorizationMessage.RequestToken,
- TokenSecret = requestTokenSecret,
- ConsumerKey = this.ConsumerKey,
- ConsumerSecret = this.ConsumerSecret,
- };
- var grantAccess = this.Channel.Request<GrantAccessTokenMessage>(requestAccess);
- this.TokenManager.ExpireRequestTokenAndStoreNewAccessToken(this.ConsumerKey, authorizationMessage.RequestToken, grantAccess.AccessToken, grantAccess.TokenSecret);
- return grantAccess.AccessToken;
+ DirectUserToConsumerMessage authorizationMessage;
+ if (this.Channel.TryReadFromRequest<DirectUserToConsumerMessage>(out authorizationMessage)) {
+ // Exchange request token for access token.
+ string requestTokenSecret = this.TokenManager.GetTokenSecret(authorizationMessage.RequestToken);
+ var requestAccess = new RequestAccessTokenMessage(this.ServiceProvider.AccessTokenEndpoint) {
+ RequestToken = authorizationMessage.RequestToken,
+ TokenSecret = requestTokenSecret,
+ ConsumerKey = this.ConsumerKey,
+ ConsumerSecret = this.ConsumerSecret,
+ };
+ var grantAccess = this.Channel.Request<GrantAccessTokenMessage>(requestAccess);
+ this.TokenManager.ExpireRequestTokenAndStoreNewAccessToken(this.ConsumerKey, authorizationMessage.RequestToken, grantAccess.AccessToken, grantAccess.TokenSecret);
+ return grantAccess.AccessToken;
+ } else {
+ return null;
+ }
}
/// <summary>