title: SpringBoot with Keycloak authenticate from query parameter as well as header
body: <p>I have a Springboot application working with Keycloak where Keycloak automatically authenticates the request based on the Authorization: Bearer &lt;&gt; header.  I have a case where I need to have a direct URL link without the ability to add headers and I'd like to encode the token as a query parameter in that case.</p>
  <p>Can anyone suggest a good way to both use a Authentication header as well as a ?token=xxx mode for validation?</p>
  <p>Here is my Spring security setup:</p>
  <pre><code>   @Autowired
      public void configureGlobal(
              AuthenticationManagerBuilder auth) throws Exception {
  
          KeycloakAuthenticationProvider keycloakAuthenticationProvider
                  = keycloakAuthenticationProvider();
          keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(
                  new SimpleAuthorityMapper());
          auth.authenticationProvider(keycloakAuthenticationProvider);
      }
  
      @Bean
      public KeycloakConfigResolver KeycloakConfigResolver() {
          return new KeycloakConfigResolver() {
              @Override
              public KeycloakDeployment resolve(HttpFacade.Request request) {
                  KeycloakDeployment deployment = null;
                  AdapterConfig adapterConfig = new AdapterConfig();
                  adapterConfig.setAuthServerUrl(System.getProperty(&quot;keycloak.auth-server-url&quot;));
                  adapterConfig.setRealm(System.getProperty(&quot;keycloak.realm&quot;));
                  adapterConfig.setResource(System.getProperty(&quot;keycloak.resource&quot;));
  //                adapterConfig.setUseResourceRoleMappings(true);
                  adapterConfig.setSslRequired(&quot;external&quot;);
                  adapterConfig.setPublicClient(true);
                  deployment = KeycloakDeploymentBuilder.build(adapterConfig);
                  return deployment;
              }
          };
      }
  </code></pre>