Пример #1
0
        public static bool ReissueAuthToken()
        {
            Dictionary <string, string> packet = SessionItemContainer.Retrieve(SessionItemContainerKey.AuthPacket) as Dictionary <string, string>;

            if (packet != null)
            {
                string apiurl = packet["__apiurl"];
                string apikey = packet["__apikey"];
                Dictionary <string, string> parameters = packet.Where(p => !p.Key.StartsWith("__")).ToDictionary(p => p.Key, p => p.Value);

                XmlNode xToken = LegionService.GetReply(apiurl, apikey, ReplyFormat.XML.ToString(), "__system", "CreateAuthToken", parameters).ToXml().SelectSingleNode("//token");
                if (xToken != null)
                {
                    string token = xToken.InnerText;
                    SessionItemContainer.Store(SessionItemContainerKey.AuthPacket, packet);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="apikey"></param>
        /// <param name="apiurl"></param>
        /// <param name="type"></param>
        /// <param name="identifier"></param>
        /// <param name="email"></param>
        /// <param name="givenname"></param>
        /// <param name="surname"></param>
        /// <returns></returns>
        public static string CreateAuthToken(string apikey, string apiurl, LegionAccountType type, string identifier)
        {
            Dictionary <string, string> packet = new Dictionary <string, string>()
            {
                { "AccountType", type.ToString() },
                { "AccountId", identifier },
                { "__apikey", apikey },
                { "__apiurl", apiurl }
            };

            Dictionary <string, string> parameters = packet.Where(p => !p.Key.StartsWith("__")).ToDictionary(p => p.Key, p => p.Value);

            XmlDocument xReply = LegionService.GetReply(apiurl, apikey, ReplyFormat.XML.ToString(), "__system", "CreateAuthToken", parameters).ToXml();

            XmlNode xToken = xReply.SelectSingleNode("//token");

            if (xToken != null)
            {
                string token = xToken.InnerText;
                SessionItemContainer.Store(SessionItemContainerKey.AuthPacket, packet);
                return(token);
            }
            else
            {
                XmlNode xFriendly = xReply.SelectSingleNode("//error/description[@type='friendly']");
                if (xFriendly != null)
                {
                    throw new LegionServiceException(string.Format("{0} ({1}:{2})", xFriendly.InnerText, type, identifier));
                }
                else
                {
                    XmlNode xError = xReply.SelectSingleNode("//error");
                    if (xError != null)
                    {
                        throw new LegionServiceException(string.Format("{0} ({1}:{2})", xFriendly.InnerText, type, identifier));
                    }
                    else
                    {
                        XmlNode xFault = xReply.SelectSingleNode("//fault");
                        if (xFault != null)
                        {
                            throw new LegionServiceException(string.Format("{0} ({1})", xFault.InnerText, xFault.Attributes["type"].Value));
                        }
                        else
                        {
                            throw new LegionServiceException("Unknown error. Unable to parse CreateAuthToken() response.");
                        }
                    }
                }
            }
        }