micronaut-projects / micronaut-servlet

Servlet support in Micronaut
Apache License 2.0
28 stars 19 forks source link

OIDC authentication via Google fails on Tomcat #728

Open tfield opened 1 month ago

tfield commented 1 month ago

Expected Behavior

When using OIDC authentication with Google and Tomcat, I expect to be able to log in successfully.

The Micronaut Guide SECURE A MICRONAUT APPLICATION WITH GOOGLE was followed, and the server was changed from netty to tomcat, and this fails.

This seems similar to https://github.com/micronaut-projects/micronaut-servlet/issues/239 which includes links to https://github.com/micronaut-projects/micronaut-servlet/pull/256 https://github.com/micronaut-projects/micronaut-servlet/pull/275

Actual Behaviour

The callback URL fails with the following exception

ERROR i.m.http.server.RouteExecutor - Unexpected error occurred: Error instantiating bean of type [io.micronaut.security.oauth2.endpoint.authorization.response.DefaultOpenIdAuthorizationResponse]: Error decoding request body: Stream closed

This works fine with Netty.

mn-tomcat-google-error.txt

Steps To Reproduce

  1. download the java/gradle micronaut guide sample from here.
  2. configure google client id/secret per your google console
  3. start and test the app to authenticate
  4. observe success
  5. edit build.gradle and change micronaut.runtime from 'netty' to 'tomcat', and add implementation("io.micronaut.servlet:micronaut-http-server-tomcat")
  6. restart the app and test to authenticate
  7. observe the stack trace

Environment Information

Example Application

Download the java/gradle micronaut guide sample from here.

Version

4.4.0

graemerocher commented 1 month ago

Seems it doesn't like async being enabled by default, will take a look. You could try and use the latest 4.9.0 version and disable async. See https://micronaut-projects.github.io/micronaut-servlet/latest/guide/configurationreference.html#io.micronaut.servlet.engine.MicronautServletConfiguration

tfield commented 1 month ago

Thank you - that worked! I set

    implementation 'io.micronaut.servlet:micronaut-servlet-engine:4.9.0'
    implementation 'io.micronaut.servlet:micronaut-http-server-tomcat:4.9.0'

and

micronaut:
  servlet:
    async-supported: false
    test-async-supported: false
    async-file-serving-enabled: false

and this was successful.