Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JWTAuthConfig" /> class.
        /// </summary>
        /// <param name="jwtSecurityToken">The JWT security token.</param>
        /// <exception cref="System.Exception">No certificates were found for the specified subject</exception>
        public JWTAuthConfig(JwtSecurityToken jwtSecurityToken)
        {
            JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();

            _client = new CloudAgentsHttpClient();
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", handler.WriteToken(jwtSecurityToken));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Refreshes the client. This method runs when the configuration is created from a certificate. If so,
        /// the client header must be refreshed anytime the token expires.
        /// </summary>
        private void RefreshClient()
        {
            var token = Utils.BuildDefaultToken(_x509Certificate2);

            _tokenExpiration = token.ValidTo;

            JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();

            _client = new CloudAgentsHttpClient();
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", handler.WriteToken(token));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicAuthConfig"/> class.
        /// </summary>
        /// <param name="username">The basic username.</param>
        /// <param name="password">The basic password.</param>
        public BasicAuthConfig(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("Invalid credentials");
            }

            var authenticationHeaderBytes = Encoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password));

            _client = new CloudAgentsHttpClient();
            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authenticationHeaderBytes));
        }
Exemplo n.º 4
0
        private CertAuthConfig(X509Certificate2 certificate)
        {
            if (certificate == null)
            {
                throw new ArgumentException("invalid certificate", "certificate");
            }
#if NET452
            _handler = new WebRequestHandler();
#else
            _handler = new HttpClientHandler();
#endif


            _handler.ClientCertificates.Add(certificate);
            _client = new CloudAgentsHttpClient(_handler);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JWTAuthConfig"/> class.
 /// </summary>
 /// <param name="encodedTokenString">The encoded token string.</param>
 public JWTAuthConfig(string encodedTokenString)
 {
     _client = new CloudAgentsHttpClient();
     _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", encodedTokenString);
 }