Using OAuth2 in Spring Boot App with {okta}
- Add the following dependencies in POM file
<dependency>
<groupId>com.okta.spring</groupId>
<artifactId>okta-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
- In spring boot main class add the following Bold and Underlined code
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
@EnableResourceServer
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
- Log in to your Okta developer account (or sign up if you don't have an account) and navigate to Applications > Add Applications. Click Single-Page App, click Next and give the app name. Change all instances of localhost:8080 to localhost:3000 (or localhost:4200 if you have angular client) and click Done.
- Copy the client Id into your server/src/main/resources/application.properties file as:
Make sure you don't include -admin in these urls.
After setting, run your spring boot app and access and you will get the following page.
Comments
Post a Comment