/// <summary> /// Authenticates the specified connection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="connection">The connection.</param> /// <returns>Task<T>.</returns> public T AuthenticateSync <T>(RestConnectionString connection) { if (!IsAuthenticated) { AuthenticationContext = PerformAuthenticateSync <T>(connection); IsAuthenticated = true; } return((T)AuthenticationContext); }
/// <summary> /// Authenticates the specified connection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="connection">The connection.</param> /// <returns>Task<T>.</returns> public async Task <T> Authenticate <T>(RestConnectionString connection) { if (!IsAuthenticated) { AuthenticationContext = await PerformAuthenticate <T>(connection); IsAuthenticated = true; } return((T)AuthenticationContext); }
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); }
/// <summary> /// Performs the authenticate. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="connection">The connection.</param> /// <returns>Task<T>.</returns> public abstract T PerformAuthenticateSync <T>(RestConnectionString connection);
/// <summary> /// Performs the authenticate. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="connection">The connection.</param> /// <returns>Task<T>.</returns> public abstract Task <T> PerformAuthenticate <T>(RestConnectionString connection);
/// <summary> /// Performs the authenticate. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="connection">The connection.</param> /// <returns>Task<T>.</returns> /// <exception cref="NotSupportedException"></exception> /// <exception cref="System.NotSupportedException"></exception> public override Task <T> PerformAuthenticate <T>(RestConnectionString connection) { return(Task.FromResult(PerformAuthenticateSync <T>(connection))); }
/// <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>(); }