//----------------------------------------------------------------------- // // 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; /// /// A request from a rich app Client to an Authorization Server requested /// authorization to access user Protected Data. /// internal class DeviceRequest : MessageBase, IOAuthDirectResponseFormat { /// /// A constant that identifies the type of message coming into the auth server. /// [MessagePart(Protocol.type, IsRequired = true)] private const string MessageType = "device_code"; /// /// Initializes a new instance of the class. /// /// The authorization server. /// The version. internal DeviceRequest(Uri tokenEndpoint, Version version) : base(version, MessageTransport.Direct, tokenEndpoint) { this.HttpMethods = HttpDeliveryMethods.GetRequest; } /// /// Initializes a new instance of the class. /// /// The authorization server. internal DeviceRequest(AuthorizationServerDescription authorizationServer) : this(authorizationServer.TokenEndpoint, authorizationServer.Version) { Contract.Requires(authorizationServer != null); Contract.Requires(authorizationServer.Version != null); Contract.Requires(authorizationServer.TokenEndpoint != null); // We prefer URL encoding of the data. this.Format = ResponseFormat.Form; } /// /// Gets the format the client is requesting the authorization server should deliver the request in. /// /// The format. ResponseFormat IOAuthDirectResponseFormat.Format { get { return this.Format.HasValue ? this.Format.Value : ResponseFormat.Json; } } /// /// Gets or sets the client identifier previously obtained from the Authorization Server. /// /// The client identifier. [MessagePart(Protocol.client_id, IsRequired = true, AllowEmpty = false)] internal string ClientIdentifier { get; set; } /// /// Gets or sets the scope. /// /// The Authorization Server MAY define authorization scope values for the Client to include. [MessagePart(Protocol.scope, IsRequired = false, AllowEmpty = true)] internal string Scope { get; set; } /// /// Gets or sets the format the client is requesting the authorization server should deliver the request in. /// /// The format. [MessagePart(Protocol.format, Encoder = typeof(ResponseFormatEncoder))] private ResponseFormat? Format { get; set; } } }