# Spring App With Keycloak - authorization request not found error

**URL:** <https://forum.keycloak.org/t/spring-app-with-keycloak-authorization-request-not-found-error/25618>\
**Category:** Securing applications\
**Tags:** authentication\
**Created:** [April 17, 2024, 1:22pm UTC](https://forum.keycloak.org/t/spring-app-with-keycloak-authorization-request-not-found-error/25618 "2024-04-17T13:22:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WalkingBread](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/walkingbread/32/10247_2.png) [@WalkingBread](https://forum.keycloak.org/u/WalkingBread)\
**Post date:** [April 17, 2024, 1:22pm UTC](https://forum.keycloak.org/t/spring-app-with-keycloak-authorization-request-not-found-error/25618/1 "2024-04-17T13:22:06Z")

</div>

Hello, I am currently developing a spring app that integrates keycloak for user authentication. I have set up a realm along with a client so that the authentication runs successfully when manually fetching token via postman and then using it to access endpoints. However, when I try to login via browser I get [authorization\_request\_not\_found] after the login page.

 ![image](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/0/01d84f38706c0ae289a3546ef1da764608b38dc6.png)

This is my application.properties setup:

```auto
spring.main.banner-mode=off

spring.datasource.url=${DATASOURCE_URL}
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}

spring.jpa.properties.hibernate.default_schema=public
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none

spring.data.rest.base-path=api/

spring.liquibase.change-log=classpath:changelog-master.xml

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false

spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/certs

jwt.auth.converter.resource-id=${KEYCLOAK_RESOURCE}
jwt.auth.converter.principal-attribute=preferred_username

spring.security.oauth2.client.registration.keycloak.client-id=${KEYCLOAK_RESOURCE}
spring.security.oauth2.client.registration.keycloak.client-secret=${KEYCLOAK_SECRET}
spring.security.oauth2.client.registration.keycloak.scope=openid,profile,email
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}
spring.security.oauth2.client.registration.keycloak.provider=keycloak
spring.security.oauth2.client.provider.keycloak.token-uri=${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/token
spring.security.oauth2.client.provider.keycloak.authorization-uri=${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/auth
spring.security.oauth2.client.provider.keycloak.user-info-uri=${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/userinfo
spring.security.oauth2.client.provider.keycloak.jwk-set-uri=${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/certs
spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username

```

And my Spring security config:

```auto
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
@Slf4j
public class SecurityConfig {

    private static final String PROFILE_FORM_URL = "/profile_form";

    private static final String VIEW_JOBS_URL = "/view_jobs";

    private final JwtConverter jwtConverter;

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests((authorize) -> authorize
                        .requestMatchers(HttpMethod.GET, PROFILE_FORM_URL).permitAll()
                        .requestMatchers(HttpMethod.POST, PROFILE_FORM_URL).permitAll()
                        .requestMatchers(HttpMethod.GET, VIEW_JOBS_URL).hasRole(Role.ADMIN.getName())
                        .anyRequest().authenticated()
                );
        http.oauth2Login(Customizer.withDefaults());
        http.oauth2ResourceServer(oauth2 -> oauth2.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtConverter)));

        return http.build();
    }

}

```

Do you have any ideas what might be causing the problem? Thank you!

---

<div class="post-metadata">

**Author:** ![embesozzi](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/embesozzi/32/12390_2.png) [@embesozzi](https://forum.keycloak.org/u/embesozzi)\
**Post date:** [April 17, 2024, 2:33pm UTC](https://forum.keycloak.org/t/spring-app-with-keycloak-authorization-request-not-found-error/25618/2 "2024-04-17T14:33:25Z")

</div>

Here are some examples that may help you as a reference:

- [https://github.com/embesozzi/oidc-demoapp-spring](https://github.com/embesozzi/oidc-demoapp-spring)
- [microsoft-verifiable-credentials-workshop/vc-issuer-app-spring at main · twogenidentity/microsoft-verifiable-credentials-workshop · GitHub](https://github.com/twogenidentity/microsoft-verifiable-credentials-workshop/tree/main/vc-issuer-app-spring)

One thing to keep in mind is that it’s not necessary to specify all the OAuth 2.0 endpoints. Simply providing the `issuer-uri` is sufficient, as the library handles the discovery of the other endpoints through the use of the OIDC discovery endpoint.

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [April 17, 2024, 7:49pm UTC](https://forum.keycloak.org/t/spring-app-with-keycloak-authorization-request-not-found-error/25618/3 "2024-04-17T19:49:37Z")

</div>

This is more a Spring related question that Keycloak related. Perhaps you should ask in a Spring forum to get proper help.
