keycloakkeycloak-connect

Keycloak login ith chrome extension


I'm being started to implement keycloak SSO authentication on an existing homemade chrome extension in pure JS. Keycloak server is well configured, i've checked that. I'm able to import keycloak.json on background.js. I'm able to init keycloak object : enter image description here

But i'm a bit lost about login. A click on login button should call keycloak.login function. A simple keycloak.login({redirectUri:${url_extension_bckg}?action=login}); obviously doesn't work. So i've found 1 example but running with angular :

async function login() {
  try {
    browser.identity.launchWebAuthFlow(
      {url: `https://AUTH_URL/auth/realms/realmName/protocol/openid-connect/auth?client_id=client&action=login`, interactive: true},
      (redirectURL) => {
        browser.extension.getBackgroundPage().console.log('result', redirectURL);
      }
    )
  } catch (err) {
    console.log(err);
  }
  
}

I've tried this but get "invalid parameter : redirect_uri". enter image description here I can't achieve to build login URL.

Help would be appreciate. I checked documentation but keycloak SSO check with chrome extension seems pretty rare...

Thanks in advance


Solution

  • I found the way :) Using control of storage token, which is always removed when i ask a log out on my extension. I just check on popup if stored token is present. If not i call login function, which verify by SSO if still logged. If not, redirect to keycloak template login page.