title: Keycloak Capacitor Adapter - Auth Redirect Problem
body: <p>We are using Ionic Vue (5.4.0 - Vue3) with Capacitor and Keycloak as the Auth Provider. We have implemented the <a href="https://www.npmjs.com/package/keycloak-ionic" rel="nofollow noreferrer">https://www.npmjs.com/package/keycloak-ionic</a> Package which provides the Capacitor Adapter. We have set up the required deeplinks for both platforms and they are working. The app should authenticate the user in the system browser (capacitor-native adapter), save the tokens and reuse these tokens on the next appstart. It's working on android. On iOS the first startup is working but if i restart (terminating and starting again) i only see a blank screen. It's not redirecting into the secured content or showing the keycloak login page. I found out that the Safari Browser with the keycloak login is opened in the background. If i close this browser tab and start the app it's working by redirecting me to the keycloak login page.</p>
  <p>May the browser with the opened keycloak instance be the problem?</p>
  <p>I also tried the same with inappbrowster (capacitor adapter). The first start is working there also. If i restart the app the custom tab is opening the redirect url page without redirecting me to the secured content or to the keycloak login page.</p>
  <p>Code Sample:</p>
  <pre><code>App.addListener('appUrlOpen', function (data: any) {
    const slug = data.url.split('/kc1').pop()
  
    // We only push to the route if there is a slug present
    if (slug) {
      router.push({ name: 'Overview' })
    }
  })
  
  // init authentication
  const initKeycloak = async () =&gt; {
    const cachedKeycloak = new CacheUtil('keycloak')
    const cachedKeycloakAccessToken = await cachedKeycloak.get('accessToken')
    const cachedKeycloakRefreshToken = await cachedKeycloak.get('refreshToken')
  
    const initOptions = { url: process.env.VUE_APP_AUTH_URL + '/auth', realm: 'mp', clientId: 'mobile', checkLoginIframe: false, onLoad: 'login-required', token: cachedKeycloakAccessToken, refreshToken: cachedKeycloakRefreshToken }
    const keycloak = KeycloakIonic(initOptions)
  
    keycloak.init({
      adapter: 'capacitor-native',
      pkceMethod:'S256',
      onLoad: initOptions.onLoad as any,
      redirectUri: process.env.VUE_APP_REDIRECT_URI
    }).then((auth: any) =&gt; {
      // auth and create app
      if (!auth) {
        console.log(auth)
      } else {
        const app = createApp(VueApp)
          .use(IonicVue)
          .use(router)
          .use(store)
  
        router.isReady().then(() =&gt; {
          app.mount('#app')
        })
      }
    }).catch((e: Error) =&gt; {
      console.log('auth failed: ', e)
    })
  
    keycloak.onAuthSuccess = () =&gt; {
      console.log('authenticated!')
  
      // save tokens to device storage
      cachedKeycloak.set('accessToken', keycloak.token)
      cachedKeycloak.set('refreshToken', keycloak.refreshToken)
    }
  }
  
  initKeycloak()
  </code></pre>