Esempio n. 1
0
        public resultClass findToken(resultClass token)
        {
            fetchToken ftoken       = new fetchToken();
            secure     secure_token = new secure(token);

            if (String.IsNullOrEmpty(token.user_name) || String.IsNullOrEmpty(token.credential))
            {
                // see if token is available in configuration
                token = decrypt_Token(token);
                if (!String.IsNullOrEmpty(token.bearer_token))
                {
                    if (token.timestamp.AddMinutes(token.expiration + 1) < DateTime.UtcNow)
                    {
                        //token has expired by now. See if credentials were kept
                        Console.Error.WriteLine("Token has expired. Using username and credential");

                        if (String.IsNullOrEmpty(token.user_name) || String.IsNullOrEmpty(token.credential))
                        {
                            Console.Error.WriteLine("No credentials stored or provided. Please provide username and credential");
                            return(token);
                        }

                        token = ftoken.get_token(token);
                    }
                    else
                    {
                        token = secure_token.decrypt_Token(token);
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(token.user_name) || String.IsNullOrEmpty(token.credential))
                    {
                        Console.Error.WriteLine("No credentials stored or provided. Please provide username and credential");
                        return(token);
                    }
                    token = ftoken.get_token(token);
                }
            }
            else
            {
                token = ftoken.get_token(token);
            }

            return(token);
        }