Exemple #1
0
        public static bool Authorize(string username, string password, out UserInfo userInfo)
        {
            var rval = false;

            userInfo = null;

            lock (m_mutex)
            {
                var internalClient = new InternalClient(Configuration, 0, username, password, false);
                try
                {
                    userInfo = internalClient.GetItem <UserInfo>("/userinfo", null);
                    if (userInfo != null)
                    {
                        rval = true;

                        var auth = new TrueDialogAuthElement
                        {
                            AccountId = userInfo.AccountId,
                            ApiKey    = userInfo.ApiKey.Key,
                            ApiSecret = userInfo.ApiKey.Secret,
                            UserName  = username,
                            Password  = password
                        };
                        m_client = new TrueDialogClient(new InternalClient(Configuration, auth));
                    }
                }
                catch (System.Exception)
                {
                    // just ignore
                }
            }

            return(rval);
        }
Exemple #2
0
        public static bool Authorize(string username, string password, out UserInfo userInfo)
        {
            var rval = false;

            userInfo = null;

            try
            {
                m_semaphore.Wait();

                var api = new ApiCaller(new RawTrueDialogConfigProvider(username, password));

                userInfo = api.Get <UserInfo>("userinfo");
                if (userInfo != null)
                {
                    rval = true;

                    var config = new TrueDialogConfig
                    {
                        AccountId = userInfo.AccountId,
                        ApiKey    = userInfo.ApiKey.Key,
                        ApiSecret = userInfo.ApiKey.Secret,
                        Username  = username,
                        Password  = password,
                        BaseUrl   = Defaults.BaseUrl,
                        Timeout   = Defaults.Timeout,
                        UserAgent = Defaults.UserAgent
                    };
                    m_client = new TrueDialogClient(new ApiCaller(config));
                }
            }
            catch
            {
                // just ignore
            }
            finally
            {
                m_semaphore.Release();
            }

            return(rval);
        }