//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; using Validation; /// /// A description of some OpenID Relying Party endpoint. /// /// /// This is an immutable type. /// internal class RelyingPartyEndpointDescription { /// /// Initializes a new instance of the class. /// /// The return to. /// /// The Type URIs of supported services advertised on a relying party's XRDS document. /// internal RelyingPartyEndpointDescription(Uri returnTo, string[] supportedServiceTypeUris) { Requires.NotNull(returnTo, "returnTo"); Requires.NotNull(supportedServiceTypeUris, "supportedServiceTypeUris"); this.ReturnToEndpoint = returnTo; this.Protocol = GetProtocolFromServices(supportedServiceTypeUris); } /// /// Gets the URL to the login page on the discovered relying party web site. /// public Uri ReturnToEndpoint { get; private set; } /// /// Gets the OpenId protocol that the discovered relying party supports. /// public Protocol Protocol { get; private set; } /// /// Derives the highest OpenID protocol that this library and the OpenID Provider have /// in common. /// /// The supported service type URIs. /// The best OpenID protocol version to use when communicating with this Provider. [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "OpenID", Justification = "Spelling correct")] private static Protocol GetProtocolFromServices(string[] supportedServiceTypeUris) { Protocol protocol = Protocol.FindBestVersion(p => p.RPReturnToTypeURI, supportedServiceTypeUris); if (protocol == null) { throw new InvalidOperationException("Unable to determine the version of OpenID the Relying Party supports."); } return protocol; } } }