Prompt
How do I secure a SaaS app with Microsoft Entra ID?
Latest observation
Securing a SaaS app with Microsoft Entra ID usually means using Entra for identity, authentication, authorization, and access governance. The exact setup depends on whether your SaaS app is:
- Single-tenant: for one customer/organization
- Multi-tenant: for many customer organizations
- B2B/B2C-style external access: if users are outside your org
Here’s a practical approach.
1) Use Entra ID for authentication
Use Microsoft Entra ID as your identity provider via standard protocols:
- OpenID Connect / OAuth 2.0 for web and API auth
- SAML if you need enterprise SSO compatibility
Best practice:
- Use OIDC for new apps
- Use Authorization Code Flow with PKCE for web/mobile apps
- Never rely on password handling in your app
2) Register your app in Entra ID
Create an app registration in the Entra admin center.
You’ll configure:
- Redirect URIs
- Logout URL
- Client ID
- Certificates/secrets
- API permissions/scopes
- Token claims
For multi-tenant SaaS:
- Set the app to support Accounts in any organizational directory
- Use the
/commonor/organizationsendpoint carefully depending on your audience
3) Enforce single sign-on and MFA
Let Entra handle authentication policies like:
- Multi-factor authentication
- Conditional Access
- Device compliance
- Location-based restrictions
- Risk-based sign-in policies
This is one of the biggest security wins because you don’t implement MFA yourself.
Recommended:
- Require MFA for admins
- Require MFA for all users if the customer allows it
- Use Conditional Access for sensitive actions
4) Use app roles and groups for authorization
Don’t use Entra only for login. Also use it to decide what users can do.
Options:
- App roles: Best for application-specific roles like
Admin,BillingAdmin,ReadOnly - Groups: Useful for customer-managed access control
- Claims in tokens: Use role/group claims to enforce authorization in your app
Best practice:
- Enforce authorization server-side
- Don’t trust the UI alone
5) Protect your APIs
If your SaaS has APIs:
- Register the API in Entra
- Define scopes and app roles
- Validate access tokens on every request
- Check:
- issuer
- audience
- signature
- expiration
- tenant
- scopes/roles
For service-to-service communication:
- Use client credentials flow
- Prefer certificates over client secrets
- Rotate credentials regularly
6) Support tenant isolation
For multi-tenant SaaS, you must ensure users from one tenant cannot access another tenant’s data.
Implement:
- Tenant ID mapping at login
- Tenant-aware authorization in your database
- Row-level security or tenant filters
- Separate customer data by tenant identifier
Important:
- A valid Entra token means the user is authenticated
- It does not automatically mean they should access all tenants in your app
7) Use consent carefully
If your app needs access to user data or Graph API permissions:
- Request only the minimum permissions needed
- Prefer delegated permissions for user-driven actions
- Use application permissions only when truly needed
- Consider admin consent workflow for enterprise customers
Best practice:
- Document why each permission is needed
- Avoid broad permissions like
Directory.ReadWrite.Allunless necessary
8) Secure secrets and keys
If your SaaS uses client secrets, signing keys, or certificates:
- Store secrets in Azure Key Vault
- Prefer certificates over secrets
- Rotate credentials regularly
- Use managed identities where possible for Azure-hosted components
Also:
- Don’t hardcode secrets in source code
- Don’t put tokens in browser storage unless you fully understand the risk
9) Validate tokens correctly
In your backend, validate:
- Signature using Entra public keys
ississueraudaudienceexpandnbftidtenant IDscporrolesfor authorization
Use standard libraries from Microsoft or your platform framework rather than writing token validation manually.
10) Log and monitor sign-ins and app activity
Use Entra and your own observability tooling to track:
- Sign-in events
- Failed logins
- Consent grants
- Privilege changes
- Suspicious activity
- Token issuance anomalies
Also log application events like:
- tenant access
- role changes
- admin actions
- export/download operations
11) Consider external identity scenarios
If your SaaS serves customers who have their own Entra tenants, the best model is often:
- Each customer consents to your app
- Their users sign in with their own tenant accounts
- Your app uses the tenant ID to isolate and authorize access
If you need consumer identities, use:
- Microsoft Entra External ID or
- Other identity providers alongside Entra
12) Recommended SaaS security baseline
A solid baseline architecture looks like this:
- Entra ID for sign-in
- OIDC Authorization Code + PKCE
- MFA via Conditional Access
- App roles for authorization
- Tenant isolation in backend and database
- Token validation on every API call
- Key Vault for secrets/certs
- Logging, auditing, and alerting
- Least-privilege API permissions
Common mistakes to avoid
- Using Entra only as an SSO button, with weak app-side authorization
- Not isolating tenant data
- Storing access tokens insecurely
- Using long-lived client secrets without rotation
- Over-requesting permissions
- Trusting client-side role checks
- Skipping token validation in backend APIs
If you want, I can help with one of these next:
- A reference architecture for a multi-tenant SaaS app using Entra ID
- A step-by-step app registration setup
- Code examples for validating Entra JWTs in .NET, Node.js, Python, or Java
- A security checklist for SaaS + Entra ID
- Guidance for single-tenant vs multi-tenant design
If you tell me your stack (for example: React + .NET API + Azure SQL), I can give you a concrete implementation plan.