问题标签 [angular2-jwt]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
3804 浏览

angular - 刷新我的 Angular 6 项目的页面时出现 403 错误

我有一个 Angular 6 项目,其 JWT 授权部署在 AWS Elastic Beanstalk 中并使用 CloudFront,我使用 @auth0/angular-jwt 库进行管理。一切正常,我有一个指向我的页面的链接,该链接将授权令牌附加到请求中:

这由我的 AuthGuard 服务处理:

在我的 AppRoutes 中:

在我的 AuthService 中:

在我的 AuthStore 中:

因此,当我单击链接时,应用程序会正确加载仪表板组件,并像这样更改 URL:

在这里,如果我按 F5 键刷新页面,我会收到以下错误:

提前致谢。

更新:这是与 CloudFront 相关的问题,资源“仪表板”不存在,因此它返回拒绝访问,如何防止/管理这些类型的事件(F5 键)角度?

0 投票
2 回答
1320 浏览

angular - 如果我们有效的令牌,Angular6 auth0/angular2-jwt isTokenExpired 函数总是返回 false

我正在使用 auth0/angular2-jwt 包来处理 Angular6 应用程序中基于 JWT 令牌的身份验证。如果我们给了有效的令牌isTokenExpired函数总是返回 false

我尝试过的以下代码:

我已经尝试了以上两种方法,它总是返回false

提前致谢。

0 投票
5 回答
43243 浏览

angular - 如何在角度 6 中发送 JWT 令牌作为授权标头

目前我在组件 .ts 文件中使用了这个静态代码,但这一个不起作用。它返回未经授权的(401)。但是当我将令牌作为查询字符串传递时,它工作正常。请为组件 .ts 文件提供一个工作示例。

0 投票
0 回答
706 浏览

angular - Angular 5发送请求时如何防止Spring安全登录重定向302

我总是得到 302 响应而不是 JSON 响应(200 OK),当我尝试使用 Spring Boot JWT 登录时,是否有任何合理的方法可以阻止 Spring Security 在成功身份验证后重定向我的 http 请求,顺便说一句,我正在使用角度 5 HttpClient 向 Spring boot 发送 Http 请求。我已经尝试了网络上的所有解决方案,但不幸的是它们都不起作用!!!

JWT授权码:

0 投票
1 回答
1892 浏览

angular - Angular 6 中的 AuthHttp(从 Angular2 迁移到 Angular6)

我最近将我的应用程序从Angular2迁移到Angular6

由于 Angular2-JWT,我的构建失败了,所以我将它升级到@auth0/angular-jwt

现在我在更新我的代码时卡住了,因为 AuthHTTP 和 AuthConfig 已被弃用。

我的 security.module.ts 有一个 factory.ts。而且我必须将一个新的 AuthHttp 返回到我的 security.module.ts。

现在我在返回 AuthHttp 时遇到错误。

我的 Security.Module.ts 如下。

我在提供时遇到错误:AuthHttp 也。

任何帮助表示赞赏。

0 投票
2 回答
48 浏览

jwt - localstorage 值仅在页面重新加载后可见

当用户登录时,我想在导航栏中显示该用户的用户名。用户成功登录后,我已将令牌和用户名设置为 localStorage。我的问题是除非我刷新页面,否则用户名不会显示在导航栏中。

我不确定如何解决此问题。

有谁能够帮我

谢谢你。

登录组件

认证服务

令牌服务

导航栏组件

0 投票
0 回答
49 浏览

angular - auth0 令牌:编译失败

我一直在从头学习 Asp.net core 和 angular

我正在看一个视频。而且我确信我正在按照视频中的说明进行操作。

我使用 npm 安装了库

然后我有这个错误

它的原因是什么?我重新观看视频三次以找出问题所在,但我无法解决。

当我导入JwtHelperService我正在使用的编辑器的智能感知时pops up。所以我假设 JwtHelperService 安装正确。

我还添加了jwtHelper = new JwtHelperService();变量

并创建了这样的方法

但是错误从何而来?我该如何解决?

更新:

当我添加变量时它给了我错误

问候, 拉蒙

0 投票
0 回答
231 浏览

angular - Angular2-jwt:拦截请求的 api 路由

我正在实现一个 jwt 刷新机制。我在 Angular 7 中使用auth0/angular2-jwt。当我访问受保护的路由时,我access_token在 Authorization 标头中向 /api/v1/protected 发送请求。当我需要刷新 jwt 令牌时,我必须refresh_token在 Authorization 标头中向 /api/v1/auth/refresh 发送请求。我想不通的是如何根据 api 路由选择要发送的令牌。

app.module.ts

令牌服务.ts

我的计划 B 是将 angulat-jwt 中的刷新路由列入黑名单并编写自定义拦截器。但我想知道是否有什么我搞砸了。这是否可以在我的令牌服务中拦截 api 调用(检查 api 路由)?

0 投票
0 回答
193 浏览

angular - JWT angular spring boot. checking authentication for user null

I have a problem when consuming services with a token using JWT. When I consume the service to obtain the token, it works perfectly and I return the token to consume the services, but when sending the headers it does not work correctly and it returns error 401. I have looked many times at the source code, and I do not see any error about it .

In spring boot in console it appears that a null user arrives:

enter image description here

enter image description here

enter image description here

in postman the services work without any problem, sending the token in the header. I do not know what I'm doing wrong.

enter image description here

enter image description here

enter image description here

thanks for your help

0 投票
1 回答
283 浏览

angular - 将 Angular 从 4 升级到 6 时使用 angular2-jwt 和 AuthHttp 的问题

我正在尝试将 angular4 应用程序更新为 angular6,并且我正在使用 angular2-jwt 向 web api 发送身份验证,但是在 angular6 中我发现了这个错误: TypeError: Observable_1.Observable.defer is not a function 请参阅此处的错误

这是我创建令牌的地方

这是我的 HttpServiceFactory