Authorization determines what an authenticated user or application is allowed to do. The Microsoft Identity Platform manages this through permissions, roles, and policies that control access to resources like APIs or Azure databases.
Applications request specific permissions to access resources. Delegated permissions are used when a signed-in user delegates authority to an app. Application permissions are for apps that run without a user, like background services. You configure these in the app registration within the Azure portal, following the principle of least privilege to request only the minimum access needed.
Implement Role-Based Access Control (RBAC)
Role-Based Access Control (RBAC) assigns permissions based on organizational roles, such as "Reader" or "Contributor," rather than to individual users. The platform integrates with Azure RBAC to manage access to Azure resources. You can use built-in roles or create custom ones. Always apply least privilege to ensure users have only the access necessary for their tasks.
Manage Consent Frameworks
The consent framework controls how users or administrators grant an app permission to access resources. Users may be prompted for consent upon sign-in. For higher-risk permissions, admin consent is required. You manage these policies in the Azure portal to enforce proper authorization and protect sensitive data.
Use Conditional Access for Enhanced Security
Conditional Access policies add security by requiring specific conditions, like multifactor authentication (MFA) or trusted locations, before granting access. These policies help prevent unauthorized access even if credentials are compromised, making them essential for protecting critical resources.
Leverage Managed Identities for Secure Access
Managed identities provide an automatically managed identity for Azure resources, like apps or virtual machines, to authenticate to other services. This eliminates the need to manage credentials in code. System-assigned identities are tied to a specific resource, while user-assigned identities can be shared. Using managed identities reduces credential exposure risk and simplifies security management.
Manage Authentication Flows and Token Security
Authentication flows verify a user's identity and obtain security tokens for accessing protected resources. The Microsoft Identity Platform supports standard OAuth 2.0 and OpenID Connect (OIDC) flows, each suited for different application types.
Key Authentication Flows
The primary flows are the authorization code flow, the implicit grant flow, and the client credentials flow. The authorization code flow is the most secure and recommended for most apps, including single-page applications (SPAs). The implicit flow is less secure due to potential token exposure and should be used sparingly. The client credentials flow is for server-to-server interactions where no user is involved, such as daemon apps.
Token Management and Security
Security tokens include access tokens, ID tokens, and refresh tokens. Configure token lifetimes based on security needs: access tokens should have short lifetimes to minimize risk, while refresh tokens can obtain new access tokens without user interaction. Always validate tokens on the resource server to ensure integrity. Never parse access tokens on the client side; this should only be done by the web API they are intended for.
Best Practices for Implementation
Use the Microsoft Authentication Library (MSAL) instead of crafting raw HTTP calls, as it handles token acquisition, caching, and renewal. Avoid the deprecated implicit grant flow for new applications; migrate SPAs to the authorization code flow with Proof Key for Code Exchange (PKCE). For daemon apps, prefer certificate-based authentication over client secrets. Regularly rotate your application's credentials to minimize exposure risk.
Ensuring Application Resilience
Design applications to handle authentication service outages gracefully. Implement a backup authentication system for resilience. Use single sign-on (SSO) for a seamless user experience and to reduce authentication requests. Configure rolling sessions to extend a user's session based on activity, which reduces token refresh frequency and improves experience during temporary disruptions.
Execute Token Acquisition and Validation via MSAL
The Microsoft Authentication Library (MSAL) simplifies acquiring, managing, and validating security tokens for the Microsoft Identity Platform. It supports various application types and platforms, handling token operations automatically.
Token Acquisition and Caching
MSAL uses a silent token acquisition pattern, first checking its token cache for valid tokens before making network calls. It securely serializes and persists the token cache, making tokens available across application sessions. This reduces network calls and improves resilience by relying on locally stored tokens during service disruptions.
Token Refresh and Resilience
MSAL automatically handles token refreshing using long-lived tokens and the refresh_in property. It implements best practices like exponential back-off retries for failed requests. Using the latest MSAL releases ensures you benefit from security updates and improved reliability features.
Validation and Security
Tokens acquired via MSAL contain standard claims for user information and permissions. Applications should validate these tokens by inspecting their claims instead of making additional network calls. MSAL supports optional claims and app roles to include additional information for fine-grained authorization, reducing dependencies on external services.
Best Practices and Integration
Avoid decoding access tokens on the client side; use ID tokens for user information instead. MSAL integrates with Azure services and supports advanced scenarios like broker authentication on mobile devices and Continuous Access Evaluation (CAE) for real-time token revocation. Leveraging MSAL ensures applications adhere to security best practices while simplifying implementation.
Implement Permissions and Consent Frameworks
The Microsoft Identity Platform manages user and app access to resources using industry standards like OAuth 2.0 and OpenID Connect.
Defining Permissions
Permissions specify what an application is allowed to do. Delegated permissions allow an app to act on behalf of a signed-in user. Application permissions grant access to resources without a user present. Properly defining these ensures apps have only the specific access they need.
Managing the Consent Framework
The consent framework controls how users or admins authorize an app's permissions. User consent allows individuals to grant access to their own data. Admin consent is required for permissions affecting the entire organization. Administrators can configure policies to limit which apps users can trust. The framework supports static consent (defined at registration) and dynamic consent (requested at runtime).
Using Managed Identities
Managed identities allow Azure resources to authenticate to other services without hard-coded secrets. A system-assigned managed identity is tied to a specific resource and deleted with it. Using these identities eliminates the risk of credential exposure in application code.
Leveraging MSAL for Implementation
The Microsoft Authentication Library (MSAL) is the primary tool for implementing these features. It simplifies acquiring access tokens, which are used to reach protected APIs like Microsoft Graph. MSAL handles token caching and security updates automatically, reducing developer effort.
Microsoft Identity Platform provides cloud-based authentication and authorization using Azure Active Directory. It centralizes identity management, enabling single sign-on across web, mobile, and API applications through support for OAuth 2.0 and OpenID Connect.
Registering Your Application
Integration begins by registering your application in Azure AD. This yields an Application (client) ID, a redirect URI, and optionally a client secret. You configure supported account types and consent settings to establish a trust relationship and define the authentication flow's scope.
Choosing Authentication Flows and Using MSAL
Developers should use the Microsoft Authentication Library (MSAL) instead of hand-coding protocol calls. MSAL simplifies token caching, conditional access, and single sign-on. Common OAuth 2.0 grant flows include the authorization code flow (with PKCE for SPAs and mobile apps), the client credentials flow (for daemons), and the on-behalf-of (OBO) flow (for APIs calling other APIs).
Applying Security Best Practices
Always request least privilege permissions and use scopes for consent. Validate tokens at every step: use ID tokens for user information and access tokens to access APIs. Manage credentials securely with Azure Key Vault or managed identities and rotate them regularly. Configure Conditional Access policies to enforce requirements like multifactor authentication and device compliance.