title: Keycloak Identity Broker API
body: <p>So i have a client which consumes an api. The API is secured with keycloak.
  Users signs in normally, but i want to allow users to sign in user without having to go keycloak's login page with their social media accounts like facebook or google.
  I need a rest API with an implementation of how to get a url generated so when user click on this url in a button, it will take the user to the respective social login page to login while keycloak still serves as the broker.</p>
  
  <p>Below is my implementation, it generates a url alright but does not take the user to google page to login</p>
  
  <p>This is a rest Controller</p>
  
  <pre><code>    @Secured("permitAll")
      @GetMapping(path = "/generator")
      public String brokerGenerator(HttpServletRequest httpServletRequest) throws ServletException {
          String provider = "google";
          String authServerRootUrl = "http://localhost:8080/";
          String realm = "realmName";
          String clientId = "clientName";
          String nonce = UUID.randomUUID().toString();
          MessageDigest md = null;
  
          try {
              md = MessageDigest.getInstance("SHA-256");
          } catch (NoSuchAlgorithmException e) {
              throw new RuntimeException(e);
          }
  
          String input = nonce + clientId + provider;
          byte[] check = md.digest(input.getBytes(StandardCharsets.UTF_8));
          String hash = Base64Url.encode(check);
          httpServletRequest.getSession().setAttribute("hash", hash);
  
          String redirectUri = "http://localhost:4200/dashboard"; 
  
          return KeycloakUriBuilder.fromUri(authServerRootUrl)
                  .path("auth/realms/realmName/google/link")
                  .queryParam("nonce", nonce)
                  .queryParam("hash", hash)
                  .queryParam("client_id", clientId)
                  .queryParam("redirect_uri", redirectUri).build(realm, provider).toString();
  
      }
  </code></pre>