Skip to content

Files

Latest commit

jan-olaveideJan-Olav Eide
and
Sep 2, 2024
571a54c · Sep 2, 2024

History

History

token-validation-spring-test

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 31, 2024
Jan 13, 2024
Sep 2, 2024

README.md

token-validation-spring-test

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

Configuration for local setup

  • 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`  
    

How to use

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.