CanActivate路由适用于不在服务器上的localhost

时间:2017-02-11 16:36:17

标签: angular auth0

我使用here进行身份验证。在我的角度应用程序中,我有一个AuthGuard,以防止在使用auth0进行身份验证时路由到角度应用程序。在身份验证期间,网址看起来像这样

     https://www.examplesite.com/#access_token=jlfdsfhWboAhvlRhbZt&expires_in=86400&id_token=aeryJ0eXAfsiOiJ..&token_type=Bearer&state=16d15855-0827-4189-bc34-26b981d578bb

该应用包含以下路线

export const ROUTES: Routes = [
 { path: '', loadChildren: './home/home.module#HomeModule', canActivate:    [AuthGuard] },
 { path: '**', redirectTo: '/' },
];

以下是AuthGuard:

@Injectable()
export class AuthGuard implements CanActivate {

constructor(private router: Router, private location: Location, private authService: AuthService) { }

   canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {

    if (route.fragment && route.fragment.startsWith('access_token')) {
        return false;
    }

    return true;
}
}

这在localhost上运行正常。 AccessToken路径出现,在消失后,应用程序正在成功加载。

但它不适用于已发布的服务器。它显示了accessstoken路径,它消失了应用程序未加载。

在控制台中,我收到此警告        #=的access_token rfsdf ...&安培; expires_in = 86400&安培; id_token = rfafsdf ...&安培; token_type =承载&安培;状态= 72e39d8b-7907-4fbb-88fb-1dd690622541:7    关键&#34;&#34;不被承认和忽视。

知道为什么这个在localhost上工作但不在服务器上工作?

1 个答案:

答案 0 :(得分:0)

问题在于Auth0和处理哈希。 https://github.com/auth0/lock/issues/527