【问题标题】:problems to validate information in jwt在 jwt 中验证信息的问题
【发布时间】:2021-10-17 05:20:13
【问题描述】:

如何对已经完成的数据进行数据认证。使用 jwt 比较该数据以验证信息。 我有一个带有 springboot 安全库的 spring 应用程序,我正在使用 angular 在 JWT 中进行验证,我需要读取 mysql 数据库中的纯文本文件,我该如何验证信息。 当用户登录时,它会使用数据库中的信息进行验证。

login(): void {
    console.log(this.usuario);
    if (this.usuario.username == null || this.usuario.password == null) {
      swal('Error Login', 'Username o password vacías!', 'error');
      return;
    }

    this.authService.login(this.usuario).subscribe(response => {
      console.log(response);

      this.authService.guardarUsuario(response.access_token);
      this.authService.guardarToken(response.access_token);
      let usuario = this.authService.usuario;
      this.router.navigate(['/clientes']);
      swal('Login', `Hola ${usuario.username}, has iniciado sesión con éxito!`, 'success');
    }, err => {
      if (err.status == 400) {
        swal('Error Login', 'Usuario o clave incorrectas!', 'error');
      }
    }
    );
  }

【问题讨论】:

  • 阅读您的问题并不清楚您要解决的问题。您的代码与login 操作相关,但您提到Using jwt to compare that data to validate information,您要做什么?在@JuanBerzosaTejero 的回答中,他认为您的问题与如何在每个“登录后”请求中发送JWT token 有关。所以,问题还是一样,你要解决的具体用例是什么?
  • 我同意@dotore

标签: angular spring spring-security jwt


【解决方案1】:

为了获得帮助,您应该提供更多信息...

但是,基本上,您需要一个拦截器,对于每个 http 调用,将其插入头部:

 setHeaders: {
            Authorization: `Bearer ${token}`,
          }

P.S:由于您的代码变量名称,我猜您会说西班牙语,因此本指南将帮助您: https://medium.com/@insomniocode/angular-autenticaci%C3%B3n-usando-interceptors-a26c167270f4

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 2019-07-28
    • 2021-02-11
    • 2016-06-27
    • 1970-01-01
    • 2017-08-06
    • 2019-12-04
    • 2019-07-29
    • 1970-01-01
    相关资源
    最近更新 更多