OAuth identity authentication

Updated at:
Note

This feature is available only in the AI Premium Edition. For details on version differences, see Version Introduction.

What is OAuth 2.0?

OAuth 2.0 is an open authorization protocol that allows a third-party application to securely access a user's resources, such as data and services, with the user's consent, without requiring the user to provide their account credentials.

In other words, Alibaba Cloud Mail can use OAuth 2.0 to delegate the authentication process to your enterprise. This process is opaque to Alibaba Cloud Mail, meaning your corporate account credentials are never transmitted to or stored on our servers.

Understanding OAuth 2.0 authentication

To enable sign-in to Alibaba Cloud Mail through your Enterprise IdP, the mail service and your Enterprise IdP must exchange information by following the OAuth 2.0 protocol.

OAuth 2.0 supports several grant types. This integration requires the authorization code grant.

Both the Alibaba Cloud Mail service and your Enterprise IdP must implement the authorization code grant. Alibaba Cloud Mail acts as the OAuth 2.0 client, and your IdP acts 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:

  1. The OAuth 2.0 Authorization Framework (RFC 6749)

  2. Proof Key for Code Exchange by OAuth Public Clients (RFC 7636)

For parts of the protocol that are loosely defined, you must adhere strictly to the following requirements:

  1. Implement the OAuth 2.0 authorization endpoint, which is the sign-in page URL of your Enterprise IdP.

    1. Must support the response_type=code request parameter for the authorization code grant.

  2. Implement the OAuth 2.0 token endpoint.

    1. Must support the grant_type=authorization_code request parameter to exchange an authorization code for a token.

    2. Must support the grant_type=refresh_token request parameter to exchange a refresh token for a new access token.

    3. The endpoint must support passing the client_id and client_secret parameters in the body of a POST request.

  3. Implement the UserInfo endpoint. This is not explicitly defined in the OAuth 2.0 standard.

    1. Must support exchanging an access token for the current user's email address.

    2. We recommend implementing this as an HTTP GET request, passing the access token in the Authorization request header.

  4. Implement the End-Session endpoint. This is not explicitly defined in the OAuth 2.0 standard.

    1. This endpoint signs the user out of the browser session, ensuring that signing out of Alibaba Cloud Mail also signs them out of the Enterprise IdP.

  5. PKCE

    1. If you support PKCE, the code_challenge must support the S256 method.

OAuth 2.0 authentication flow diagram

image

Final result

After configuration, you can sign in by using your Enterprise IdP in one of two ways.

Method 1: Go to your custom sign-in URL for Alibaba Cloud Mail. You will be automatically redirected to your Enterprise IdP's sign-in page.

image.png

Method 2: Go to your custom sign-in URL for Alibaba Cloud Mail and click the icon for your OAuth 2.0 IdP under More sign-in options.

image.png

Procedure

Step 1: Create an OAuth 2.0 client

If you have a self-hosted IdP, contact the relevant team within your organization to create an OAuth 2.0 client for Alibaba Cloud Mail.

If you use a third-party IDaaS product, follow its documentation to create an OAuth 2.0 client with the following key settings:

  1. Grant Types (grant_type for the token endpoint): authorization_code, refresh_token

  2. Response Type (response_type for the authorization endpoint): code

  3. Token endpoint authentication method: client_secret_post

  4. Authorization code expiration: We recommend at least 600 seconds.

  5. Access token expiration: We recommend 14 days (1,209,600 seconds).

  6. Refresh token expiration: We recommend 28 days (2,592,000 seconds).

  7. Redirect URIs: See the configuration page, as shown in the following figure.

image

Note

If the redirect URI field contains multiple comma-separated URLs, you must add all of them to your client configuration.

Step 2: Configure the OAuth 2.0 client

  1. In domain management, go to Integration > Identity Source Management > Identity Authentication, and click Start Configuration to open the Select Authentication Protocol page.

image

  1. Click the OAuth2.0 identity source button to open the OAuth2.0 Configuration page.

image

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

image

Note

If you are using Microsoft for OAuth authentication, enter the Secret Value from your Microsoft configuration as the Client Secret, not the Secret ID.

image

Prerequisite

Description

Required

Add a custom sign-in URL

Path: Domain > Sign-in URL > Add Domain

A custom sign-in URL for Alibaba Cloud Mail is required to correctly route and redirect users to your Enterprise IdP.

Complete the CNAME configuration for your custom sign-in URL

Path: Domain > Sign-in URL > CNAME configuration

This ensures your custom sign-in URL functions correctly.

Complete the ICP filing for your custom sign-in URL

Path: Domain > Sign-in URL > ICP Filing Settings

This ensures your custom sign-in URL works in Chinese mainland.

Recommended

Set the custom sign-in URL as the default link

Path: Domain > Sign-in URL > Set as Link in Functional Emails

In some scenarios, you may need to direct employees to use the custom sign-in URL.

Upload an SSL certificate for your custom sign-in URL

Path: Domain > SSL Certificate Management > Upload Certificate

This allows secure HTTPS access to your custom sign-in URL.

Force HTTPS

Path: Domain > SSL Certificate Management > Force HTTPS

This enforces an HTTPS connection when accessing your custom sign-in URL, improving security.

Enforce app-specific passwords for all users / Prohibit third-party clients for all users

Paths:

1. Security > Account Security > Password Policy > Force App-specific Password / Allow Third-Party Clients

2. Security > Account Security > Access Policy > Disable Third-Party Client Access Policy

If you want to enable the 'Only allow sign-in via this identity source' option, you must enforce app-specific passwords to ensure standard protocols (SMTP, IMAP, POP) continue to work.

We strongly recommend this. Most mailbox security incidents stem from standard protocols. Enforcing app-specific passwords or disabling third-party clients can eliminate these security risks and prevent account takeover or financial loss.

Note: After app-specific passwords are enabled, users can no longer authenticate with standard protocols by using their regular account passwords. Each user must create a unique app-specific password to use with these protocols. Plan your rollout carefully to minimize disruption, especially for system mail accounts.

  1. On the OAuth2.0 Configuration page, fill in the following fields.

Important: For the initial setup, you must test and verify the connection. Keep the Set as Default Sign-in Method option disabled to avoid locking users out of their mailboxes.

Parameter

Description

Basic configuration

Display name

This name appears on the button on the user sign-in page.

App logo

This logo appears on the sign-in page as the entry for OAuth 2.0 sign-in.

Client ID

The client ID provided by your Enterprise IdP.

Client secret

The client secret provided by your Enterprise IdP.

Scope

The scope defined in the OAuth 2.0 authorization endpoint. This field is optional if your IdP does not support scopes.

Authorization URL

The OAuth 2.0 authorization endpoint, which is the sign-in page URL of your Enterprise IdP.

Token URL

The OAuth 2.0 token endpoint, used to exchange an authorization code for a token or a refresh token for a new access token.

UserInfo endpoint HTTP request message

The UserInfo endpoint retrieves user information in exchange for a token. Describe the call method here by using a standard HTTP request message.

The ${access_token} placeholder represents the access token variable. You can change the variable name as needed.

Use HTTP for UserInfo endpoint

If set to false, an HTTPS connection is used.

JsonPath for the email field in the UserInfo endpoint response

This path retrieves the current user's email during sign-in. You can use an online JsonPath tool to validate it.

End-Session endpoint HTTP request message

The End-Session endpoint is a browser-side endpoint that clears the Enterprise IdP's sign-in state. Describe the call method here by using a standard HTTP request message.

The ${redirect_uri} placeholder represents the redirect URI variable. You can change the variable name as needed.

Use HTTP for End-Session endpoint

If set to false, an HTTPS connection is used.

Redirect URI

You must configure all of these URLs as redirect URIs in your Enterprise IdP.

Mailbox Sign-in URL

The URL for signing in to the mailbox via the IdP. This should be your custom sign-in URL for Alibaba Cloud Mail.

Sign-in configuration

Enable identity source

You must enable this switch to test or use this identity source for sign-in.

Enabling this option adds an OAuth 2.0 sign-in button for this identity source to the sign-in page.

Set as Default Sign-in Method

When enabled, visiting your custom sign-in URL for Alibaba Cloud Mail automatically redirects to the Enterprise IdP sign-in page.

Important: Ensure you can successfully sign in by using this identity source before you enable this option. Otherwise, users will be locked out of their mailboxes.

Only allow sign-in via this identity source

We recommend that new enterprises enable this switch. Existing enterprises with many active mailboxes should enable it with caution.

When enabled, users can only authenticate through this identity source and are blocked from using other methods such as their mailbox password. For example:

  1. Users cannot sign in with their mailbox password at the official Alibaba Cloud Mail sign-in page.

  2. Standard protocols and third-party clients (such as Outlook or Foxmail) cannot authenticate with mailbox passwords. You must enable app-specific passwords and use the generated passwords for authentication.

Important: Ensure you have enforced app-specific passwords for all users (go to Security > Account Security > Password Policy and select Force App-specific Password). Otherwise, standard protocols and third-party clients (such as Outlook or Foxmail) will not work.

  1. After you complete the configuration, click Save to create the identity source.

Step 3: Validate the integration

After you save the configuration, a confirmation message appears. You must verify that you can sign in to Alibaba Cloud Mail through your Enterprise IdP.

In a browser, copy the URL and open it in incognito mode. Click the OAuth 2.0 icon to be redirected to your Enterprise IdP for sign-in.

image

image.png