예제 #1
0
        private static ExtractAccountIdAndServerIdFromTokenResult?ExtractAccountIdAndServerIdFromToken(string tokenId)
        {
            if (tokenId == null)
            {
                return(null);
            }

            if (tokenId.IndexOf('-') >= 0)
            {
                // retrieve the account id
                string firstValue = tokenId.Substring(0, tokenId.IndexOf('-'));
                // remove the first value from the token
                tokenId = tokenId.Substring(tokenId.IndexOf("-") + 1);

                // verify that the first value (account id) is not a number; that would mean that we're looking at a root token instead of an account token
                if (firstValue.All(char.IsDigit))
                {
                    return(new ExtractAccountIdAndServerIdFromTokenResult()
                    {
                        AccountId = null, AccountServerId = firstValue
                    });
                }

                // verify that the first value is a valid account name (i.e. does not contain invalid characters)
                if (firstValue != null && FormattingHelper.ContainsOnlyAllowedIdentifierCharacters(firstValue) == false)
                {
                    return(null);
                }

                if (tokenId.IndexOf('-') >= 0)
                {
                    string secondValue = tokenId.Substring(0, tokenId.IndexOf('-'));
                    // verify that the second value is a number (i.e. the server id)
                    if (secondValue.All(char.IsDigit))
                    {
                        return(new ExtractAccountIdAndServerIdFromTokenResult {
                            AccountId = firstValue, AccountServerId = secondValue
                        });
                    }
                }
            }

            // if we reach here, the token is not valid
            return(null);
        }