title: Infinite redirect when logged in my angular keycloak application
body: <p>My application experiences an infinite redirect after what seemed to be my first successful login.</p>
  
  <p>The url I can see in the browser is:</p>
  
  <pre><code>http://localhost:4200/#state=04e2f6b5-4998-473b-91fc-bc77c8482796&amp;session_state=3ffbf15e-464a-4a6a-afe7-d82a8be58797&amp;code=eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..abvyusExa2W6OSNnGosqpw.bKGSzVqZtc9ZxOgVEwmACOJ_zXdmdNsnzU1rbHOSlEhPVkqiJuQUjOHk2LHny7zC0qFqKI5BgdAeQjBJOyar-tkf2Jy-aYO4EBbZ1kkA2CPdqzJOmf3Y740LaqGP_GvaEuiTNRA50El3L9laVYmyEmEGbFXs9t5p7rr-juDG7itTTExoW92Dx4WuLwR_ocsrOG8U74ARpj_CuF6wXxOty3XoDHbKpddFTbLH48gOAdHK1Fj0FTh5rPk9kXCVVUlX.uxT-1uwvGKpBF1bLBi5BvA
  </code></pre>
  
  <p>Using the Keycloak admin console, I created:</p>
  
  <pre><code>- a demo realm with the `demo-keycloak` id
  - a demo-frontend client (openid-connect, public, root url http://localhost:4200, valid redirect uris /*, web origins http://localhost:4200)
  - a demo-backend client (openid-connect, bearer-only)
  </code></pre>
  
  <p>My application is using the <code>https://github.com/mauriciovigolo/keycloak-angular</code> dependency.</p>
  
  <p>I configured it as:</p>
  
  <pre><code>export async function keycloakInitializer(keycloak: KeycloakService) {
    await keycloak.init({
      config: {
          url: 'http://localhost:8180/auth/',
          realm: 'demo',
          clientId: 'demo-frontend'
      },
      initOptions: {
          onLoad: 'login-required',
          checkLoginIframe: false
      },
      bearerExcludedUrls: [
        '/login',
      ]
    });
  }
  
  @NgModule({
    imports: [
      KeycloakAngularModule,
      HttpClientModule
    ],
    providers: [
      KeycloakClientService,
      AuthService,
      AuthGuardService,
      {
        provide: APP_INITIALIZER,
        useFactory: keycloakInitializer,
        multi: true,
        deps: [KeycloakService]
      }
    ]
  })
  </code></pre>
  
  <p>I wonder where should I configure the <code>demo-backend</code> client. Or, if I need to have two clients instead of just one...</p>
  
  <p>EDIT: I can see the network tab of the debugger shows one failing request, saying it fails to load the response data.</p>
  
  <pre><code>Request URL: http://localhost:8180/auth/realms/demo/protocol/openid-connect/token
  Referrer Policy: no-referrer-when-downgrade
  Request Headers
  Provisional headers are shown
  Content-type: application/x-www-form-urlencoded
  Origin: http://localhost:4200
  Referer: http://localhost:4200/
  User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Mobile Safari/537.36
  Form Data
  view source
  view URL encoded
  code: eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..Mn0FpnSHx-BYZm_8jNZAQQ.DI3Ph2nz6b43mHGWHFTvsL1414CpYC6eQK6E3rzK1D6t5eQ08IKTP2x57-cUnR9PNwLXPJbLeR1h_yqHp4hfE75TSBUrztu9Rg0PXqHh-S2FcHnTldUWLVnsJ57w-5eOGhlpMq1vUM9sUMxKmRksZi3eveGTQLZI2YDGhlGMO-gOELeyC1tbRMoejUxqU3qCZ48TME5VZjzcN0vkA9ifg482STg5sUdRePBpdxjAw07xCT855KnNVsOf7M2atqHU.HdVXW57ZeDtUEdS8XbR-Pg
  grant_type: authorization_code
  client_id: demo-frontend
  redirect_uri: http://localhost:4200/?redirect_fragment=state%3D6d989fa7-30bd-4dd6-8834-d09ac5e3c1c1%26session_state%3D3710ad77-29f5-4e38-af47-083b7f318ace%26code%3DeyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..U4fPpqwk4wg7a3AKAbiffA.yVZbYwQMJPAtsgvnvMVpc8zNwyBsPnl9XvX2WzDEmDZdYJGjUVpCRBWPn1OwY0xWpWUK3DsbD5n9ATeGVkwLNRt42pTuH0dgmhEMvSeuZ_nY4E2_MV_30Z9ElmsaaOmmuXm1AcrAKRl6uX1OjKwQAj4Rjqo0r6v6Cmv5FBrz3q3nsiUxXeUZpdDtkBuuUU-JFTOgD5taowQwxHjovpOJYMmddjq9RFwR-IhX3NnHl-Mh2smYoyjEMFhPYkKSNr-n.TkfNegnxHwKz62U_jAuOiQ
  </code></pre>