TL;DR
This guide shows you how to let users created in your Azure Active Directory (AD) B2C tenant access resources in a different Azure AD directory. We’ll use Conditional Access Policies and Guest Invitations.
Prerequisites
- An active Azure subscription
- An Azure AD B2C tenant
- An Azure AD tenant (separate from your B2C tenant) containing the resources you want to access.
- Global Administrator or Application Administrator role in both tenants.
Step 1: Register an Application in Your Resource Directory
This application will represent B2C users when accessing resources.
- In your resource directory (the tenant *with* the resources), go to Azure Active Directory > App registrations.
- Click New registration.
- Give it a name (e.g., ‘B2C Access App’).
- Under Supported account types, select Accounts in this organizational directory only.
- Add a redirect URI: This is important! Use a dummy URL for now, like https://localhost. You can change it later.
- Click Register.
Step 2: Grant API Permissions to the Application
Give the application permission to access the resources you want to share.
- In your resource directory, go to your newly created app registration.
- Click API permissions.
- Click Add a permission.
- Select Microsoft Graph or the specific API representing your resources.
- Choose the necessary permissions (e.g., ‘User.Read’, ‘Files.ReadWrite.All’). Select both Delegated and Application permissions as needed.
- Click Add permissions.
- Click Grant admin consent for [Your Tenant Name]. This is crucial!
Step 3: Create a Guest Invitation in Your Resource Directory
Invite the B2C tenant as a guest to your resource directory.
- In your resource directory, go to Azure Active Directory > Guests.
- Click New guest invitation.
- Enter the email address of your B2C tenant administrator (e.g., admin@yourb2ctenant.onmicrosoft.com).
- Add a message if you like.
- Click Send.
Step 4: Configure Conditional Access Policy in Your Resource Directory
Control access based on the B2C tenant membership.
- In your resource directory, go to Azure Active Directory > Security > Conditional Access.
- Click New policy.
- Give it a name (e.g., ‘B2C User Access’).
- Assignments:
- Users or workload identities: Select All users, then exclude your regular tenant users (e.g., by group). This ensures the policy only applies to guest users from B2C.
- Cloud apps or actions: Select the application you registered in Step 1.
- Conditions:
- Configure any other conditions as needed (e.g., location, device platform).
- Access controls:
- Select Grant access and choose the appropriate grant control (e.g., require multi-factor authentication).
- Click Create.
Step 5: Configure Your B2C Application to Request Access
Modify your B2C application to request access tokens for the resource directory.
- In your B2C tenant, go to App registrations.
- Select your application.
- Click Authentication.
- Add a redirect URI if needed (matching Step 1).
- Under API permissions, click Add a permission.
- Select the API representing your resources in the resource directory.
- Choose the necessary permissions.
- Click Add permissions.
Step 6: Test Access
Sign in to your B2C application and verify access to the resources.
- Sign in with a user from your B2C tenant.
- Your application should now be able to request an access token for the resource directory using the client ID and secret of the app registration you created in Step 1.