Esempio n. 1
0
        void AuthenticateByJWT(object o)
        {
            this.IsBusy = true;
            JWTAuthenticator auth = ApplicationController.Instance.CurSparkManager.CurSpark.Authenticator as JWTAuthenticator;

            auth?.AuthorizeWith(this.jwtStr, result =>
            {
                this.IsBusy = false;
                if (result.IsSuccess)
                {
                    ApplicationController.Instance.AppLogOutput("authorize success!");
                    ApplicationController.Instance.ChangeState(State.Main);
                }
                else
                {
                    ApplicationController.Instance.AppLogOutput("authorize failed!");
                }
            });
        }
Esempio n. 2
0
        private bool JWtLogin()
        {
            string jwt        = ConfigurationManager.AppSettings["JWT"] ?? "";
            var    completion = new ManualResetEvent(false);
            var    response   = new SparkApiEventArgs();

            jwtAuth.AuthorizeWith(jwt, rsp =>
            {
                response = rsp;
                completion.Set();
            });

            if (false == completion.WaitOne(30000))
            {
                Console.WriteLine("authorizeWith timeout");
                return(false);
            }

            return(response.IsSuccess);
        }
Esempio n. 3
0
        public void AuthorizeTestErrorJwt2()
        {
            var completion = new ManualResetEvent(false);

            var    auth      = new JWTAuthenticator();
            string jwt       = "yJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG5Eb2UiLCJpc3MiOiJjZDVjOWFmNy04ZWQzLTRlMTUtOTcwNS0wMjVlZjMwYjFiNmEifQ.oC-QPs-Eotaq4ovv2glwrHpxXQzqN1WvNlKmMAmtp24";
            var    rspOfauth = new WebexApiEventArgs();

            auth.AuthorizeWith(jwt, r =>
            {
                rspOfauth = r;
                completion.Set();
            });

            if (!completion.WaitOne(30000))
            {
                Assert.Fail();
                return;
            }
            Assert.IsFalse(rspOfauth.IsSuccess);
        }
Esempio n. 4
0
        public void AuthorizeTestErrorJwt1()
        {
            var completion = new ManualResetEvent(false);

            var auth = new JWTAuthenticator();

            var rspOfauth = new WebexApiEventArgs();

            auth.AuthorizeWith("a.b.c", r =>
            {
                rspOfauth = r;
                completion.Set();
            });

            if (!completion.WaitOne(30000))
            {
                Assert.Fail();
                return;
            }
            Assert.IsFalse(rspOfauth.IsSuccess);
        }
Esempio n. 5
0
        public void AuthorizeTestInvalidJWT()
        {
            var completion = new ManualResetEvent(false);

            var    auth = new JWTAuthenticator();
            string jwt  = "a.c";

            var rspOfauth = new SparkApiEventArgs();

            auth.AuthorizeWith(jwt, r =>
            {
                rspOfauth = r;
                completion.Set();
            });

            if (false == completion.WaitOne(30000))
            {
                Assert.Fail();
                return;
            }
            Assert.IsFalse(rspOfauth.IsSuccess);
        }
Esempio n. 6
0
        public void AuthorizeTestInvalidJWTexpire()
        {
            var completion = new ManualResetEvent(false);

            var auth = new JWTAuthenticator();
            //expired JWT
            string jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG5Eb2UiLCJleHAiOiIxNDA1OTc0ODczIiwiaXNzIjoiY2Q1YzlhZjctOGVkMy00ZTE1LTk3MDUtMDI1ZWYzMGIxYjZhIn0.brzUE0LYgEIkt4kK7s2QwrHkhgWPUwbj5XMVECAA_hQ";

            var rspOfauth = new WebexApiEventArgs();

            auth.AuthorizeWith(jwt, r =>
            {
                rspOfauth = r;
                completion.Set();
            });

            if (!completion.WaitOne(30000))
            {
                Assert.Fail();
                return;
            }
            Assert.IsFalse(rspOfauth.IsSuccess);
        }
Esempio n. 7
0
        private bool Login(JWTAuthenticator auth)
        {
            var completion = new ManualResetEvent(false);
            var response   = new WebexApiEventArgs();

            if (auth == null)
            {
                Console.WriteLine("jwt login: auth is null");
                return(false);
            }
            auth.AuthorizeWith(jwt, r =>
            {
                response = r;
                completion.Set();
            });
            if (!completion.WaitOne(30000))
            {
                Console.WriteLine("jwt login: timeout");
                return(false);
            }

            Console.WriteLine($"jwt login: success is {response.IsSuccess}");
            return(response.IsSuccess);
        }