//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OAuth2 { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; /// /// An interface that resource server hosts should implement if they accept access tokens /// issued by non-DotNetOpenAuth authorization servers. /// [ContractClass((typeof(IAccessTokenAnalyzerContract)))] public interface IAccessTokenAnalyzer { /// /// Reads an access token to find out what data it authorizes access to. /// /// The message carrying the access token. /// The access token. /// The user whose data is accessible with this access token. /// The scope of access authorized by this access token. /// A value indicating whether this access token is valid. [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#", Justification = "Try pattern")] [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "2#", Justification = "Try pattern")] bool TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet scope); } /// /// Code contract for the interface. /// [ContractClassFor(typeof(IAccessTokenAnalyzer))] internal abstract class IAccessTokenAnalyzerContract : IAccessTokenAnalyzer { /// /// Prevents a default instance of the class from being created. /// private IAccessTokenAnalyzerContract() { } /// /// Reads an access token to find out what data it authorizes access to. /// /// The message carrying the access token. /// The access token. /// The user whose data is accessible with this access token. /// The scope of access authorized by this access token. /// /// A value indicating whether this access token is valid. /// bool IAccessTokenAnalyzer.TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet scope) { Requires.NotNull(message, "message"); Requires.NotNullOrEmpty(accessToken, "accessToken"); Contract.Ensures(Contract.Result() == (Contract.ValueAtReturn(out user) != null)); throw new NotImplementedException(); } } }