【发布时间】:2021-06-08 12:20:53
【问题描述】:
我在项目的 Angular 和 Identity Server 中使用 angular-oauth2-oidc 库。而我使用的另一个客户端是MVC。 当我在 MVC 上注销时,我想在 Angular 中注销。但是令牌在 Angular 应用程序中不会过期。 当我去 Angular 应用程序时,我得到了授权用户。我明白了
this.oauthService.hasValidAccessToken(); // 是的
我的角度设置:
const authConfig: AuthConfig = {
clientId: this.configurationService.config.audience,
issuer: `${this.configurationService.config.issuer}`,
redirectUri: `${location.origin}/auth-callback`,
loginUrl: `${this.configurationService.config.issuer}/connect/authorize`,
logoutUrl: `${this.configurationService.config.issuer}/connect/revocation`,
requestAccessToken: true,
clearHashAfterLogin: true,
responseType: 'id_token token',
sessionChecksEnabled: true,
showDebugInformation: true,
postLogoutRedirectUri: `${this.configurationService.config.issuer}/Account/Logout`,
requireHttps: this.configurationService.config.requireHttps,
scope: this.configurationService.config.scope,
};
身份设置:
new Client
{
AccessTokenType = AccessTokenType.Jwt,
RefreshTokenExpiration = TokenExpiration.Absolute,
AccessTokenLifetime = coreSettings.AbsoluteRefreshTokenLifetimeInSeconds,
IdentityTokenLifetime = coreSettings.AbsoluteRefreshTokenLifetimeInSeconds,
UpdateAccessTokenClaimsOnRefresh = true,
AllowOfflineAccess = true,
ClientId = "jsclient",
ClientName = "JavaScript client",
ClientSecrets =
{
new Secret("personal-cabinet".Sha256())
},
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
AlwaysIncludeUserClaimsInIdToken = true,
RequireConsent = false,
RedirectUris =
{
$"{coreSettings.PersonalCabinet}/auth-callback"
},
PostLogoutRedirectUris =
{
coreSettings.IdentityServer
},
AllowedCorsOrigins =
{
coreSettings.PersonalCabinetApiService,
coreSettings.PersonalCabinet
},
AllowedScopes =
{
StandardScopes.OpenId,
StandardScopes.Profile,
"personal-cabinet-api"
}
}
如何在 Angular 中使令牌过期?也许需要我添加一些注销网址? 我在设置中添加
logoutUrl:
${this.configurationService.config.issuer}/connect/revocation
但它不起作用。
也许我需要发送一些用于注销的 url?
有什么想法吗?谢谢
【问题讨论】:
-
如何在客户端存储令牌?你不能在注销时删除令牌吗?或者您是否有必须过期的用例?
-
@tcrite 我可以在 this.oauthService.getAccessToken() 中获取令牌。 oauthService - 来自“angular-oauth2-oidc”的 OAuthService 的类实例。此类具有注销方法 - this.oauthService.logOut(); 但是如何从 Identity Server 调用此方法?
标签: angular asp.net-mvc oauth identityserver4 openid-connect