This repository demonstrates how to build a Spring Boot Web MVC application that provides API endpoints integrated with Microsoft Azure Active Directory (AAD) for managing organizational identities. The application implements the "Resource Owner Password Credentials (ROPC) Authentication" scheme in Active Directory, leveraging Microsoft Graph APIs. This scheme is suitable for scenarios where a custom registration and authentication process with a tailored UI/UX is a business requirement for your organization.
- Spring Boot Web MVC: Leveraging Spring Boot for rapid application development with RESTful endpoints.
- Microsoft Azure Active Directory Integration: Secure API endpoints using Azure AD for authentication and authorization.
- Resource Owner Password Credentials (ROPC) Authentication: Implementing ROPC flow for custom user registration and authentication.
- Java 21 or higher
- Gradle
- Azure Active Directory tenant
- Azure AD application registration with appropriate permissions
git clone https://github.com/misoft-pro/demo-spring-azure-ad-integration.git
cd demo-spring-azure-ad-integration
-
Azure AD Configuration:
- Register a new application in the Azure portal.
- Note down the Tenant ID, Client ID, and Client Secret.
- Configure API permissions and expose an API if required.
-
Application Properties:
- Update the
application.yml
with your Azure AD credentials:
- Update the
azure:
active-directory:
tenant-id: YOUR_TENANT_ID
client-id: YOUR_CLIENT_ID
client-secret: YOUR_CLIENT_SECRET
user-group:
allowed-groups: GROUP_ID_1, GROUP_ID_2
./gradlew clean build
./gradlew bootRun
- Login:
POST /api/v1/tokens
- Request Body:
{ "username": "user@example.com", "password": "yourpassword" }
- Response:
{ "token": "JWT_TOKEN" }
- Request Body:
-
Create User:
POST /api/v1/users
- Request Body:
{ "username": "user@example.com", "password": "yourpassword"}
- Response:
{ "id": "USER_ID" }
- Request Body:
-
Get User:
GET /api/users/{userId}
-
- Request Header:
{ "Authorization": "Bearer yourJwtToken"}
- Response:
{ "id": "USER_ID" }
- Request Header:
-
Patch User:
PATCH /api/v1/users/{userId}
- Request Body:
{ "fieldToUpdate": "newValue" }
- Request Header:
{ "Authorization": "Bearer yourJwtToken"}
- Response:
{ "id": "USER_ID", "fieldToUpdate": "newValue" }
- Request Body:
The application uses JWT (JSON Web Token) for securing API endpoints. The tokens are issued by Azure AD and are verified by the application before granting access to protected resources.
Contributions are welcome! Please submit a pull request or open an issue to discuss improvements or fixes.