//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; using System.Linq; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; using DotNetOpenAuth.OpenId.RelyingParty; using Validation; /// /// Describes some OpenID Provider endpoint and its capabilities. /// /// /// This is an immutable type. /// [Serializable] internal sealed class ProviderEndpointDescription : IProviderEndpoint { /// /// Initializes a new instance of the class. /// /// The OpenID Provider endpoint URL. /// The OpenID version supported by this particular endpoint. internal ProviderEndpointDescription(Uri providerEndpoint, Version openIdVersion) { Requires.NotNull(providerEndpoint, "providerEndpoint"); Requires.NotNull(openIdVersion, "openIdVersion"); this.Uri = providerEndpoint; this.Version = openIdVersion; this.Capabilities = new ReadOnlyCollection(EmptyList.Instance); } /// /// Initializes a new instance of the class. /// /// The URI the provider listens on for OpenID requests. /// The set of services offered by this endpoint. internal ProviderEndpointDescription(Uri providerEndpoint, IEnumerable serviceTypeURIs) { Requires.NotNull(providerEndpoint, "providerEndpoint"); Requires.NotNull(serviceTypeURIs, "serviceTypeURIs"); this.Uri = providerEndpoint; this.Capabilities = new ReadOnlyCollection(serviceTypeURIs.ToList()); Protocol opIdentifierProtocol = Protocol.FindBestVersion(p => p.OPIdentifierServiceTypeURI, serviceTypeURIs); Protocol claimedIdentifierProviderVersion = Protocol.FindBestVersion(p => p.ClaimedIdentifierServiceTypeURI, serviceTypeURIs); if (opIdentifierProtocol != null) { this.Version = opIdentifierProtocol.Version; } else if (claimedIdentifierProviderVersion != null) { this.Version = claimedIdentifierProviderVersion.Version; } else { ErrorUtilities.ThrowProtocol(OpenIdStrings.ProviderVersionUnrecognized, this.Uri); } } /// /// Gets the URL that the OpenID Provider listens for incoming OpenID messages on. /// public Uri Uri { get; private set; } /// /// Gets the OpenID protocol version this endpoint supports. /// /// /// If an endpoint supports multiple versions, each version must be represented /// by its own object. /// public Version Version { get; private set; } /// /// Gets the collection of service type URIs found in the XRDS document describing this Provider. /// internal ReadOnlyCollection Capabilities { get; private set; } #region IProviderEndpoint Members /// /// Checks whether the OpenId Identifier claims support for a given extension. /// /// The extension whose support is being queried. /// /// True if support for the extension is advertised. False otherwise. /// /// /// Note that a true or false return value is no guarantee of a Provider's /// support for or lack of support for an extension. The return value is /// determined by how the authenticating user filled out his/her XRDS document only. /// The only way to be sure of support for a given extension is to include /// the extension in the request and see if a response comes back for that extension. /// bool IProviderEndpoint.IsExtensionSupported() { throw new NotImplementedException(); } /// /// Checks whether the OpenId Identifier claims support for a given extension. /// /// The extension whose support is being queried. /// /// True if support for the extension is advertised. False otherwise. /// /// /// Note that a true or false return value is no guarantee of a Provider's /// support for or lack of support for an extension. The return value is /// determined by how the authenticating user filled out his/her XRDS document only. /// The only way to be sure of support for a given extension is to include /// the extension in the request and see if a response comes back for that extension. /// bool IProviderEndpoint.IsExtensionSupported(Type extensionType) { throw new NotImplementedException(); } #endregion #if CONTRACTS_FULL /// /// Verifies conditions that should be true for any valid state of this object. /// [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Called by code contracts.")] [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Called by code contracts.")] [ContractInvariantMethod] private void ObjectInvariant() { Contract.Invariant(this.Capabilities != null); } #endif } }