diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-07-26 07:32:50 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-07-26 07:32:50 -0700 |
commit | cb8528f3bace8ffdc11c6b0c5d5a460697fa48c9 (patch) | |
tree | aafa7d1074a06577c95022b5488e00d226dfb115 /src | |
parent | ab2382fcbd345abad15f8fdd709438cbf5547351 (diff) | |
download | DotNetOpenAuth-cb8528f3bace8ffdc11c6b0c5d5a460697fa48c9.zip DotNetOpenAuth-cb8528f3bace8ffdc11c6b0c5d5a460697fa48c9.tar.gz DotNetOpenAuth-cb8528f3bace8ffdc11c6b0c5d5a460697fa48c9.tar.bz2 |
Collapsed the AuthorizationServerBase and AuthorizationServer classes.
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/DotNetOpenAuth.csproj | 1 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs | 63 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OAuth2/AuthorizationServerBase.cs | 83 |
3 files changed, 57 insertions, 90 deletions
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj index f402c95..63325d6 100644 --- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj +++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj @@ -344,7 +344,6 @@ http://opensource.org/licenses/ms-pl.html <Compile Include="Messaging\Reflection\MessageDescriptionCollection.cs" /> <Compile Include="Mvc\OpenIdAjaxOptions.cs" /> <Compile Include="Messaging\StandardMessageFactory.cs" /> - <Compile Include="OAuth2\AuthorizationServerBase.cs" /> <Compile Include="OAuth2\AuthorizationState.cs" /> <Compile Include="OAuth2\ChannelElements\AccessRequestBindingElement.cs" /> <Compile Include="OAuth2\ChannelElements\AccessToken.cs" /> diff --git a/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs b/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs index 5f251e1..9eefb9d 100644 --- a/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs +++ b/src/DotNetOpenAuth/OAuth2/AuthorizationServer.cs @@ -18,17 +18,38 @@ namespace DotNetOpenAuth.OAuth2 { /// <summary> /// Authorization Server supporting the web server flow. /// </summary> - public class AuthorizationServer : AuthorizationServerBase { + public class AuthorizationServer { /// <summary> /// Initializes a new instance of the <see cref="AuthorizationServer"/> class. /// </summary> /// <param name="authorizationServer">The authorization server.</param> - public AuthorizationServer(IAuthorizationServer authorizationServer) - : base(authorizationServer) { + public AuthorizationServer(IAuthorizationServer authorizationServer) { Contract.Requires<ArgumentNullException>(authorizationServer != null, "authorizationServer"); + this.OAuthChannel = new OAuth2AuthorizationServerChannel(authorizationServer); } /// <summary> + /// Gets the channel. + /// </summary> + /// <value>The channel.</value> + public Channel Channel { + get { return this.OAuthChannel; } + } + + /// <summary> + /// Gets the authorization server. + /// </summary> + /// <value>The authorization server.</value> + public IAuthorizationServer AuthorizationServerServices { + get { return this.OAuthChannel.AuthorizationServer; } + } + + /// <summary> + /// Gets the channel. + /// </summary> + internal OAuth2AuthorizationServerChannel OAuthChannel { get; private set; } + + /// <summary> /// Reads in a client's request for the Authorization Server to obtain permission from /// the user to authorize the Client's access of some protected resource(s). /// </summary> @@ -71,7 +92,7 @@ namespace DotNetOpenAuth.OAuth2 { if (request != null) { // This convenience method only encrypts access tokens assuming that this auth server // doubles as the resource server. - RSAParameters resourceServerPublicKey = this.AuthorizationServer.AccessTokenSigningPrivateKey; + RSAParameters resourceServerPublicKey = this.AuthorizationServerServices.AccessTokenSigningPrivateKey; response = this.PrepareAccessTokenResponse(request, resourceServerPublicKey); return true; } @@ -111,7 +132,7 @@ namespace DotNetOpenAuth.OAuth2 { callback = this.GetCallback(authorizationRequest); } - var client = this.AuthorizationServer.GetClientOrThrow(authorizationRequest.ClientIdentifier); + var client = this.AuthorizationServerServices.GetClientOrThrow(authorizationRequest.ClientIdentifier); EndUserAuthorizationSuccessResponseBase response; switch (authorizationRequest.ResponseType) { case EndUserAuthorizationResponseType.AccessToken: @@ -135,6 +156,36 @@ namespace DotNetOpenAuth.OAuth2 { return response; } + /// <summary> + /// Prepares the response to an access token request. + /// </summary> + /// <param name="request">The request for an access token.</param> + /// <param name="accessTokenEncryptingPublicKey">The public key to encrypt the access token to, such that the resource server will be able to decrypt it.</param> + /// <param name="accessTokenLifetime">The access token's lifetime.</param> + /// <param name="includeRefreshToken">If set to <c>true</c>, the response will include a long-lived refresh token.</param> + /// <returns>The response message to send to the client.</returns> + public virtual IDirectResponseProtocolMessage PrepareAccessTokenResponse(AccessTokenRequestBase request, RSAParameters accessTokenEncryptingPublicKey, TimeSpan? accessTokenLifetime = null, bool includeRefreshToken = true) { + Contract.Requires<ArgumentNullException>(request != null, "request"); + + var tokenRequest = (ITokenCarryingRequest)request; + var accessTokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServerServices.AccessTokenSigningPrivateKey, accessTokenEncryptingPublicKey); + var accessToken = new AccessToken(tokenRequest.AuthorizationDescription, accessTokenLifetime); + + var response = new AccessTokenSuccessResponse(request) { + AccessToken = accessTokenFormatter.Serialize(accessToken), + Lifetime = accessToken.Lifetime, + }; + response.Scope.ResetContents(tokenRequest.AuthorizationDescription.Scope); + + if (includeRefreshToken) { + var refreshTokenFormatter = RefreshToken.CreateFormatter(this.AuthorizationServerServices.Secret); + var refreshToken = new RefreshToken(tokenRequest.AuthorizationDescription); + response.RefreshToken = refreshTokenFormatter.Serialize(refreshToken); + } + + return response; + } + protected Uri GetCallback(EndUserAuthorizationRequest authorizationRequest) { Contract.Requires<ArgumentNullException>(authorizationRequest != null, "authorizationRequest"); Contract.Ensures(Contract.Result<Uri>() != null); @@ -144,7 +195,7 @@ namespace DotNetOpenAuth.OAuth2 { return authorizationRequest.Callback; } - var client = this.AuthorizationServer.GetClient(authorizationRequest.ClientIdentifier); + var client = this.AuthorizationServerServices.GetClient(authorizationRequest.ClientIdentifier); if (client.Callback != null) { return client.Callback; } diff --git a/src/DotNetOpenAuth/OAuth2/AuthorizationServerBase.cs b/src/DotNetOpenAuth/OAuth2/AuthorizationServerBase.cs deleted file mode 100644 index 9078326..0000000 --- a/src/DotNetOpenAuth/OAuth2/AuthorizationServerBase.cs +++ /dev/null @@ -1,83 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="AuthorizationServerBase.cs" company="Andrew Arnott"> -// Copyright (c) Andrew Arnott. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.OAuth2 { - using System; - using System.Collections.Generic; - using System.Diagnostics.Contracts; - using System.Linq; - using System.Security.Cryptography; - using System.Text; - using ChannelElements; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.OAuth2.Messages; - using OAuth.ChannelElements; - - /// <summary> - /// A base class for authorization server facade classes. - /// </summary> - public abstract class AuthorizationServerBase { - /// <summary> - /// Initializes a new instance of the <see cref="AuthorizationServerBase"/> class. - /// </summary> - /// <param name="authorizationServer">The authorization server.</param> - protected AuthorizationServerBase(IAuthorizationServer authorizationServer) { - Contract.Requires<ArgumentNullException>(authorizationServer != null, "authorizationServer"); - this.OAuthChannel = new OAuth2AuthorizationServerChannel(authorizationServer); - } - - /// <summary> - /// Gets the channel. - /// </summary> - /// <value>The channel.</value> - public Channel Channel { - get { return this.OAuthChannel; } - } - - /// <summary> - /// Gets the authorization server. - /// </summary> - /// <value>The authorization server.</value> - public IAuthorizationServer AuthorizationServer { - get { return this.OAuthChannel.AuthorizationServer; } - } - - /// <summary> - /// Gets the channel. - /// </summary> - internal OAuth2AuthorizationServerChannel OAuthChannel { get; private set; } - - /// <summary> - /// Prepares the response to an access token request. - /// </summary> - /// <param name="request">The request for an access token.</param> - /// <param name="accessTokenEncryptingPublicKey">The public key to encrypt the access token to, such that the resource server will be able to decrypt it.</param> - /// <param name="accessTokenLifetime">The access token's lifetime.</param> - /// <param name="includeRefreshToken">If set to <c>true</c>, the response will include a long-lived refresh token.</param> - /// <returns>The response message to send to the client.</returns> - public virtual IDirectResponseProtocolMessage PrepareAccessTokenResponse(AccessTokenRequestBase request, RSAParameters accessTokenEncryptingPublicKey, TimeSpan? accessTokenLifetime = null, bool includeRefreshToken = true) { - Contract.Requires<ArgumentNullException>(request != null, "request"); - - var tokenRequest = (ITokenCarryingRequest)request; - var accessTokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServer.AccessTokenSigningPrivateKey, accessTokenEncryptingPublicKey); - var accessToken = new AccessToken(tokenRequest.AuthorizationDescription, accessTokenLifetime); - - var response = new AccessTokenSuccessResponse(request) { - AccessToken = accessTokenFormatter.Serialize(accessToken), - Lifetime = accessToken.Lifetime, - }; - response.Scope.ResetContents(tokenRequest.AuthorizationDescription.Scope); - - if (includeRefreshToken) { - var refreshTokenFormatter = RefreshToken.CreateFormatter(this.AuthorizationServer.Secret); - var refreshToken = new RefreshToken(tokenRequest.AuthorizationDescription); - response.RefreshToken = refreshTokenFormatter.Serialize(refreshToken); - } - - return response; - } - } -} |