コード例 #1
0
        /// <summary>
        /// Authenticates the specified connection.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection">The connection.</param>
        /// <returns>Task&lt;T&gt;.</returns>
        public T AuthenticateSync <T>(RestConnectionString connection)
        {
            if (!IsAuthenticated)
            {
                AuthenticationContext = PerformAuthenticateSync <T>(connection);
                IsAuthenticated       = true;
            }

            return((T)AuthenticationContext);
        }
コード例 #2
0
        /// <summary>
        /// Authenticates the specified connection.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection">The connection.</param>
        /// <returns>Task&lt;T&gt;.</returns>
        public async Task <T> Authenticate <T>(RestConnectionString connection)
        {
            if (!IsAuthenticated)
            {
                AuthenticationContext = await PerformAuthenticate <T>(connection);

                IsAuthenticated = true;
            }

            return((T)AuthenticationContext);
        }
コード例 #3
0
        public override T PerformAuthenticateSync <T>(RestConnectionString connection)
        {
            // HACK: there has to be a better way to do this that allows callers (e.g. RestSharpClient) to be able to rely on T at compile time
            if (!string.IsNullOrWhiteSpace(connection.ClientSecret))
            {
                var authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(connection.ClientSecret);
                return((T)(object)authenticator);
            }

            if (!string.IsNullOrWhiteSpace(connection.CertificateThumbprint))
            {
                //TODO: add support for more auth types, e.g. OAuth2 JWT
                throw new NotSupportedException();
            }

            // anonymous authentication
            return((T)(object)null);
        }
コード例 #4
0
        /// <summary>
        /// Performs the authenticate.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection">The connection.</param>
        /// <returns>Task&lt;T&gt;.</returns>

        public abstract T PerformAuthenticateSync <T>(RestConnectionString connection);
コード例 #5
0
 /// <summary>
 /// Performs the authenticate.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="connection">The connection.</param>
 /// <returns>Task&lt;T&gt;.</returns>
 public abstract Task <T> PerformAuthenticate <T>(RestConnectionString connection);
コード例 #6
0
 /// <summary>
 /// Performs the authenticate.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="connection">The connection.</param>
 /// <returns>Task&lt;T&gt;.</returns>
 /// <exception cref="NotSupportedException"></exception>
 /// <exception cref="System.NotSupportedException"></exception>
 public override Task <T> PerformAuthenticate <T>(RestConnectionString connection)
 {
     return(Task.FromResult(PerformAuthenticateSync <T>(connection)));
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RestConnection"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="authProvider">The authentication provider.</param>
 public RestConnection(string connection, IRestAuthenticationProvider authProvider)
 {
     _authProvider     = authProvider;
     _connectionString = connection.FromJson <RestConnectionString>();
 }