Angular 2 JWT是否有未经验证的重定向器?

Angular 2 JWT是否有未经验证的重定向器?,angular,authentication,jwt,angular2-jwt,Angular,Authentication,Jwt,Angular2 Jwt,我来自angular 1,我使用JWT令牌对用户进行身份验证。在angular 1中,我有以下内容: .config(function Config($httpProvider, jwtOptionsProvider) { // Interceptor for token push on every $http request jwtOptionsProvider.config({ tokenGetter: ['storageService

我来自angular 1,我使用JWT令牌对用户进行身份验证。在angular 1中,我有以下内容:

.config(function Config($httpProvider, jwtOptionsProvider) {
        // Interceptor for token push on every $http request
        jwtOptionsProvider.config({
            tokenGetter: ['storageService', function (storageService) {
                return storageService.getToken();
            }],
            whiteListedDomains: ['127.0.0.1', 'localhost'],
            unauthenticatedRedirector: ['$state', 'authManager', 'storageService', 'jwtHelper', function ($state, authManager, storageService, jwtHelper) {
                if (storageService.getToken() != null) {
                    if (jwtHelper.isTokenExpired(storageService.getToken())) {
                        alert('Su sesión ha caducado.');
                    }
                }

                storageService.removeToken();
                storageService.clearAll();
                authManager.unauthenticate();
                $state.go('autorepuestos_fe');
            }],
            unauthenticatedRedirectPath: '/login'
        });

        $httpProvider.interceptors.push('jwtInterceptor');
    })
这是拦截器。我从Angular 2的JWT官方页面了解到,我可以轻松拦截用户的路由,并使用AuthGuard重定向它。这没关系,我用过,效果很好。但是,我的问题是。。。在此版本的Angular 2 JWT上是否有未经验证的重定向器?这样,如果用户向我的后端的任何端点发出请求,则会自动显示一条消息并将其重定向到登录页面


你知道我该怎么做吗?我在考虑放置一个函数,该函数拦截对任何端点的每次调用,并首先验证令牌是否有效,如果这是真的,则发出请求。。。但是听起来很复杂。

在Angular 2&4中重定向到登录可以通过路由中的“canActivate”完成,如果需要,您可以添加一些消息

这是我的AuthGuard路由设置

{ path: 'secret', component: SecretComponent, canActivate: [ AuthService] }
public canActivate() {
    if (this.checkLogin()) {
        return true;
    } else {
        this.router.navigate(['login']);
        return false;
    }
}
然后在我的守卫里

{ path: 'secret', component: SecretComponent, canActivate: [ AuthService] }
public canActivate() {
    if (this.checkLogin()) {
        return true;
    } else {
        this.router.navigate(['login']);
        return false;
    }
}
要显示ASP.NET Angular JWT解决方案的完整详细信息,请执行以下操作:

库中,提供一些用于在angular+2中验证jwt的工具