예제 #1
0
        internal override JSONNode ToJsonNode()
        {
            JSONObject jso = new JSONObject {
                [ApiConstants.Batch] = BatchSize
            };

            if (MaxBytes > 0)
            {
                jso[ApiConstants.MaxBytes] = MaxBytes;
            }
            if (NoWait)
            {
                jso[ApiConstants.NoWait] = true;
            }
            if (ExpiresIn != null && ExpiresIn.IsPositive())
            {
                jso[ApiConstants.Expires] = ExpiresIn.Nanos;
            }
            if (IdleHeartbeat != null && IdleHeartbeat.IsPositive())
            {
                jso[ApiConstants.IdleHeartbeat] = IdleHeartbeat.Nanos;
            }

            return(jso);
        }
예제 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Method != global::Spotify.Login5.V3.Challenges.CodeChallenge.Types.Method.Unknown)
            {
                hash ^= Method.GetHashCode();
            }
            if (CodeLength != 0)
            {
                hash ^= CodeLength.GetHashCode();
            }
            if (ExpiresIn != 0)
            {
                hash ^= ExpiresIn.GetHashCode();
            }
            if (CanonicalPhoneNumber.Length != 0)
            {
                hash ^= CanonicalPhoneNumber.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #3
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (ConversationId != null)
         {
             hashCode = hashCode * 59 + ConversationId.GetHashCode();
         }
         if (Token != null)
         {
             hashCode = hashCode * 59 + Token.GetHashCode();
         }
         if (ExpiresIn != null)
         {
             hashCode = hashCode * 59 + ExpiresIn.GetHashCode();
         }
         if (StreamUrl != null)
         {
             hashCode = hashCode * 59 + StreamUrl.GetHashCode();
         }
         if (ReferenceGrammarId != null)
         {
             hashCode = hashCode * 59 + ReferenceGrammarId.GetHashCode();
         }
         if (ETag != null)
         {
             hashCode = hashCode * 59 + ETag.GetHashCode();
         }
         return(hashCode);
     }
 }
예제 #4
0
        public override int GetHashCode()
        {
            int hashCode = -746518720;

            if (AccessToken != null)
            {
                hashCode += AccessToken.GetHashCode();
            }

            if (TokenType != null)
            {
                hashCode += TokenType.GetHashCode();
            }

            if (ExpiresIn != null)
            {
                hashCode += ExpiresIn.GetHashCode();
            }

            if (Scope != null)
            {
                hashCode += Scope.GetHashCode();
            }

            if (Expiry != null)
            {
                hashCode += Expiry.GetHashCode();
            }

            return(hashCode);
        }
예제 #5
0
        /// <summary>
        /// Output all properties
        /// </summary>
        /// <returns>A string</returns>
        public override string ToString()
        {
            var toString = new StringBuilder();

            toString.Append("AccessTokenValue: ").AppendLine(AccessToken);
            toString.Append("TokenType: ").AppendLine(TokenType);
            toString.Append("ExpiresIn: ").AppendLine(ExpiresIn.ToString(CultureInfo.InvariantCulture));
            toString.Append("ExpiresIn: ").AppendLine(Store.ToString());
            return(toString.ToString());
        }
예제 #6
0
        protected new void ToString(List <string> toStringOutput)
        {
            toStringOutput.Add($"AccessToken = {(AccessToken == null ? "null" : AccessToken == string.Empty ? "" : AccessToken)}");
            toStringOutput.Add($"TokenType = {(TokenType == null ? "null" : TokenType == string.Empty ? "" : TokenType)}");
            toStringOutput.Add($"ExpiresIn = {(ExpiresIn == null ? "null" : ExpiresIn.ToString())}");
            toStringOutput.Add($"Scope = {(Scope == null ? "null" : Scope == string.Empty ? "" : Scope)}");
            toStringOutput.Add($"Expiry = {(Expiry == null ? "null" : Expiry.ToString())}");

            base.ToString(toStringOutput);
        }
예제 #7
0
        private string CalculateSignature(string key)
        {
            string content = Timestamp + Application + ExpiresIn.ToString();

            byte[] contentBytes = Encoding.ASCII.GetBytes(content);

            byte[] keyBytes = Encoding.ASCII.GetBytes(key);
            System.Security.Cryptography.HMACSHA256 hmac = new System.Security.Cryptography.HMACSHA256(keyBytes);
            byte[] signatureBytes = hmac.ComputeHash(contentBytes);
            return(Convert.ToBase64String(signatureBytes));
        }
예제 #8
0
        private void ObterToken(Entity tokenConfigRecord)
        {
            var client = new HttpClient();
            //get all attibutes required to get token
            string tokenEndPoint = (string)tokenConfigRecord[token_endpoint_attribute];
            string clientId      = (string)tokenConfigRecord[clientid_attribute];
            string clientSecret  = (string)tokenConfigRecord[client_secret_attribute];
            string resource      = (string)tokenConfigRecord[resource_attribute];

            client.BaseAddress = new Uri(tokenEndPoint);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("resource", resource),
                new KeyValuePair <string, string>("client_id", clientId),
                new KeyValuePair <string, string>("client_secret", clientSecret),
                new KeyValuePair <string, string>("client_info", "1"),
                new KeyValuePair <string, string>("grant_type", "client_credentials")
            });

            var    result        = client.PostAsync("", content).GetAwaiter().GetResult();
            string resultContent = result.Content.ReadAsStringAsync().GetAwaiter().GetResult();

            if (!string.IsNullOrEmpty(resultContent) && resultContent.Contains("access_token"))
            {
                var tokenParse = new TokenParse(resultContent);
                Token.Set(ExecutionContext, tokenParse.access_token);
                var dataExpiracao = DateTime.Now.AddSeconds(tokenParse.expires_in);
                ExpiresIn.Set(ExecutionContext, dataExpiracao);
                Sucess.Set(ExecutionContext, true);
                Message.Set(ExecutionContext, "Sucess");
                //grava token na entidade para cache
                var tokenUpdt = new Entity()
                {
                    LogicalName = tokenConfigRecord.LogicalName, Id = tokenConfigRecord.Id
                };
                tokenUpdt[data_expiracao] = dataExpiracao;
                tokenUpdt[valor_token]    = tokenParse.access_token;
                Service.Update(tokenUpdt);
            }
            else
            {
                if (!string.IsNullOrEmpty(resultContent) && resultContent.Contains("error_description"))
                {
                    var tokenParse = new TokenParse(resultContent);
                    Message.Set(ExecutionContext, tokenParse.error_description);
                }
                else
                {
                    Message.Set(ExecutionContext, "Requisição não retornou um token válido.");
                }
            }
        }
예제 #9
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is OAuthToken other &&
                   ((AccessToken == null && other.AccessToken == null) || (AccessToken?.Equals(other.AccessToken) == true)) &&
                   ((TokenType == null && other.TokenType == null) || (TokenType?.Equals(other.TokenType) == true)) &&
                   ((ExpiresIn == null && other.ExpiresIn == null) || (ExpiresIn?.Equals(other.ExpiresIn) == true)) &&
                   ((Scope == null && other.Scope == null) || (Scope?.Equals(other.Scope) == true)) &&
                   ((Expiry == null && other.Expiry == null) || (Expiry?.Equals(other.Expiry) == true)));
        }
예제 #10
0
        /// <summary>
        /// Returns true if Conversation instances are equal
        /// </summary>
        /// <param name="other">Instance of Conversation to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Conversation other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     ConversationId == other.ConversationId ||
                     ConversationId != null &&
                     ConversationId.Equals(other.ConversationId)
                     ) &&
                 (
                     Token == other.Token ||
                     Token != null &&
                     Token.Equals(other.Token)
                 ) &&
                 (
                     ExpiresIn == other.ExpiresIn ||
                     ExpiresIn != null &&
                     ExpiresIn.Equals(other.ExpiresIn)
                 ) &&
                 (
                     StreamUrl == other.StreamUrl ||
                     StreamUrl != null &&
                     StreamUrl.Equals(other.StreamUrl)
                 ) &&
                 (
                     ReferenceGrammarId == other.ReferenceGrammarId ||
                     ReferenceGrammarId != null &&
                     ReferenceGrammarId.Equals(other.ReferenceGrammarId)
                 ) &&
                 (
                     ETag == other.ETag ||
                     ETag != null &&
                     ETag.Equals(other.ETag)
                 ));
        }
예제 #11
0
        protected override void OnExecute()
        {
            Trace("Start....");
            try
            {
                //get de record used to configure token creation
                EntityReference configRefence = TokenConfig.Get(ExecutionContext);
                if (configRefence == null)
                {
                    Sucess.Set(ExecutionContext, true);
                    Message.Set(ExecutionContext, "Nenhuma referencia de configuração foi definida na Action.");
                    return;
                }

                var tokenConfigRecord = Service.Retrieve(configRefence.LogicalName, configRefence.Id, new ColumnSet(atributos));
                ValidarCamposObrigatorios(tokenConfigRecord);
                var dataExpiracao = tokenConfigRecord.Contains(data_expiracao) ? tokenConfigRecord.GetAttributeValue <DateTime>(data_expiracao) : DateTime.MinValue;

                //Obtem novo token se atual expirado
                if (dataExpiracao < DateTime.Now)
                {
                    ObterToken(tokenConfigRecord);
                }
                else
                {
                    Token.Set(ExecutionContext, tokenConfigRecord.GetAttributeValue <string>(valor_token));
                    ExpiresIn.Set(ExecutionContext, tokenConfigRecord.GetAttributeValue <DateTime>(data_expiracao));
                    Sucess.Set(ExecutionContext, true);
                    Message.Set(ExecutionContext, "Sucess");
                }
            }
            catch (Exception ex)
            {
                Message.Set(ExecutionContext, ex.Message);
            }
        }
예제 #12
0
        /// <summary>
        /// Success response
        /// </summary>
        /// <returns>string output</returns>
        public string ToStringSuccessResponse()
        {
            var output = AccessToken.ObjectToString("AccessToken") + ExpiresIn.ObjectToString("ExpiresIn") + RefreshToken.ObjectToString("RefreshToken") + TokenType.ObjectToString("TokenType") + Scope.ObjectToString("Scope");

            return(output);
        }