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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-19 12:19:25 +0000
Seen: 13 times
Last updated: May 19 '23
How can a role assignment be added to a managed identity that is assigned to a system in Azure?
How can key vault be utilized to access Azure blob storage in Databricks?
How can Oracle Tables in bulk be transferred to Azure Storage using Azure Data Factory?
What is the reason for the authentication failure in Azure GIT?
What is the process of utilizing Forge API with Azure, S3, or other storage systems?
How does UDP multicast work on Windows Azure cloud service?
How can the onpremisessamaccountname be included as a claim in the JWT token for Azure AD?