diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-03-31 18:25:42 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-03-31 18:25:42 -0700 |
commit | 6ac3e08b63bbade07f687477a01ae8fc39f81f77 (patch) | |
tree | f55ae4ecebbed5de7b137f149931886b6855fc6f | |
parent | efddcdeeea5f5793760291e39fa80183c4450194 (diff) | |
download | DotNetOpenAuth-6ac3e08b63bbade07f687477a01ae8fc39f81f77.zip DotNetOpenAuth-6ac3e08b63bbade07f687477a01ae8fc39f81f77.tar.gz DotNetOpenAuth-6ac3e08b63bbade07f687477a01ae8fc39f81f77.tar.bz2 |
Removed another auth server binding element.
4 files changed, 29 insertions, 102 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/DotNetOpenAuth.OAuth2.AuthorizationServer.csproj b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/DotNetOpenAuth.OAuth2.AuthorizationServer.csproj index 9498295..c1f3124 100644 --- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/DotNetOpenAuth.OAuth2.AuthorizationServer.csproj +++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/DotNetOpenAuth.OAuth2.AuthorizationServer.csproj @@ -26,7 +26,6 @@ </Compile> <Compile Include="OAuth2\AuthServerUtilities.cs" /> <Compile Include="OAuth2\ChannelElements\TokenCodeSerializationBindingElement.cs" /> - <Compile Include="OAuth2\ChannelElements\AccessTokenBindingElement.cs" /> <Compile Include="OAuth2\ChannelElements\AuthorizationCode.cs" /> <Compile Include="OAuth2\ChannelElements\MessageValidationBindingElement.cs" /> <Compile Include="OAuth2\ChannelElements\AuthServerBindingElementBase.cs" /> diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs index 88145d2..7770163 100644 --- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs +++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/AuthorizationServer.cs @@ -110,8 +110,21 @@ namespace DotNetOpenAuth.OAuth2 { IProtocolMessage responseMessage; try { if (this.Channel.TryReadFromRequest(request, out requestMessage)) { + IAccessTokenRequestInternal accessRequestInternal = requestMessage; + accessRequestInternal.AccessTokenCreationParameters = this.AuthorizationServerServices.GetAccessTokenParameters(requestMessage); + ErrorUtilities.VerifyHost(accessRequestInternal.AccessTokenCreationParameters != null, "IAuthorizationServer.GetAccessTokenParameters must not return null."); + // TODO: refreshToken should be set appropriately based on authorization server policy. - responseMessage = this.PrepareAccessTokenResponse(requestMessage); + var successResponseMessage = this.PrepareAccessTokenResponse(requestMessage); + successResponseMessage.Lifetime = accessRequestInternal.AccessTokenCreationParameters.AccessTokenLifetime; + + var authCarryingRequest = requestMessage as IAuthorizationCarryingRequest; + if (authCarryingRequest != null) { + IAccessTokenIssuingResponse accessTokenIssuingResponse = successResponseMessage; + accessTokenIssuingResponse.AuthorizationDescription = new AccessToken(authCarryingRequest.AuthorizationDescription, successResponseMessage.Lifetime); + } + + responseMessage = successResponseMessage; } else { responseMessage = new AccessTokenFailedResponse() { Error = Protocol.AccessTokenRequestErrorCodes.InvalidRequest, }; } @@ -165,13 +178,23 @@ namespace DotNetOpenAuth.OAuth2 { EndUserAuthorizationSuccessResponseBase response; switch (authorizationRequest.ResponseType) { case EndUserAuthorizationResponseType.AccessToken: - var accessTokenResponse = new EndUserAuthorizationSuccessAccessTokenResponse(callback, authorizationRequest); - response = accessTokenResponse; + IAccessTokenRequestInternal accessRequestInternal = (EndUserAuthorizationImplicitRequest)authorizationRequest; + accessRequestInternal.AccessTokenCreationParameters = this.AuthorizationServerServices.GetAccessTokenParameters(accessRequestInternal); + + var implicitGrantResponse = new EndUserAuthorizationSuccessAccessTokenResponse(callback, authorizationRequest); + IAccessTokenCarryingRequest tokenCarryingResponse = implicitGrantResponse; + tokenCarryingResponse.AuthorizationDescription = new AccessToken( + authorizationRequest.ClientIdentifier, + implicitGrantResponse.Scope, + implicitGrantResponse.AuthorizingUsername, + implicitGrantResponse.Lifetime); + + response = implicitGrantResponse; break; case EndUserAuthorizationResponseType.AuthorizationCode: var authCodeResponse = new EndUserAuthorizationSuccessAuthCodeResponseAS(callback, authorizationRequest); - IAuthorizationCodeCarryingRequest tokenCarryingResponse = authCodeResponse; - tokenCarryingResponse.AuthorizationDescription = new AuthorizationCode( + IAuthorizationCodeCarryingRequest codeCarryingResponse = authCodeResponse; + codeCarryingResponse.AuthorizationDescription = new AuthorizationCode( authorizationRequest.ClientIdentifier, authorizationRequest.Callback, authCodeResponse.Scope, @@ -224,7 +247,7 @@ namespace DotNetOpenAuth.OAuth2 { /// <param name="request">The request for an access token.</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> - private IDirectResponseProtocolMessage PrepareAccessTokenResponse(AccessTokenRequestBase request, bool includeRefreshToken = true) { + private AccessTokenSuccessResponse PrepareAccessTokenResponse(AccessTokenRequestBase request, bool includeRefreshToken = true) { Requires.NotNull(request, "request"); if (includeRefreshToken) { diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AccessTokenBindingElement.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AccessTokenBindingElement.cs deleted file mode 100644 index 9d7e8f2..0000000 --- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/AccessTokenBindingElement.cs +++ /dev/null @@ -1,94 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="AccessTokenBindingElement.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.OAuth2.ChannelElements { - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Linq; - using System.Security.Cryptography; - using System.Text; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.OAuth2.Messages; - - /// <summary> - /// Serializes access tokens inside an outgoing message. - /// </summary> - internal class AccessTokenBindingElement : AuthServerBindingElementBase { - /// <summary> - /// Initializes a new instance of the <see cref="AccessTokenBindingElement"/> class. - /// </summary> - internal AccessTokenBindingElement() { - } - - /// <summary> - /// Gets the protection commonly offered (if any) by this binding element. - /// </summary> - /// <value>Always <c>MessageProtections.None</c></value> - /// <remarks> - /// This value is used to assist in sorting binding elements in the channel stack. - /// </remarks> - public override MessageProtections Protection { - get { return MessageProtections.None; } - } - - /// <summary> - /// Prepares a message for sending based on the rules of this channel binding element. - /// </summary> - /// <param name="message">The message to prepare for sending.</param> - /// <returns> - /// The protections (if any) that this binding element applied to the message. - /// Null if this binding element did not even apply to this binding element. - /// </returns> - public override MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) { - var directResponse = message as IDirectResponseProtocolMessage; - var request = directResponse != null ? directResponse.OriginatingRequest as IAccessTokenRequestInternal : null; - var authCarryingRequest = request as IAuthorizationCarryingRequest; - var accessTokenResponse = message as IAccessTokenIssuingResponse; - var implicitGrantResponse = message as EndUserAuthorizationSuccessAccessTokenResponse; - - if (request != null) { - request.AccessTokenCreationParameters = this.AuthorizationServer.GetAccessTokenParameters(request); - ErrorUtilities.VerifyHost(request.AccessTokenCreationParameters != null, "IAuthorizationServer.GetAccessTokenParameters must not return null."); - - if (accessTokenResponse != null) { - accessTokenResponse.Lifetime = request.AccessTokenCreationParameters.AccessTokenLifetime; - } - } - - if (authCarryingRequest != null) { - ErrorUtilities.VerifyInternal(request != null, MessagingStrings.UnexpectedMessageReceived, typeof(IAccessTokenRequestInternal), request.GetType()); - accessTokenResponse.AuthorizationDescription = new AccessToken(authCarryingRequest.AuthorizationDescription, accessTokenResponse.Lifetime); - } else if (implicitGrantResponse != null) { - IAccessTokenCarryingRequest tokenCarryingResponse = implicitGrantResponse; - accessTokenResponse.AuthorizationDescription = new AccessToken( - request.ClientIdentifier, - implicitGrantResponse.Scope, - implicitGrantResponse.AuthorizingUsername, - implicitGrantResponse.Lifetime); - } - - return null; - } - - /// <summary> - /// Performs any transformation on an incoming message that may be necessary and/or - /// validates an incoming message based on the rules of this channel binding element. - /// </summary> - /// <param name="message">The incoming message to process.</param> - /// <returns> - /// The protections (if any) that this binding element applied to the message. - /// Null if this binding element did not even apply to this binding element. - /// </returns> - /// <exception cref="ProtocolException"> - /// Thrown when the binding element rules indicate that this message is invalid and should - /// NOT be processed. - /// </exception> - public override MessageProtections? ProcessIncomingMessage(IProtocolMessage message) { - return null; - } - } -} diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs index 09d35ee..00c34eb 100644 --- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs +++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs @@ -115,7 +115,6 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements { // The order they are provided is used for outgoing messgaes, and reversed for incoming messages. bindingElements.Add(new MessageValidationBindingElement()); - bindingElements.Add(new AccessTokenBindingElement()); bindingElements.Add(new TokenCodeSerializationBindingElement()); return bindingElements.ToArray(); |