diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-02-21 10:21:10 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-02-21 10:21:10 -0800 |
commit | 4fc95a91caf2caa216a5080f151e24ad1d6fcba4 (patch) | |
tree | 2024ba45599cb8ef9b92d8e652d6dae4f7057e92 /src/DotNetOpenAuth.OAuth2.Client/OAuth2 | |
parent | d7c4c22f7a35d884c0f0c1f8fb0b517b7f68f54b (diff) | |
download | DotNetOpenAuth-4fc95a91caf2caa216a5080f151e24ad1d6fcba4.zip DotNetOpenAuth-4fc95a91caf2caa216a5080f151e24ad1d6fcba4.tar.gz DotNetOpenAuth-4fc95a91caf2caa216a5080f151e24ad1d6fcba4.tar.bz2 |
Added two more OAuth2 unit tests, for the UserAgentClient class.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.Client/OAuth2')
-rw-r--r-- | src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs index ded0e97..d2ede6f 100644 --- a/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs +++ b/src/DotNetOpenAuth.OAuth2.Client/OAuth2/UserAgentClient.cs @@ -72,17 +72,7 @@ namespace DotNetOpenAuth.OAuth2 { Requires.NotNull(authorization, "authorization"); Requires.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier)); - if (authorization.Callback == null) { - authorization.Callback = new Uri("http://localhost/"); - } - - var request = new EndUserAuthorizationRequest(this.AuthorizationServer) { - ClientIdentifier = this.ClientIdentifier, - Callback = authorization.Callback, - ClientState = state, - }; - request.Scope.ResetContents(authorization.Scope); - + var request = this.PrepareRequestUserAuthorization(authorization, state); return this.Channel.PrepareResponse(request).GetDirectUriRequest(this.Channel); } @@ -105,6 +95,21 @@ namespace DotNetOpenAuth.OAuth2 { return null; } + return this.ProcessUserAuthorization(authorizationState, response); + } + + /// <summary> + /// Scans the incoming request for an authorization response message. + /// </summary> + /// <param name="authorizationState">The authorization.</param> + /// <param name="response">The incoming authorization response message.</param> + /// <returns> + /// The granted authorization, or <c>null</c> if the incoming HTTP request did not contain an authorization server response or authorization was rejected. + /// </returns> + internal IAuthorizationState ProcessUserAuthorization(IAuthorizationState authorizationState, IDirectedProtocolMessage response) { + Requires.NotNull(authorizationState, "authorizationState"); + Requires.NotNull(response, "response"); + EndUserAuthorizationSuccessAccessTokenResponse accessTokenSuccess; EndUserAuthorizationSuccessAuthCodeResponse authCodeSuccess; EndUserAuthorizationFailedResponse failure; @@ -119,5 +124,32 @@ namespace DotNetOpenAuth.OAuth2 { return authorizationState; } + + /// <summary> + /// Generates a URL that the user's browser can be directed to in order to authorize + /// this client to access protected data at some resource server. + /// </summary> + /// <param name="authorization">The authorization state that is tracking this particular request. Optional.</param> + /// <param name="state">The client state that should be returned with the authorization response.</param> + /// <returns> + /// A message to send to the authorization server. + /// </returns> + internal EndUserAuthorizationRequest PrepareRequestUserAuthorization(IAuthorizationState authorization, string state = null) { + Requires.NotNull(authorization, "authorization"); + Requires.ValidState(!string.IsNullOrEmpty(this.ClientIdentifier)); + + if (authorization.Callback == null) { + authorization.Callback = new Uri("http://localhost/"); + } + + var request = new EndUserAuthorizationRequest(this.AuthorizationServer) { + ClientIdentifier = this.ClientIdentifier, + Callback = authorization.Callback, + ClientState = state, + }; + request.Scope.ResetContents(authorization.Scope); + + return request; + } } } |