Created
January 16, 2020 20:59
-
-
Save mraible/8efe7a632182f9af984f8eca61d57971 to your computer and use it in GitHub Desktop.
Spring Security OIDC Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('spring-boot-starter-oauth2-client') | |
@RestController | |
class Application { | |
@GetMapping('/') | |
String home(java.security.Principal user) { | |
'Hello ' + user.name | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
class HomeController { | |
@GetMapping("/") | |
public String hello(@AuthenticationPrincipal OidcUser user) { | |
return "Hello, " + user.getFullName(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OIDC QuickStart with Spring Security
For
app.groovy
to work, you'll need to:Register a Web app on Okta
Set the Login redirect URI to
http://localhost:8080/login/oauth2/code/okta
Create an
okta.env
with the following settings.Run
source okta.env
, followed byspring run app.groovy
. Navigate to http://localhost:8080 and you'll be prompted to log in. It will only show you the user's unique identifier.Do More with Java
To get their full name, create a new Spring Boot app with HTTPie and expand the downloaded zip file.
Use the Okta Maven Plugin to create an Okta account and register a Spring Boot app.
Start your app with
./mvnw spring-boot:run
and go to http://localhost:8080. After logging in, your full name will be displayed.