简体   繁体   English

如何在 ngx-admin 中添加 JWT 身份验证?

[英]How can I add the JWT authentication in ngx-admin?

I've looking for a while for how I can implement the JWT interceptor and auth guard in the ngx-admin without any success.我一直在寻找如何在 ngx-admin 中实现 JWT 拦截器和身份验证保护而没有任何成功。 How can I do that?我怎样才能做到这一点?

I've tried following @WebVbn's tutorial in this thread, Add JWT automatically for every HTTP request #1375 , but it didn't work and honestly I'm still kinda new to this whole angular and ngx-admin stuff我已经尝试在这个线程中遵循@WebVbn 的教程,为每个 HTTP 请求自动添加 JWT #1375 ,但它没有用,老实说,我对整个 angular 和 ngx-admin 的东西还是有点陌生

that's how to configure it in your front-end to support JWT.这就是如何在前端配置它以支持 JWT。

Of course your back-end should support it, and you can configure your routes as you wish, this is just an example当然你的后端应该支持它,你可以随意配置你的路由,这只是一个例子

  export const NB_CORE_PROVIDERS = [
  ...DataModule.forRoot().providers,
  ...NbAuthModule.forRoot({

    strategies: [

      NbPasswordAuthStrategy.setup({
        name: 'email',
        baseEndpoint:"http://localhost:8080/api/",
      requestPass:false,
      logout:{ 
        endpoint:'auth/logout',
        method:'post',
        requireValidToken:true
      },
      resetPass:{
        endpoint:"auth/reset",
        redirect:{
          success:"/",
          failure:"/auth/login"
        }
      },
      refreshToken:{
        endpoint:'auth/refresh',
        method:"post"
      },
        login: {
          endpoint: 'auth/login',
          method:"post",
          redirect:{
            success:"/pages"
          },
          requireValidToken:true
        },
        token: {
          class: NbAuthJWTToken,
          key:'token'
        }
      }),
    ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM