コード例 #1
0
        internal TokenProvider(Func <ILog> log, string rootUrl, string username, string password, ISerializer serializer = null, string referer = "", ICryptoProvider cryptoProvider = null, Func <HttpClient> httpClientFunc = null)
        {
            if (string.IsNullOrWhiteSpace(rootUrl))
            {
                throw new ArgumentNullException(nameof(rootUrl), "rootUrl is null.");
            }

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException(nameof(username), "username is null.");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException(nameof(password), "password is null.");
            }

            Serializer = serializer ?? SerializerFactory.Get();

            RootUrl        = rootUrl.AsRootUrl();
            CryptoProvider = cryptoProvider ?? CryptoProviderFactory.Get();
            var httpFunc = httpClientFunc ?? HttpClientFactory.Get;

            _httpClient  = httpFunc();
            TokenRequest = new GenerateToken(username, password)
            {
                Referer = referer
            };
            UserName = username;

            _logger = log() ?? LogProvider.For <TokenProvider>();
            _logger.DebugFormat("Created new token provider for {0}", RootUrl);
        }
コード例 #2
0
 public StaticTokenProvider(string rootURL, string token)
 {
     this.RootUrl   = rootURL.AsRootUrl();
     CryptoProvider = CryptoProviderFactory.Get();
     UserName       = "";
     Serializer     = SerializerFactory.Get();
     this.token     = new Token()
     {
         Value = token
     };
 }