angular - 在 Angular 8 中使用 JWT 和 SwaggerUI Bundle 进行预身份验证
问题描述
我正在尝试将 SwaggerUiBundle 集成到角度应用程序中。从创建的 url 获取请求时,我不必再次授权它并使用存储在 localStorage 中的当前 JWT 令牌发送以在 swagger 中使用 CRUD 请求。我无法将令牌存储在任何地方。我需要一些关于这个问题的帮助。谢谢大家。
ngOnInit() {
const ui = SwaggerUIBundle({
dom_id: '#swagger-ui',
layout: 'BaseLayout',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
url: url,
docExpansion: 'none',
operationsSorter: 'alpha',
securityDefinitions: {
JWT: {
type: "apiKey",
description: "",
name: "Authorization",
in: "header"
}
},
// requestInterceptor: function(request){
// console.log('[Swagger] intercept try-it-out request');
// let currentUser = hInterceptor.userService.currentUserValue;
// var token = `Bearer ${currentUser.token}`
// request.headers.Authorization = token;
// return request;
// }
// requestInterceptor: function(request){
// var rq = new HttpRequest(
// "GET",
// request.url,
// request.body, {
// headers: new HttpHeaders(request.headers),
// responseType: request.responseType,
// })
// hInterceptor.intercept(rq, new HttpXhrBackend({ build: () => new XMLHttpRequest }));
// }
}
解决方案
推荐阅读
- r - 将一列拆分为多列,同时防止前导零掉入拆分列
- r - 使用 seq 在 R 中打印偶数行文本
- laravel - 使用 Laravel 迁移更新枚举选项
- join - 有条件的更新/插入行
- jquery - Jquery .get函数不读取txt文件
- selenium - 如何获取 selenium 中子项的标记名作为字符串并根据标记名类型执行操作
- java - java.util.ArrayList 无法转换为 com.android.billingclient.api.SkuDetails
- javascript - 如何使用索引迭代 json 文件并使用本机组件进行渲染?
- python - 如何替换多个索引处的字符串(Python)?
- javascript - 我如何在没有订单的情况下填充托盘架存储?