How can I do forcible logout and renew token using angular-auth-oidc-client?

80 views Asked by At

I am using angular-auth-oidc-client in Angular15 application to authenticate with AWS cognito.

I want to forcibly logout the current session and renew the token on application initialization every time

I tried the following options but I don't see a new token in the browser n/w tab whenever I manually refresh the page.

{
        provide: APP_INITIALIZER,
        useFactory: (oidcSecurityService: OidcSecurityService) => {
            return () => {
                const app_client_id: string = 'application cognitoAppClientId';
                const config_id: string = 'application cognitoUserPoolId';
                
                if (app_client_id) {
                    const customParams: {[key: string]: string} = {
                        client_id: 'xxxxxxxxxx',
                        redirect_uri: 'application base url',
                        response_type: 'code',
                        scope: 'openid profile',
                        logout_uri: 'application base url',
                    };
                    const logoutAuthOptions: LogoutAuthOptions = {
                        customParams: customParams,
                    };

                   // Below are the options I tried
                   **Option 1:**
                    oidcSecurityService.logoff().subscribe((result: any) => {});
                   Option 2: 
                    oidcSecurityService.logoffAndRevokeTokens().subscribe((result: any) => {});
                    **Option 3:**
                    oidcSecurityService.logoff(config_id, logoutAuthOptions).subscribe((result: any) => {});
                    **Option 4:**
                    oidcSecurityService
                         .logoffAndRevokeTokens(config_id, logoutAuthOptions)
                         .subscribe((result: any) => {});
                    **Option 5:**
                     oidcSecurityService.logoffLocal(config_id);
                    **Option 6:**
             oidcSecurityService.forceRefreshSession(customParams).subscribe((result: any) => {});
                }
            };
        },
        deps: [OidcSecurityService],
        multi: true,
    },

Expectation is getting new token on browser tab refresh.

0

There are 0 answers