Example #1
0
        private BasicAuthEventArgs LogoutRequest(string accessToken, bool doAsync)
        {
            BasicAuthEventArgs result = null;

            string uri = FSUri.ActiveDomain + FSUri.IdentityV2Path + "/logout?sessionId=" + accessToken;

            string authResult = string.Empty;

            if (doAsync)
            {
                client.DownloadStringAsync(new Uri(uri), false); //we are using a SINGLE event handler for both login and logout.  Setting state as "true" will indicate to the Completed handler to know what the DownloadString was for.
            }
            else
            {
                authResult = client.DownloadString(uri);
            }

            return(GetArgsFromAuthResponse(client.StatusCode, client.StatusDescription, authResult));
        }
Example #2
0
        /// <summary>
        /// Authenticate with FamilySearch using Basic Authentication
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <param name="devKey">Dev Key (or Client ID)</param>
        /// <returns></returns>
        public BasicAuthEventArgs Login(string username, string password, string devKey)
        {
            bool valid = ValidateLogin(username, password, devKey);

            BasicAuthEventArgs ir = null;

            if (valid)
            {
                //Attempt Login to the system, get the response
                ir = AuthRequest(username, password, devKey, false);

                if (ir != null && ir.Result != null && ir.Result.Session != null)
                {
                    this.AccessToken = ir.Result.Session.Id;
                }
            }

            return(ir);
        }
Example #3
0
        private BasicAuthEventArgs AuthRequest(string username, string password, string devKey, bool doAsync)
        {
            BasicAuthEventArgs result = null;

            client.Credentials = new NetworkCredential(username, password);

            string uri = FSUri.ActiveDomain + FSUri.IdentityV2Path + "/login?key=" + devKey;

            string authResult = string.Empty;

            if (doAsync)
            {
                client.DownloadStringAsync(new Uri(uri), true); //we are using a SINGLE event handler for both login and logout.  Setting state as "true" will indicate to the Completed handler to know what the DownloadString was for.
            }
            else
            {
                authResult = client.DownloadString(uri);
            }

            return(GetArgsFromAuthResponse(client.StatusCode, client.StatusDescription, authResult));
        }
        void target_LogoutCompleted(object sender, BasicAuthEventArgs e)
        {
            var expected = System.Net.HttpStatusCode.OK;
            var actual = e;

            Assert.AreEqual(expected, actual.StatusCode);

            this._TestTrigger.Set();
        }
        void target_LoginCompleted(object sender, BasicAuthEventArgs e)
        {
            BasicAuthEventArgs actual = e;

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Result);
            Assert.IsNotNull(actual.Result.Session);
            Assert.IsNotNull(actual.Result.Session.Id);
            if (actual.Result.Session.Id != null)
                Debug.WriteLine("AccessToken: " + actual.Result.Session.Id);


            this._TestTrigger.Set();
        }