First, create an Azure AD application in the Azure portal. Follow the documentation for more detailed instructions on how to do this.
Once your Azure AD application is created, note the application ID and tenant ID as you will need these values later.
Configure your Spring Boot application by adding the following dependencies to your pom.xml file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
spring.security.oauth2.client.registration.azure.client-id=<application ID>
spring.security.oauth2.client.registration.azure.client-secret=<client secret>
spring.security.oauth2.client.registration.azure.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.azure.redirect-uri=<redirect URI>
spring.security.oauth2.client.provider.azure.authorization-uri=https://login.microsoftonline.com/<tenant ID>/oauth2/v2.0/authorize
spring.security.oauth2.client.provider.azure.token-uri=https://login.microsoftonline.com/<tenant ID>/oauth2/v2.0/token
Replace the placeholders (<application id="">, <client secret="">, <redirect uri="">, <tenant id="">) with the values you noted earlier.
Finally, start your Spring Boot application and try accessing a secured endpoint. You should be redirected to the Azure AD login page and once authenticated, be granted access to the secured endpoint.
Asked: 2023-05-19 12:19:25 +0000
Seen: 13 times
Last updated: May 19 '23