Skip to content

Instantly share code, notes, and snippets.

@mraible
Created January 10, 2019 00:28
Show Gist options
  • Save mraible/476470f37a19d4b83c2d36a2ca6f9d63 to your computer and use it in GitHub Desktop.
Save mraible/476470f37a19d4b83c2d36a2ca6f9d63 to your computer and use it in GitHub Desktop.
Get an ID Token from Okta with Spring Boot
okta:
oauth2:
issuer: https://{yourOktaDomain}/oauth2/default
client-id: {clientId}
client-secret: {clientSecret}
@Grab('com.okta.spring:okta-spring-boot-starter:1.0.0')
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
@RestController
class Application {
@GetMapping('/')
String home(@AuthenticationPrincipal(expression = "idToken") OidcIdToken idToken) {
idToken.getTokenValue()
}
}
@mraible
Copy link
Author

mraible commented Jan 10, 2019

Put both files in the same directory. Install the Spring Boot CLI, then run:

spring run idtoken.groovy

Hit http://localhost:8080 after you start it, it’ll prompt you to log in, then you’ll see the ID token on the resulting screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment