How do I log out of a chrome.identity oauth provider

前端 未结 8 1963
一生所求
一生所求 2020-12-01 16:52

I\'m using chrome.identity to log into a 3rd party oauth provider in an chrome extension. It works fine for logging in- when I use launchWebAuthFlow I am presented with the

相关标签:
8条回答
  • 2020-12-01 17:02

    You should add prompt=select_account to your auth URL. Your problem will be solved.

    https://accounts.google.com/o/oauth2/auth?client_id={clientId}&response_type=token&scope={scopes}&redirect_uri={redirectURL}&prompt=select_account

    0 讨论(0)
  • 2020-12-01 17:02

    I could achieve result only with this implementation

      chrome.identity.getAuthToken({ 'interactive': false }, currentToken => {
        if (!chrome.runtime.lastError) {
          // Remove the local cached token
          chrome.identity.removeCachedAuthToken({ token: currentToken }, () => {})
    
          // Make a request to revoke token in the server
          const xhr = new XMLHttpRequest()
          xhr.open('GET', `${googleRevokeApi}${currentToken}`)
          xhr.send()
    
          // Update the user interface accordingly
          // TODO: your callback
        }
      })
    
    0 讨论(0)
  • 2020-12-01 17:08

    I happened to hit the same problem recently, and I finally solved it by adding login_hint=<new_user> and prompt=consent in the login URL.

    0 讨论(0)
  • 2020-12-01 17:16

    For me, https://accounts.google.com/logout does not work. But https://accounts.google.com/o/oauth2/revoke?token=TOKEN work well, using simple window.fetch(url), not with hrome.identity.launchWebAuthFlow.

    0 讨论(0)
  • 2020-12-01 17:17

    I am not aware about the specific third party provider. But I faced the similar problem when using Google Oauth with chrome.identity.launchWebAuthFlow(). I could sign in the user, but not sign out using removeCachedAuthToken()

    In this case, to logout the user, I used chrome.identity.launchWebAuthFlow() with Google's logout URL rather than it's oauth URL

    chrome.identity.launchWebAuthFlow(
        { 'url': 'https://accounts.google.com/logout' },
        function(tokenUrl) {
            responseCallback();
        }
    );
    

    This worked pretty well.

    0 讨论(0)
  • 2020-12-01 17:26

    I've found that calling these two in the sequence is working:

    var url = 'https://accounts.google.com/o/oauth2/revoke?token=' + token;
    window.fetch(url);
    
    chrome.identity.removeCachedAuthToken({token: token}, function (){
      alert('removed');
    });
    
    0 讨论(0)
提交回复
热议问题