public Webex CreateWebexbyJwt() { if (jwtWebex == null) { jwtAuth = new JWTAuthenticator(); jwtWebex = new WebexSDK.Webex(jwtAuth); //login for (int count = 1; count <= 5; count++) { if (JWtLogin() == true) { Console.WriteLine("JWtLogin success."); break; } Console.WriteLine($"Error: jwt login fail[{count}]."); if (count == 5) { jwtWebex = null; return(null); } } } return(jwtWebex); }
public Spark CreateSparkbyJwt() { if (jwtSpark == null) { jwtAuth = new JWTAuthenticator(); jwtSpark = new SparkSDK.Spark(jwtAuth); //login for (int count = 1; count <= 5; count++) { if (JWtLogin() == true) { Console.WriteLine("JWtLogin success."); break; } Console.WriteLine($"Error: jwt login fail[{count}]."); if (count == 5) { jwtSpark = null; return(null); } } } return(jwtSpark); }
public IdentityData GetIdentity() { string username = null; try { username = JWTAuthenticator.GetTokenIdentity(Security.BinarySecurityToken); } catch (Exception ex) when(ex is ArgumentException || ex is SecurityTokenInvalidSignatureException || ex is SecurityTokenExpiredException) { throw new SoapException("Authentication Failure - Auth token provided is not valid", SoapException.ClientFaultCode); } if (username == null) { return(null); } using (var ds = new DataService()) { User loggedUser = ds.getUserDAO().FindByUsername(username); if (loggedUser == null) { return(null); } return(new IdentityData { Username = username, Role = loggedUser.Role }); } }
public void AuthorizeWithTest() { var auth = new JWTAuthenticator(); Assert.IsTrue(LoginWithTryTimes(auth, 5)); Assert.IsTrue(Logout(auth)); }
public void AccessTokenTest() { var completion = new ManualResetEvent(false); var repOfaccessToken = new SparkApiEventArgs <string>(); var auth = new JWTAuthenticator(); Assert.IsTrue(LoginWithTryTimes(auth, 5)); auth.AccessToken(r => { repOfaccessToken = r; completion.Set(); }); if (false == completion.WaitOne(30000)) { Assert.Fail(); return; } Assert.IsTrue(repOfaccessToken.IsSuccess); Assert.IsNotNull(repOfaccessToken.Data); Assert.IsNull(repOfaccessToken.Error); Assert.IsTrue(Logout(auth)); }
private bool Logout(JWTAuthenticator auth) { if (auth == null) { return(false); } auth.Deauthorize(); Console.WriteLine("jwt logout: success"); return(true); }
private bool LoginWithTryTimes(JWTAuthenticator auth, int times) { int tryTimes = times; while (tryTimes > 0) { tryTimes--; if (Login(auth)) { Console.WriteLine("loginWithTryTimes: success"); return(true); } } Console.WriteLine("loginWithTryTimes: fail"); return(false); }
public void AccessTokenTestUnexpirAccessToken() { var completion = new ManualResetEvent(false); var repOfaccessToken = new SparkApiEventArgs <string>(); var auth = new JWTAuthenticator(); Assert.IsTrue(LoginWithTryTimes(auth, 5)); auth.AccessToken(r => { repOfaccessToken = r; completion.Set(); }); if (false == completion.WaitOne(30000)) { Assert.Fail(); return; } Assert.IsTrue(repOfaccessToken.IsSuccess); Assert.IsNotNull(repOfaccessToken.Data); Assert.IsNull(repOfaccessToken.Error); //get unexpired access token, it is the same of last one. completion.Reset(); var newAccessToken = new SparkApiEventArgs <string>(); auth.AccessToken(r => { newAccessToken = r; completion.Set(); }); if (false == completion.WaitOne(30000)) { Assert.Fail(); return; } Assert.IsTrue(newAccessToken.IsSuccess); Assert.AreEqual(repOfaccessToken.Data, newAccessToken.Data); Logout(auth); }
//# //[TestMethod()] //public void AccessTokenTest() //{ // var completion = new ManualResetEvent(false); // var repOfaccessToken = new WebexApiEventArgs<string>(); // var auth = new JWTAuthenticator(); // Assert.IsTrue(LoginWithTryTimes(auth, 5)); // auth.AccessToken(r => // { // repOfaccessToken = r; // completion.Set(); // }); // if (!completion.WaitOne(30000)) // { // Assert.Fail(); // return; // } // Assert.IsTrue(repOfaccessToken.IsSuccess); // Assert.IsNotNull(repOfaccessToken.Data); // Assert.IsNull(repOfaccessToken.Error); // Assert.IsTrue(Logout(auth)); // Thread.Sleep(30000); //} //[TestMethod()] //public void AccessTokenTestUnexpirAccessToken() //{ // var completion = new ManualResetEvent(false); // var repOfaccessToken = new WebexApiEventArgs<string>(); // var auth = new JWTAuthenticator(); // Assert.IsTrue(LoginWithTryTimes(auth, 5)); // auth.AccessToken(r => // { // repOfaccessToken = r; // completion.Set(); // }); // if (!completion.WaitOne(30000)) // { // Assert.Fail(); // return; // } // Assert.IsTrue(repOfaccessToken.IsSuccess); // Assert.IsNotNull(repOfaccessToken.Data); // Assert.IsNull(repOfaccessToken.Error); // //get unexpired access token, it is the same of last one. // completion.Reset(); // var newAccessToken = new WebexApiEventArgs<string>(); // auth.AccessToken(r => // { // newAccessToken = r; // completion.Set(); // }); // if (!completion.WaitOne(30000)) // { // Assert.Fail(); // return; // } // Assert.IsTrue(newAccessToken.IsSuccess); // Assert.AreEqual(repOfaccessToken.Data, newAccessToken.Data); // Assert.IsTrue(Logout(auth)); // Thread.Sleep(30000); //} //[TestMethod()] //public void LoginLogoutManytimes() //{ // var auth = new JWTAuthenticator(); // int count = 3; // while (count > 0) // { // count--; // Console.WriteLine($"loginLogoutManytimes[{count}]"); // Assert.IsTrue(loginWithTryTimes(auth, 10)); // logout(auth); // } //} private bool CheckAuthorized(JWTAuthenticator auth) { var completion = new ManualResetEvent(false); var response = new WebexApiEventArgs(); auth.Authorized(r => { response = r; completion.Set(); }); if (!completion.WaitOne(30000)) { Assert.Fail(); return(false); } return(response.IsSuccess); }
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!"); } }); }
void TryToLoginByJWT() { this.IsBusy = true; var auth = new JWTAuthenticator(); var sparkManager = new SparkManager(auth); ApplicationController.Instance.CurSparkManager = sparkManager; auth.Authorized(r => { this.IsBusy = false; if (r.IsSuccess) { ApplicationController.Instance.ChangeState(State.Main); } else { ApplicationController.Instance.ChangeState(State.LoginByJWT); } }); }
public void AuthorizeTestInvalidJWTnull() { var completion = new ManualResetEvent(false); var auth = new JWTAuthenticator(); var response = new WebexApiEventArgs <string>(); auth.AccessToken(r => { response = r; completion.Set(); }); if (!completion.WaitOne(30000)) { Assert.Fail(); return; } Assert.IsFalse(response.IsSuccess); }
/// <summary> /// Start up the user manager /// </summary> /// <param name="inventoryService"></param> protected virtual void StartupUserServerModules() { m_log.Info("[STARTUP]: Establishing data connection"); //we only need core components so we can request them from here IInterServiceInventoryServices inventoryService; TryGet <IInterServiceInventoryServices>(out inventoryService); CommunicationsManager commsManager = new UserServerCommsManager(); //setup database access service, for now this has to be created before the other modules. m_userDataBaseService = new UserDataBaseService(commsManager); m_userDataBaseService.Initialize(this); RegisterInterface <UserDataBaseService>(m_userDataBaseService); //TODO: change these modules so they fetch the databaseService class in the PostInitialize method m_userManager = new Modules.UserManager(m_userDataBaseService); m_userManager.Initialize(this); m_avatarAppearanceModule = new UserServerAvatarAppearanceModule(m_userDataBaseService); m_avatarAppearanceModule.Initialize(this); m_friendsModule = new UserServerFriendsModule(m_userDataBaseService); m_friendsModule.Initialize(this); if (m_useJwt) { m_jwtAuthenticator = new JWTAuthenticator(); m_jwtAuthenticator.Initialize(this); } m_consoleCommandModule = new UserServerCommandModule(); m_consoleCommandModule.Initialize(this); m_messagesService = new MessageServersConnector(); m_messagesService.Initialize(this); m_gridInfoService = new GridInfoServiceModule(); m_gridInfoService.Initialize(this); }
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); }
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); }
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); }
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); }
void TryToLoginByJWT() { this.IsBusy = true; var auth = new JWTAuthenticator(); var sparkManager = new SparkManager(auth); ApplicationController.Instance.CurSparkManager = sparkManager; sparkManager.CurSpark.Logger = ApplicationController.Instance.ShellViewModel; ApplicationController.Instance.AppLogOutput("check if authorized"); auth.Authorized(r => { this.IsBusy = false; if (r.IsSuccess) { ApplicationController.Instance.AppLogOutput("authorize success!"); ApplicationController.Instance.ChangeState(State.Main); } else { ApplicationController.Instance.ChangeState(State.LoginByJWT); } }); }
private void ValidateSecurity(Security Security) { if (Security == null || String.IsNullOrEmpty(Security.BinarySecurityToken)) { throw new SoapException("Authentication Failure - Auth token required but not received", SoapException.ClientFaultCode); } try { bool validToken = JWTAuthenticator.ValidateToken(Security.BinarySecurityToken); if (!validToken) { throw new SoapException("Authentication Failure - Auth token provided is not valid", SoapException.ClientFaultCode); } } catch (Exception ex) when(ex is ArgumentException || ex is SecurityTokenInvalidSignatureException || ex is SecurityTokenExpiredException) { throw new SoapException("Authentication Failure - Auth token provided is not valid", SoapException.ClientFaultCode); } }
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); }