在 Nestjs 中,我通过创建有效负载对象并对其进行签名来创建 JWT(令牌)。像这样的东西:
const jwtPayload: JwtPayload =
{
iss: issuer,
sub: info,
aud: audience,
// exp: - populated by fn: this.jwtService.sign(payload),
// iat: - populated by fn: this.jwtService.sign(payload),
jti: 'XXXX1234'
}
const signedJwtAccessToken: string = this.jwtService.sign(jwtPayload);
Run Code Online (Sandbox Code Playgroud)
Nest 将 jwtPayload 编码为字符串。
对于清理工作,我想知道 JWT 何时到期。这会通过 .sign() 函数自动编码到“ signedJwtAccessToken ”(属性.exp )中。
要在签名后立即访问它,需要对其进行解码。
在签署后立即以相同的方法解码签名的JwtAccessToken最简单的方法是什么???
笔记:
当 JWT 从客户端返回时,nestjs 在访问 fn: validate() 时对其进行解码,但我想在签名后立即解码 - 在将响应发送给客户端之前,如下所示:
// signing - encoding
const signedJwtAccessToken: string = this.jwtService.sign(jwtPayload);
// decoding
const decodedJwtAccessToken: string = decodeJwt(signedJwtAccessToken); …Run Code Online (Sandbox Code Playgroud) 我们知道
String s = new Object();
Run Code Online (Sandbox Code Playgroud)
会导致错误:
incompatible types: Object cannot be converted to String
Run Code Online (Sandbox Code Playgroud)
因此,从下面的例子来看,我们不能这样做:
Car car = new Vehicle();
Run Code Online (Sandbox Code Playgroud)
但是对于 Java 来说,如果有这样的东西会有什么问题:
超级班:
public class Vehicle {
String color;
int numberOfWheels;
int maxSpeed;
// etc.
}
Run Code Online (Sandbox Code Playgroud)
子类:
public class Car extends Vehicle {
String engineType;
String transmissionType;
int numberOfDoors;
// etc.
Car(Vehicle vehicle) {
// the theoretical idea of passing
// the superclass object within a subclass
super = vehicle;
}
}
Run Code Online (Sandbox Code Playgroud)
“超级=车辆;” 将允许我们一次性将先前设置的超类(车辆)的所有值传递给新的子类(汽车)。用法是:
public class App { …Run Code Online (Sandbox Code Playgroud) 首先 - 仅供参考,路由模块设置为:
@NgModule({
imports: [RouterModule.forRoot(ALL_ROUTES)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {}
Run Code Online (Sandbox Code Playgroud)
将所有路由放在 1 个名为:'ALL_ROUTES' 的数组中,并将该数组传递给 AppRoutingModule - 导入:[RouterModule.forRoot(ALL_ROUTES)],工作正常:
export const ALL_ROUTES: Routes = [
{path: 'route1', component: FirstComponent},
{path: 'route2', component: SecondComponent},
{path: 'route3', component: ThirdComponent},
{path: 'route4', component: FourthComponent}
];
Run Code Online (Sandbox Code Playgroud)
所以,上面的代码工作正常。但是,如果我们有 2 个数组并像这样连接它们:
export const ROUTES1: Routes = [
{path: 'route1', component: FirstComponent},
{path: 'route2', component: SecondComponent}
];
export const ROUTES2: Routes = [
{path: 'route3', component: ThirdComponent},
{path: 'route4', component: FourthComponent}
];
export const …Run Code Online (Sandbox Code Playgroud) There is a service used to read initial persisted values - "settings" and provide them via observable "settings$" to subscribers - components. Several components use the "settings$" observable to retrieve the initial persisted values and further exchange updated values among themselves. For that the BehaviorSubject is implemented in the service. All works well here.
@Injectable()
export class SettingsService implements OnInit {
settingsBS;
settings$: Observable<SettingsI>;
init() {
this.settingsBS = new BehaviorSubject<SettingsI>(defaultSettings);
this.settings$ = this.settingsBS.asObservable();
... …Run Code Online (Sandbox Code Playgroud) 我希望背景与主题颜色mat-sidenav相同mat-toolbar。
在src\styles.scss我有:
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
Run Code Online (Sandbox Code Playgroud)
我的模板/ HTML文件具有:
<mat-toolbar color="primary">
<button mat-icon-button (click)="sidenav.toggle()">
<mat-icon>menu</mat-icon>
</button>
Title text
</mat-toolbar>
Run Code Online (Sandbox Code Playgroud)
这很好地显示为带有menu图标和的靛蓝菜单栏Title text。在下面,我想要一个mat-sidenav(将具有菜单项),并且我希望该mat-sidenav区域的整个背景具有与该颜色相同的颜色:
<mat-toolbar color="primary">
Run Code Online (Sandbox Code Playgroud)
这是靛蓝-由主题定义。
HTML代码继续进行渲染mat-sidenav:
<mat-sidenav-container>
<mat-sidenav #sidenav mode="side" opened>
<app-vertical-menu></app-vertical-menu> // renders the menu items
</mat-sidenav>
<mat-sidenav-content>
<div class="app-main-area">
<router-outlet></router-outlet>
</div>
</mat-sidenav-content>
</mat-sidenav-container>
Run Code Online (Sandbox Code Playgroud)
的mat-sidenav背景和颜色都被应用的主题,不变和它的背景颜色是空白。
我知道我可以mat-sidenav使用模板中的类名在组件内设置背景样式-例如:
...
<mat-sidenav #sidenav2 mode="side" opened class="vertical-menu">
...
Run Code Online (Sandbox Code Playgroud)
并在style / scss文件中:
.vertical-menu {
background-color: navy !important;
}
Run Code Online (Sandbox Code Playgroud)
但是相反,我想应用默认主题的主题颜色(例如:) …
angular ×3
typescript ×2
concat ×1
css ×1
html ×1
inheritance ×1
java ×1
jwt ×1
nestjs ×1
nestjs-jwt ×1
observable ×1