public async Task GetToken_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken) { var args = new GetTokenArgs(); await args.ReadAsync(iprot, cancellationToken); await iprot.ReadMessageEndAsync(cancellationToken); var result = new GetTokenResult(); try { result.Success = await _iAsync.GetTokenAsync(args.UserInfo, cancellationToken); await oprot.WriteMessageBeginAsync(new TMessage("GetToken", TMessageType.Reply, seqid), cancellationToken); await result.WriteAsync(oprot, cancellationToken); } catch (TTransportException) { throw; } catch (Exception ex) { Console.Error.WriteLine("Error occurred in processor:"); Console.Error.WriteLine(ex.ToString()); var x = new TApplicationException(TApplicationException.ExceptionType.InternalError, " Internal error."); await oprot.WriteMessageBeginAsync(new TMessage("GetToken", TMessageType.Exception, seqid), cancellationToken); await x.WriteAsync(oprot, cancellationToken); } await oprot.WriteMessageEndAsync(cancellationToken); await oprot.Transport.FlushAsync(cancellationToken); }
private void GetToken() { getTokenResult = new GetTokenResult(); HttpWebRequest request = WebRequest.CreateHttp(loginUrl); request.Method = "Get"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string setCookie = response.Headers.GetValues("Set-Cookie")[0]; Dictionary <string, string> setCookieDictionary = setCookie.Split(';').ToDictionary <string, string, string>(i => i.Split('=')[0], i => i.Split('=').Length > 1 ? i.Split('=')[1] : null); getTokenResult.antiForgeryCookie = setCookieDictionary.First().Value; Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(responseFromServer); HtmlNode requestVerificationTokenNode = doc.DocumentNode.Descendants().Where(node => node.GetAttributeValue("name", "Error") == RequestVerificationToken).First(); getTokenResult.token = requestVerificationTokenNode.GetAttributeValue("value", "Error"); var properties = new Dictionary <string, string>(); properties.Add("AntiForgeryCookie", getTokenResult.antiForgeryCookie); SendTelemetry(loginUrl, "GetToken", response.StatusCode.ToString(), properties); }
public async Task <IUsuario> RegisterUser(string email, string password, string nome) { try { IAuthResult result = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password); await result.User.UpdateProfileAsync(new UserProfileChangeRequest.Builder().SetDisplayName(nome).Build()); GetTokenResult tokenResult = await result.User.GetIdTokenAsync(false); return(new Usuario() { Uid = result.User.Uid, Token = tokenResult.Token, Email = email, DtLastLogin = DateTime.Now, Nome = nome, IsAdmin = false, IsPro = false }); } catch (FirebaseAuthUserCollisionException e) { throw new Exception("Já existe um usuário registrado com o e-mail informado: " + email); } catch (FirebaseAuthEmailException e) { throw new Exception("O e-mail informado está preenchido incorretamente: " + email); } catch (Exception e) { throw new Exception("Erro: " + e.Message); } }
public async Task <string> SignUp(string email, string password) { var user = await Firebase.Auth.FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password); GetTokenResult tokenResult = await(user.User.GetIdToken(true).AsAsync <GetTokenResult>()); return(tokenResult.Token); }
public static GetTokenResult getTokenResult(string userId) { var gtr = new GetTokenResult { UserID = userId }; var u = SysUserBLL.Get(userId); gtr.UserName = u.Name; return(gtr); }
public async Task <string> GetToken() { if (IsSignedIn()) { GetTokenResult tokenRequest = (GetTokenResult)await FirebaseAuth.Instance.CurrentUser.GetIdToken(true); return(tokenRequest.Token); } return(string.Empty); }
/// <summary> /// Fetches a Firebase Auth ID Token for the user. /// </summary> /// <param name="forceRefresh">Force refreshes the token. Should only be set to true if the token is invalidated out of band.</param> /// <returns>Task with the ID Token</returns> public async Task <string> GetIdTokenAsync(bool forceRefresh) { try { GetTokenResult tokenResult = await _user.GetIdTokenAsync(forceRefresh); return(tokenResult.Token); } catch (FirebaseException ex) { throw GetFirebaseAuthException(ex); } }
public void OnSuccess(Java.Lang.Object result) { GetTokenResult t = result as GetTokenResult; AppManager.User.FirebaseToken = t.Token; if (!publishLoginDone && !silentSignIn) { Xamarin.Forms.MessagingCenter.Send("NavigateToNextPage", "LoginDone"); publishLoginDone = true; } AppManager.GetFavoritesFromFirebase(AppManager.User.UserId); }
public async Task <string> SignUpWithEmailPassword(string email, string password) { try { IAuthResult user = await FirebaseAuth.Instance.CreateUserWithEmailAndPasswordAsync(email, password); GetTokenResult token = await user.User.GetIdTokenAsync(false); return(token.Token); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <string> IsSignIn() { var user = Firebase.Auth.FirebaseAuth.Instance.CurrentUser; if (user == null) { return(string.Empty); } GetTokenResult tokenResult = await(user.GetIdToken(true).AsAsync <GetTokenResult>()); if (tokenResult == null) { return(string.Empty); } return(tokenResult.Token); }
public async Task SignInAsync_ShouldSignIn() { var dto = new SignInRequest { Password = mockUser.Password, Username = mockUser.Username }; var tokenResult = new GetTokenResult { Token = "token" }; var signedUser = new SignInResult { CreationDate = mockUser.CreationDate, DisplayName = mockUser.DisplayName, EmailAddress = mockUser.EmailAddress, Username = mockUser.Username, Id = mockUser.Id }; mockUserRepository.Setup(m => m.GetUserByUsernameAndPassword(It.IsAny <SignInRequest>())) .Returns(mockUser); mockAuth0Client.Setup(m => m.GetTokenAsync()) .ReturnsAsync(tokenResult); var validationResult = new ValidationResult(new List <ValidationFailure>() { new ValidationFailure("EmailAddress", "Email address already in use") }); mockSignUpValidator.Setup(v => v.Validate(It.IsAny <SignUpRequest>())) .Returns(validationResult); mockMapper.Setup(m => m.Map <SignInResult>(It.IsAny <User>())) .Returns(signedUser); var result = await userServices.SignInAsync(dto); Assert.Equal(tokenResult.Token, result.Token); Assert.Equal(signedUser.Id, result.Id); }
public void Start() { PushApi pushApi = new PushApi(session.GetApiClient()); GetPushConfigResult getPushConfigResult = pushApi.GetPushConfig("ws"); if (getPushConfigResult.Hdr.Rc == 0) { pushServer = getPushConfigResult.Host; GetTokenResult getTokenResult = pushApi.GetToken(session.UserKey); if (getTokenResult.Hdr.Rc == 0) { signature = getTokenResult.Token; BuildChannel(); Connect(); UserAuth(); Subscribe(); BuildChannelMonitor(); } } }
public async Task <string> LoginWithEmailPassword(string email, string password) { try { IAuthResult user = await FirebaseAuth.Instance.SignInWithEmailAndPasswordAsync(email, password); GetTokenResult token = await user.User.GetIdTokenAsync(false); return(token.Token); } catch (FirebaseAuthInvalidUserException e) { e.PrintStackTrace(); return(string.Empty); } catch (FirebaseAuthInvalidCredentialsException e) { e.PrintStackTrace(); return(string.Empty); } }
public async Task <IUsuario> LoginWithEmailPassword(string email, string password) { try { IAuthResult user = await FirebaseAuth.Instance.SignInWithEmailAndPasswordAsync(email, password); GetTokenResult tokenResult = await user.User.GetIdTokenAsync(false); Usuario usr = new Usuario(); usr.Uid = user.User.Uid; usr.Token = tokenResult.Token; usr.Nome = user.User.DisplayName; usr.Email = email; usr.DtLastLogin = DateTime.Now; return(usr); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <string> GetTokenAsync(string UserInfo, CancellationToken cancellationToken) { await OutputProtocol.WriteMessageBeginAsync(new TMessage("GetToken", TMessageType.Call, SeqId), cancellationToken); var args = new GetTokenArgs(); args.UserInfo = UserInfo; await args.WriteAsync(OutputProtocol, cancellationToken); await OutputProtocol.WriteMessageEndAsync(cancellationToken); await OutputProtocol.Transport.FlushAsync(cancellationToken); var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken); if (msg.Type == TMessageType.Exception) { var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken); await InputProtocol.ReadMessageEndAsync(cancellationToken); throw x; } var result = new GetTokenResult(); await result.ReadAsync(InputProtocol, cancellationToken); await InputProtocol.ReadMessageEndAsync(cancellationToken); if (result.__isset.success) { return(result.Success); } throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "GetToken failed: unknown result"); }
public AuthTokenResultWrapper(GetTokenResult getTokenResult) { _getTokenResult = getTokenResult ?? throw new ArgumentNullException(nameof(getTokenResult)); }