//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OAuth2.Messages { using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth2.ChannelElements; /// /// The message sent by the Authorization Server to the Client via the user agent /// to indicate that user authorization was granted, carrying only an access token, /// and to return the user to the Client where they started their experience. /// internal class EndUserAuthorizationSuccessAccessTokenResponse : EndUserAuthorizationSuccessResponseBase, IAuthorizationCarryingRequest, IHttpIndirectResponse { /// /// Initializes a new instance of the class. /// /// The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server. /// The protocol version. internal EndUserAuthorizationSuccessAccessTokenResponse(Uri clientCallback, Version version) : base(clientCallback, version) { Contract.Requires(version != null); Contract.Requires(clientCallback != null); this.TokenType = Protocol.AccessTokenTypes.Bearer; } /// /// Initializes a new instance of the class. /// /// The URL to redirect to so the client receives the message. This may not be built into the request message if the client pre-registered the URL with the authorization server. /// The authorization request from the user agent on behalf of the client. internal EndUserAuthorizationSuccessAccessTokenResponse(Uri clientCallback, EndUserAuthorizationRequest request) : base(clientCallback, request) { Contract.Requires(clientCallback != null); Contract.Requires(request != null); ((IMessageWithClientState)this).ClientState = request.ClientState; this.TokenType = Protocol.AccessTokenTypes.Bearer; } #region IAuthorizationCarryingRequest Members /// /// Gets or sets the verification code or refresh/access token. /// /// The code or token. string IAuthorizationCarryingRequest.CodeOrToken { get { return this.AccessToken; } set { this.AccessToken = value; } } /// /// Gets the type of the code or token. /// /// The type of the code or token. CodeOrTokenType IAuthorizationCarryingRequest.CodeOrTokenType { get { return CodeOrTokenType.AccessToken; } } /// /// Gets or sets the authorization that the token describes. /// /// IAuthorizationDescription IAuthorizationCarryingRequest.AuthorizationDescription { get; set; } #endregion #region IHttpIndirectResponse Members /// /// Gets a value indicating whether the payload for the message should be included /// in the redirect fragment instead of the query string or POST entity. /// bool IHttpIndirectResponse.Include301RedirectPayloadInFragment { get { return true; } } #endregion /// /// Gets or sets the token type. /// /// Usually "bearer". /// /// Described in OAuth 2.0 section 7.1. /// [MessagePart(Protocol.token_type, IsRequired = true)] public string TokenType { get; internal set; } /// /// Gets or sets the access token. /// /// The access token. [MessagePart(Protocol.access_token, IsRequired = true)] public string AccessToken { get; set; } /// /// Gets or sets the scope of the if one is given; otherwise the scope of the authorization code. /// /// The scope. [MessagePart(Protocol.scope, IsRequired = false, Encoder = typeof(ScopeEncoder))] public new ICollection Scope { get { return base.Scope; } protected set { base.Scope = value; } } /// /// Gets or sets the lifetime of the authorization. /// /// The lifetime. [MessagePart(Protocol.expires_in, IsRequired = false, Encoder = typeof(TimespanSecondsEncoder))] internal TimeSpan? Lifetime { get; set; } } }