【问题标题】:How can I expire token on client in Angular 6?如何在 Angular 6 中使客户端上的令牌过期?
【发布时间】: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


【解决方案1】:

您可以使用会话管理技术,它是 OIDC 标准:https://openid.net/specs/openid-connect-session-1_0.html

angular-oauth2-oidc 库支持此功能:https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/session-checks.html 您必须检查如何在 Identity Server 中启用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-22
    • 2022-11-29
    • 2020-02-09
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    相关资源
    最近更新 更多