This feature is available only in the AI Premium Edition. For details about version differences, see Version Introduction.
What is OAuth 2.0
OAuth 2.0 is an open authorization protocol. It allows third-party applications to securely access a user's resources, such as data or services, with the user's consent, without requiring the user to share their account credentials.
In other words, Alibaba Cloud Mail can use OAuth 2.0 to delegate the authentication process to your enterprise. This delegation is secure because your enterprise account credentials are not transmitted to or stored on mail servers.
How OAuth 2.0 authentication works
To enable users to sign in to their mailboxes with your enterprise IdP, the Alibaba Cloud Mail server and your enterprise IdP must exchange information according to the OAuth 2.0 protocol.
The OAuth 2.0 standard protocol supports multiple grant types. This integration requires the authorization code grant.
Both servers must implement the OAuth 2.0 authorization code grant, with the mail server acting as the OAuth 2.0 client and the enterprise IdP as the OAuth 2.0 server.
How to implement OAuth 2.0
To implement the OAuth 2.0 authorization code grant, refer to the following standard protocol documents:
Additionally, for parts of the protocol that are not strictly defined, you must adhere to the following requirements:
Implement the OAuth 2.0 Authorization endpoint, which is the URL of your enterprise IdP's sign-in page.
The endpoint must support the
response_type=coderequest parameter for the authorization code grant.
Implement the OAuth 2.0 Token endpoint.
The endpoint must support the
grant_type=authorization_coderequest parameter to exchange an authorization code for an access token.The endpoint must support the
grant_type=refresh_tokenrequest parameter to exchange a refresh token for a new access token.The endpoint must support passing the
client_idandclient_secretparameters in a POST request body to authenticate the client.
Implement a UserInfo endpoint. This is not explicitly defined in the OAuth 2.0 specification.
The endpoint must support exchanging an access token for the current user's email address.
We recommend implementing this as a GET request that passes the access token in the
Authorizationrequest header.
Implement an EndSession endpoint. This is not explicitly defined in the OAuth 2.0 specification.
This endpoint is used to sign the user out of the browser session. It ensures that signing out of the mailbox also signs the user out of their enterprise IdP session.
PKCE
If you support PKCE, the
code_challengeencoding method must support S256.
OAuth 2.0 sign-in flow

Final result
After configuration, users can sign in through the enterprise IdP in two ways:
Method 1: Go to your enterprise's custom mailbox sign-in URL. The user is automatically redirected to the enterprise IdP's sign-in page.

Method 2: Go to your enterprise's custom mailbox sign-in URL and click the icon for your OAuth 2.0 IdP under More sign-in options.

Configuration steps
Step 1: Create an OAuth 2.0 client in your IdP
If your enterprise uses a self-built IdP, contact the responsible team to create an OAuth 2.0 client for Alibaba Cloud Mail.
If your enterprise uses a third-party Identity as a Service (IDaaS) product, follow the product's documentation to create an OAuth 2.0 client. Use the following key settings:
Grant types (
grant_typefor the Token endpoint):authorization_code,refresh_tokenResponse type (
response_typefor the Authorization endpoint):codeToken endpoint authentication method:
client_secret_postAuthorization code expiration: At least 600 seconds (recommended).
Access token expiration: 14 days or 1,209,600 seconds (recommended).
Refresh token expiration: 28 days or 2,592,000 seconds (recommended).
Callback URL: See the configuration page, as shown in the following figure.

If multiple callback URLs are provided (separated by commas), you must add each one as a separate entry in your IdP's configuration.
Step 2: Configure the OAuth 2.0 client in the console
In the domain admin console, go to Enterprise Customization > Identity Source Management and click Start Configuration to go to the Select Authentication Protocol page.

Click the OAuth2.0 identity source button to go to the OAuth2.0 Configuration page.

On the OAuth2.0 Configuration page, verify that you meet the prerequisites.

If you use Microsoft for OAuth authentication, for the Client Secret field, provide the secret's Value, not its ID, from your Microsoft application settings.

Prerequisite | Description |
Mandatory | |
Add a custom sign-in URL. | Path: Enterprise Customization > UI Customization > Customize Mailbox Logon URL > Add Domain A custom mailbox sign-in URL is required to correctly route users to the enterprise IdP. |
Complete the CNAME configuration for the custom sign-in URL. | Path: Enterprise Customization > UI Customization > Customize Mailbox Logon URL > CNAME Settings This ensures that the custom mailbox sign-in URL works correctly. |
Complete the ICP filing for the custom sign-in URL. | Path: Enterprise Customization > UI Customization > Customize Mailbox Logon URL > ICP Filing Settings This ensures that the custom mailbox sign-in URL can be legally operated in the Chinese mainland. |
Recommended | |
Set the custom sign-in URL as the default link. | Path: Enterprise Customization > UI Customization > Customize Mailbox Logon URL > Set as Functional Mail Link In some scenarios, you may need to direct employees to use the enterprise's custom sign-in URL to access their mailboxes. |
Add an SSL certificate for the custom sign-in URL. | Path: Enterprise Customization > Domain Management > SSL Certificate Management > Upload Certificate This allows the custom sign-in URL to be accessed over HTTPS for better security. |
Enforce HTTPS. | Path: Enterprise Customization > Domain Management > SSL Certificate Management > Enforce HTTPS This ensures that all connections to the custom sign-in URL use HTTPS by default, improving security. |
Force all users to enable security passwords, or disallow all users from using third-party clients. | Path: Security Management > Account Security Policy > Force Enable Security Password / Allow Third-party Clients If you plan to enable the "Only allow logon via this identity source" option, you must force enable security passwords to ensure that standard protocols (SMTP, IMAP, POP) continue to work. Highly recommended: Most account security issues originate from using standard protocols. Enabling security passwords or disabling third-party clients can eliminate these risks and prevent account compromise or financial loss. Note: After security passwords are enabled, users can no longer authenticate with their regular mailbox password over standard protocols. Each user must create a unique security password for this purpose. Plan this transition carefully to minimize disruption, especially for system mail accounts. |
On the OAuth2.0 Configuration page, configure the fields.
Note: When you first configure and test this integration, keep the Set as Default Logon Method option disabled to ensure employees can still sign in to their mailboxes.
Parameter | Description |
Basic configuration | |
Display name | This name appears on the button on the user sign-in page. |
Application logo | This logo appears on the sign-in page as the entry point for signing in with OAuth 2.0. |
Client ID | The client ID provided by your enterprise IdP. |
Client secret | The client secret provided by your enterprise IdP. |
Scope | The scope defined for the OAuth 2.0 Authorization endpoint. You can leave this blank if it is not supported. |
Authorization URL | The URL of your enterprise IdP's Authorization endpoint, which serves as the sign-in page. |
Token URL | The URL of the Token endpoint, used to exchange authorization codes and refresh tokens for access tokens. |
UserInfo endpoint HTTP request | The UserInfo endpoint exchanges a token for user information. This field specifies the HTTP request for calling the endpoint.
|
Use HTTP for UserInfo endpoint | If this option is disabled, an HTTPS connection is used. |
JsonPath for email in UserInfo response | The JsonPath expression to extract the |
EndSession endpoint HTTP request | The EndSession endpoint is a browser-side sign-out endpoint that clears the user's sign-in session with the enterprise IdP. This field specifies the HTTP request for calling the endpoint.
|
Use HTTP for EndSession endpoint | If this option is disabled, an HTTPS connection is used. |
Callback URL | You must add all of these URLs to your enterprise IdP's configuration. |
Mailbox sign-in URL | The URL for signing in to the mailbox through the IdP. This should be your enterprise's custom mailbox sign-in URL. |
Sign-in configuration | |
Enable identity source | You must enable this switch to validate and use this identity source for sign-in. After you enable it, an OAuth 2.0 sign-in button for this identity source is added to the sign-in page. |
Set as Default Logon Method | After you enable this switch, users who access the enterprise's custom mailbox sign-in URL are automatically redirected to the enterprise IdP sign-in page. Important: Before enabling this option, verify that you can sign in successfully using this identity source to avoid locking out employees. |
Only allow logon via this identity source | We recommend enabling this switch for new enterprises. For established enterprises with many active mail accounts, enable this with caution. When enabled, employees can only authenticate using this identity source, as other methods like using mailbox credentials will be disabled. For example:
Important: Ensure that you have enabled the Force Enable Security Password policy (Security Management > Account Security Policy > Force Enable Security Password). Otherwise, standard protocols and third-party clients will not work. |
After you configure the settings, click Save.
Step 3: Verify the integration
After you save the configuration, a confirmation message appears. Verify that you can successfully sign in to your mailbox through your enterprise IdP.
In a browser, copy the address and open it in an incognito mode window. Click the OAuth 2.0 icon to redirect to your enterprise IdP to sign in.

