Applications & Authentication - Microsoft Graph API
This resource covers app registrations, service principals, OAuth2 permissions, authentication methods, and credentials management in Azure AD.
Contents
- Base Endpoints
- Overview
- Applications
- Application Properties
- Service Principals
- App Role Assignments
- OAuth2 Permission Grants
- Application Credentials
- Federated Identity Credentials
- Owners
- App Templates
- Policies
- Authentication Methods
- Application Extensions
- Synchronization (App Provisioning)
- Permissions Reference
- Common Patterns
- Best Practices
- Troubleshooting
Base Endpoints
- Applications:
https://graph.microsoft.com/v1.0/applications - Service Principals:
https://graph.microsoft.com/v1.0/servicePrincipals - OAuth2 Permissions:
https://graph.microsoft.com/v1.0/oauth2PermissionGrants - Authentication Methods:
https://graph.microsoft.com/v1.0/users/{id}/authentication
Overview
Authentication in Microsoft Graph follows OAuth 2.0 standards:
- App registers in Azure AD
- User grants permissions (delegated) or app gets permissions (application)
- Access token obtained
- Token used in API calls
Applications
List Applications
GET /applications
GET /applications?$select=displayName,appId,createdDateTime
Get Application
GET /applications/{application-object-id}
GET /applications(appId='{client-id}')
Create Application
POST /applications
Content-Type: application/json
{
"displayName": "My Application",
"signInAudience": "AzureADMyOrg"
}
Required Permissions: Application.ReadWrite.All
signInAudience values:
AzureADMyOrg- Single tenantAzureADMultipleOrgs- Multi-tenantAzureADandPersonalMicrosoftAccount- Multi-tenant + personal accountsPersonalMicrosoftAccount- Personal accounts only
Update Application
PATCH /applications/{id}
{
"displayName": "Updated App Name",
"web": {
"redirectUris": [
"https://myapp.com/callback"
]
}
}
Delete Application
DELETE /applications/{id}
---
Application Properties
Configure Redirect URIs
PATCH /applications/{id}
{
"web": {
"redirectUris": [
"https://myapp.com/auth/callback"
]
},
"spa": {
"redirectUris": [
"https://myapp.com/spa-callback"
]
},
"publicClient": {
"redirectUris": [
"https://login.microsoftonline.com/common/oauth2/nativeclient"
]
}
}
Configure API Permissions
PATCH /applications/{id}
{
"requiredResourceAccess": [
{
"resourceAppId": "00000003-0000-0000-c000-000000000000",
"resourceAccess": [
{
"id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
"type": "Scope"
},
{
"id": "df021288-bdef-4463-88db-98f22de89214",
"type": "Role"
}
]
}
]
}
resourceAppId:
- Microsoft Graph:
00000003-0000-0000-c000-000000000000
type:
Scope- Delegated permissionRole- Application permission
Expose API
PATCH /applications/{id}
{
"identifierUris": [
"api://{client-id}"
],
"api": {
"oauth2PermissionScopes": [
{
"adminConsentDescription": "Allow the app to access data",
"adminConsentDisplayName": "Access data",
"id": "{guid}",
"isEnabled": true,
"type": "User",
"userConsentDescription": "Allow the app to access your data",
"userConsentDisplayName": "Access your data",
"value": "access_as_user"
}
]
}
}
Configure App Roles
PATCH /applications/{id}
{
"appRoles": [
{
"allowedMemberTypes": ["User"],
"description": "Administrators have full access",
"displayName": "Administrator",
"id": "{guid}",
"isEnabled": true,
"value": "Admin"
},
{
"allowedMemberTypes": ["User"],
"description": "Readers can view data",
"displayName": "Reader",
"id": "{guid}",
"isEnabled": true,
"value": "Reader"
}
]
}
---
Service Principals
Service principals are the local representation of an application in a specific tenant.
List Service Principals
GET /servicePrincipals
GET /servicePrincipals?$filter=displayName eq 'My App'
Get Service Principal
GET /servicePrincipals/{id}
GET /servicePrincipals(appId='{client-id}')
Create Service Principal
POST /servicePrincipals
{
"appId": "{client-id}"
}
Update Service Principal
PATCH /servicePrincipals/{id}
{
"tags": ["WindowsAzureActiveDirectoryIntegratedApp"]
}
Delete Service Principal
DELETE /servicePrincipals/{id}
---
App Role Assignments
List App Role Assignments
GET /servicePrincipals/{sp-id}/appRoleAssignedTo
Assign App Role to User
POST /servicePrincipals/{sp-id}/appRoleAssignedTo
{
"principalId": "{user-id}",
"resourceId": "{sp-id}",
"appRoleId": "{app-role-id}"
}
Assign App Role to Group
POST /groups/{group-id}/appRoleAssignments
{
"principalId": "{group-id}",
"resourceId": "{sp-id}",
"appRoleId": "{app-role-id}"
}
Remove App Role Assignment
DELETE /servicePrincipals/{sp-id}/appRoleAssignedTo/{assignment-id}
---
OAuth2 Permission Grants
List Permission Grants
GET /oauth2PermissionGrants
GET /oauth2PermissionGrants?$filter=clientId eq '{sp-id}'
Grant Delegated Permissions
POST /oauth2PermissionGrants
{
"clientId": "{client-sp-id}",
"consentType": "AllPrincipals",
"principalId": null,
"resourceId": "{resource-sp-id}",
"scope": "User.Read Mail.Read"
}
consentType:
AllPrincipals- Admin consent for all usersPrincipal- User consent for specific user (requires principalId)
Update Permission Grant
PATCH /oauth2PermissionGrants/{grant-id}
{
"scope": "User.Read Mail.Read Calendars.Read"
}
Revoke Permission Grant
DELETE /oauth2PermissionGrants/{grant-id}
---
Application Credentials
Credentials secure your application authentication to Microsoft Graph.
List Password Credentials
GET /applications/{id}?$select=passwordCredentials
Add Password Credential (Client Secret)
POST /applications/{id}/addPassword
{
"passwordCredential": {
"displayName": "Client Secret 1"
}
}
Returns: New secret value (store immediately - cannot retrieve later)
Remove Password Credential
POST /applications/{id}/removePassword
{
"keyId": "{credential-key-id}"
}
List Certificate Credentials
GET /applications/{id}?$select=keyCredentials
Add Certificate Credential
POST /applications/{id}/addKey
{
"keyCredential": {
"type": "AsymmetricX509Cert",
"usage": "Verify",
"key": "BASE64_ENCODED_CERTIFICATE"
},
"passwordCredential": null,
"proof": "{proof-token}"
}
---
Federated Identity Credentials
Use for workload identity federation (GitHub Actions, Kubernetes, etc.) - no secrets needed.
List Federated Credentials
GET /applications/{id}/federatedIdentityCredentials
Add Federated Credential
POST /applications/{id}/federatedIdentityCredentials
{
"name": "GitHubActions",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:org/repo:environment:Production",
"audiences": ["api://AzureADTokenExchange"]
}
---
Owners
List Application Owners
GET /applications/{id}/owners
Add Owner
POST /applications/{id}/owners/$ref
{
"@odata.id": "https://graph.microsoft.com/v1.0/users/{user-id}"
}
Remove Owner
DELETE /applications/{id}/owners/{user-id}/$ref
---
App Templates
List Application Templates
GET /applicationTemplates
Get Template
GET /applicationTemplates/{template-id}
Instantiate Template
POST /applicationTemplates/{template-id}/instantiate
{
"displayName": "My App from Template"
}
---
Policies
Token Lifetime Policies
List Policies
GET /policies/tokenLifetimePolicies
Create Policy
POST /policies/tokenLifetimePolicies
{
"displayName": "Custom Token Lifetime",
"definition": [
"{\"TokenLifetimePolicy\":{\"Version\":1,\"AccessTokenLifetime\":\"4:00:00\"}}"
]
}
Assign Policy to Application
POST /applications/{app-id}/tokenLifetimePolicies/$ref
{
"@odata.id": "https://graph.microsoft.com/v1.0/policies/tokenLifetimePolicies/{policy-id}"
}
Home Realm Discovery Policies
POST /policies/homeRealmDiscoveryPolicies
{
"displayName": "HRD Policy",
"definition": [
"{\"HomeRealmDiscoveryPolicy\":{\"AccelerateToFederatedDomain\":true}}"
]
}
---
Authentication Methods
Authentication methods allow users to sign in.
List User's Authentication Methods
GET /users/{user-id}/authentication/methods
Phone Authentication
List Phone Methods
GET /users/{user-id}/authentication/phoneMethods
Add Phone Method
POST /users/{user-id}/authentication/phoneMethods
{
"phoneNumber": "+1 555-0100",
"phoneType": "mobile"
}
Phone types: mobile, alternateMobile, office
Email Authentication
Get Email Methods
GET /users/{user-id}/authentication/emailMethods
Add Email Method
POST /users/{user-id}/authentication/emailMethods
{
"emailAddress": "backup@example.com"
}
FIDO2 Security Keys
List FIDO2 Methods
GET /users/{user-id}/authentication/fido2Methods
Microsoft Authenticator
List Authenticator Methods
GET /users/{user-id}/authentication/microsoftAuthenticatorMethods
Temporary Access Pass (TAP)
Create TAP
POST /users/{user-id}/authentication/temporaryAccessPassMethods
{
"lifetimeInMinutes": 60,
"isUsableOnce": true
}
Returns: One-time password for passwordless onboarding
Password Methods
Reset Password
POST /users/{user-id}/authentication/passwordMethods/{method-id}/resetPassword
{
"newPassword": "NewP@ssw0rd!"
}
---
Application Extensions
Define Schema Extension
POST /schemaExtensions
{
"id": "myapp_customData",
"description": "Custom data for my app",
"targetTypes": ["User"],
"properties": [
{
"name": "customField",
"type": "String"
}
]
}
Use Extension
PATCH /users/{user-id}
{
"myapp_customData": {
"customField": "value"
}
}
---
Synchronization (App Provisioning)
Get Synchronization Schema
GET /servicePrincipals/{sp-id}/synchronization/jobs/{job-id}/schema
Start Synchronization
POST /servicePrincipals/{sp-id}/synchronization/jobs/{job-id}/start
Pause Synchronization
POST /servicePrincipals/{sp-id}/synchronization/jobs/{job-id}/pause
---
Permissions Reference
Delegated Permissions
Application.Read.All- Read all applicationsApplication.ReadWrite.All- Read and write all applicationsApplication.ReadWrite.OwnedBy- Manage apps the user owns
Application Permissions
Application.Read.All- Read all applicationsApplication.ReadWrite.All- Read and write all applicationsApplication.ReadWrite.OwnedBy- Manage owned applications
---
Common Patterns
Register App with Permissions
# 1. Create application
POST /applications
{
"displayName": "My App",
"requiredResourceAccess": [...]
}
# 2. Create service principal
POST /servicePrincipals
{
"appId": "{client-id}"
}
# 3. Grant admin consent
POST /oauth2PermissionGrants
{...}
Rotate Client Secret
# 1. Add new secret
POST /applications/{id}/addPassword
{...}
# 2. Update application to use new secret
# 3. Remove old secret
POST /applications/{id}/removePassword
{...}
Setup Federated Identity (GitHub Actions)
# 1. Register application
POST /applications
{...}
# 2. Add federated credential
POST /applications/{id}/federatedIdentityCredentials
{
"name": "GitHubActions",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:org/repo:ref:refs/heads/main",
"audiences": ["api://AzureADTokenExchange"]
}
# 3. Use in GitHub Actions workflow (no secrets needed)
---
Best Practices
- Use managed identities when possible (Azure resources)
- Rotate secrets regularly (every 90 days recommended)
- Use certificates instead of secrets for production
- Use federated identities for CI/CD (no secrets)
- Request least privilege permissions
- Use workload identity federation for external systems
- Monitor consent grants regularly
- Document custom app roles clearly
- Implement proper token caching
- Test multi-tenant apps in multiple tenants
---
Troubleshooting
| Issue | Solution |
|---|---|
| 401 Invalid token | Check token expiration, request new token |
| 403 Permission denied | Verify app has required permissions in Azure AD |
| App not found | Verify appId/application object ID is correct |
| Credential expired | Renew password/certificate credentials |
| Cannot add secret | Verify you have Application.ReadWrite.All |