I'm facing this issue - I'm integrating GitLab to my application once I login into GitLab through my application after I disconnect how to clear the GitLab cookies using revoke. if I'm again login to GitLab through my application it should ask for new user login details.

This code was not working - It is directly logged into the old GitLab lab credentails without asking for new user credentials

signOut(): void {

    const token = localStorage.getItem('gitlab_access_token');
    if (token) {
      // Revoke access token
      this.revokeToken(token).subscribe(
        () => {
          console.log('Access token revoked successfully');
          // Clear cache data
          localStorage.clear();
          console.log('localStorage is cleared');
          // Redirect user
          window.location.href = 'http://localhost:4200';
        }
      );
    } else {
      // If token is not found, simply clear cache data and redirect user
      localStorage.clear();
      console.log('localStorage is cleared');
      window.location.href = 'http://localhost:4200';
    }
  }


  revokeToken(token: string): Observable<any> {


    const parameters = `client_id=${this.gitlabClientId}&client_secret=${this.gitlabClientSecret}&token=${token}`;

    const headers = new HttpHeaders({
      'Content-Type': 'application/x-www-form-urlencoded'
    });

    return this.http.post<any>('https://gitlab.com/oauth/revoke', parameters, { headers });
  }
0

There are 0 best solutions below