예제 #1
0
        private void Authenticate()
        {
            var response = _httpClient
                           .Post("Authentication/AuthenticateUser", JsonConvert.SerializeObject(_credentials));

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new AuthenticationException("Invalid RSign API user name or password");
            }

            IsAuthenticated = true;

            var authenticationResponse = JsonConvert
                                         .DeserializeObject <AuthenticationResponse>(response.Content.ReadAsStringAsync().Result);

            _httpClient.SetAuthenticationToken(authenticationResponse.AuthToken);

            _envelopeTypes = new HashSet <EnvelopeType>(GetEnvelopeTypes());

            _dateFormat = GetDateFormats()
                          .Single(x => _options.DateFormat.Equals(x.Description, StringComparison.InvariantCultureIgnoreCase));

            _expiryType = GetExpiryTypes()
                          .Single(x => _options.ExpiryType.Equals(x.Description, StringComparison.InvariantCultureIgnoreCase));
        }
예제 #2
0
        public async Task FinishCodeGrantFlowAsync(string code, ExpiryType expiresIn = ExpiryType.EightHours)
        {
            SetBasicAuthorizationHeader();

            var response = await HttpClient.PostAsync(TokenBaseUrl, new FormUrlEncodedContent(GetFormContent(code, expiresIn)));

            var responseContent = await response.Content.ReadAsStringAsync();

            var authenticationResponse = JsonConvert.DeserializeObject <AuthenticationResponse>(responseContent);

            //TODO decode
        }
예제 #3
0
        public async Task RefreshTokenAsync(ExpiryType expiresIn = ExpiryType.EightHours)
        {
            SetBasicAuthorizationHeader();

            var content = new FormUrlEncodedContent(new[] {
                new KeyValuePair <string, string>("grant_type", "refresh_token"),
                new KeyValuePair <string, string>("refresh_token", AuthenticationResponse.RefreshToken),
                new KeyValuePair <string, string>("expires_in", Convert.ToString((int)expiresIn))
            });
            var response = await HttpClient.PostAsync(TokenBaseUrl, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            //TODO decode
        }
 private long GetEpochExpiry(DistributedCacheEntryOptions options, out ExpiryType expiryType)
 {
     if (options.SlidingExpiration.HasValue)
     {
         expiryType = ExpiryType.Sliding;
         return(DateTimeOffset.Now.ToUniversalTime().ToUnixTimeSeconds() + (long)options.SlidingExpiration.Value.TotalSeconds);
     }
     else if (options.AbsoluteExpiration.HasValue)
     {
         expiryType = ExpiryType.Absolute;
         return(options.AbsoluteExpiration.Value.ToUnixTimeSeconds());
     }
     else if (options.AbsoluteExpirationRelativeToNow.HasValue)
     {
         expiryType = ExpiryType.Absolute;
         return(DateTimeOffset.Now.Add(options.AbsoluteExpirationRelativeToNow.Value).ToUniversalTime().ToUnixTimeSeconds());
     }
     else
     {
         throw new Exception("Cache expiry option must be set to Sliding, Absolute or Absolute relative to now");
     }
 }
예제 #5
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ExpiryType != global::PKIo.ExpiryType.ExpireNone)
            {
                hash ^= ExpiryType.GetHashCode();
            }
            if (expiryOneofCase_ == ExpiryOneofOneofCase.FixedExpiryDate)
            {
                hash ^= FixedExpiryDate.GetHashCode();
            }
            if (expiryOneofCase_ == ExpiryOneofOneofCase.ExpireAfterXDays)
            {
                hash ^= ExpireAfterXDays.GetHashCode();
            }
            hash ^= (int)expiryOneofCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
 internal void SetExpiryType(ExpiryType expiryType)
 {
     ExpiryTypeID = expiryType.ID.ToString();
 }
예제 #7
0
        private IEnumerable <KeyValuePair <string, string> > GetFormContent(string code, ExpiryType expiresIn)
        {
            var keyValuePairs = new List <KeyValuePair <string, string> >();

            keyValuePairs.Add(new KeyValuePair <string, string>("code", code));
            keyValuePairs.Add(new KeyValuePair <string, string>("grant_type", "authorization_code"));
            keyValuePairs.Add(new KeyValuePair <string, string>("client_id", ApplicationCredentials.ClientId));
            keyValuePairs.Add(new KeyValuePair <string, string>("redirect_uri", ApplicationCredentials.RedirectUri.ToString()));
            keyValuePairs.Add(new KeyValuePair <string, string>("expires_in", Convert.ToString((int)expiresIn)));

            if (!string.IsNullOrWhiteSpace(_internalState))
            {
                keyValuePairs.Add(new KeyValuePair <string, string>("state", _internalState));
            }

            if (!string.IsNullOrWhiteSpace(_internalCodeVerifier))
            {
                keyValuePairs.Add(new KeyValuePair <string, string>("code_verifier", _internalCodeVerifier));
            }

            return(keyValuePairs);
        }
예제 #8
0
        public string GetImplicitGrantFlowUrl(PermissionsRequestType[] scope, AuthenticationPromptType prompt = AuthenticationPromptType.None, ExpiryType expiresIn = ExpiryType.OneDay, string state = "")
        {
            var authorizationUrl = new StringBuilder(AuthorizeBaseUrl);

            AppendGeneralParameters(scope, prompt, state, authorizationUrl);

            authorizationUrl.Append($"&response_type=token");
            authorizationUrl.Append($"&expires_in={expiresIn}");

            return(authorizationUrl.ToString());
        }