Spartacus storefront 刷新令牌功能
如何使刷新令牌功能正常工作? 我在本地存储中没有看到刷新令牌,这是因为core在storemodule配置中没有它Spartacus storefront 刷新令牌功能,spartacus-storefront,Spartacus Storefront,如何使刷新令牌功能正常工作? 我在本地存储中没有看到刷新令牌,这是因为core在storemodule配置中没有它 export function authStoreConfigFactory(): StateConfig { // if we want to reuse AUTH_FEATURE const in config, we have to use factory instead of plain object const config: StateConfig = {
export function authStoreConfigFactory(): StateConfig {
// if we want to reuse AUTH_FEATURE const in config, we have to use factory instead of plain object
const config: StateConfig = {
state: {
storageSync: {
keys: {
'auth.userToken.token.access_token': StorageSyncType.LOCAL_STORAGE,
'auth.userToken.token.token_type': StorageSyncType.LOCAL_STORAGE,
'auth.userToken.token.expires_in': StorageSyncType.LOCAL_STORAGE,
'auth.userToken.token.expiration_time': StorageSyncType.LOCAL_STORAGE,
'auth.userToken.token.scope': StorageSyncType.LOCAL_STORAGE,
'auth.userToken.token.userId': StorageSyncType.LOCAL_STORAGE,
},
},
},
};
return config;
}
正确的使用方法是什么?出于安全原因,在默认存储同步配置中故意省略了刷新令牌 但是,如果需要,您可以始终提供自己的存储同步配置,如下面的示例所示。它不会覆盖默认配置,但会与之结合。要从默认配置中排除某些内容,可以使用类似于
storageSync
配置中的keys
属性的excludeKeys
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { translationChunksConfig, translations } from "@spartacus/assets";
import { ConfigModule, StateConfig, StorageSyncType } from "@spartacus/core";
import { B2cStorefrontModule } from "@spartacus/storefront";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
export function refreshTokenConfigFactory(): StateConfig {
const config: StateConfig = {
state: {
storageSync: {
keys: {
"auth.userToken.token.refresh_token": StorageSyncType.LOCAL_STORAGE
}
}
}
};
return config;
}
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
AppRoutingModule,
B2cStorefrontModule.withConfig({
backend: {
occ: {
baseUrl: "http://localhost:9002",
prefix: "/rest/v2/"
}
},
context: {
baseSite: ["electronics-spa"]
},
i18n: {
resources: translations,
chunks: translationChunksConfig,
fallbackLang: "en"
},
features: {
level: "1.5",
anonymousConsents: true
}
}),
ConfigModule.withConfigFactory(refreshTokenConfigFactory),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}