Contains Spring auto-configuration for setting up a mock-oauth2-server.
The mock-oauth2-server can be used to represent as many issuers as you'd like supporting OpenID Connect/OAuth 2.0 discovery with valid JWKS uris, and should work nicely together with the validation from token-validation-spring
-
Add as dependency with test scope
-
Simply add the annotation
@EnableMockOAuth2Server
to your test configuration:@EnableMockOAuth2Server
-
For usage with token-validation-spring set the following properties in your local profile:
no.nav.security.jwt.issuer.issuer1.discoveryurl=http://localhost:${mock-oauth2-server.port}/issuer1/.well-known/openid-configuration
no.nav.security.jwt.issuer.issuer1.acceptedaudience=someaudience
-
For local use of your app there should now be RestController available in your app at /local
The query param `issuerId` must match the path after port in the `discoveryurl` - e.g. `issuer1` in `http://localhost:${mock-oauth2-server.port}/issuer1/.well-known/openid-configuration`
See token-validation-spring-demo for usage scenarios when starting your app locally.
For JUnit tests, your Spring application context should contain a bean of the type MockOAuth2Server
which can be used to issue tokens and provides a JWKS endpoint for validation.
- Usage: DemoControllerTest.java
- For detailed usage and features see the mock-oauth2-server documentation.