API overview
This API reference is designed for users who want to integrate CIAM by using RESTful APIs. The APIs are divided into authentication APIs, management APIs, and user APIs.
1. API endpoint
The API endpoint uses the following format:
https://xxxx.api.aliyunidaas.com
Log on to the IDaaS console, choose , and then find the Instance Open API Domain Name of the target instance.
2. API categories
CIAM provides a wide range of APIs, which fall into three categories: authentication APIs, management APIs, and user APIs.
|
API type |
Caller |
Purpose |
Limits |
Authentication |
|
Authentication APIs |
Business system server |
Account and password logon, SMS logon, social media registration, SMS registration, and password retrieval. |
The APPLICATION_API scope must be granted. |
Protected by the application's accessToken. |
|
Management APIs |
Business system server |
Managing the account lifecycle, canceling an account, viewing user details, and more. |
The MANAGEMENT_APPLICATION_API scope must be granted. |
Protected by the application's accessToken. |
|
User APIs |
Business system server |
Changing a phone number, changing an email address, querying personal information, linking a third-party social account, and canceling an account |
Available after the end user logs on. |
Protected by the user's accessToken. |
3. API flows
In CIAM, fId identifies the entire flow. In a complete flow (such as account and password logon -> MFA -> profile completion -> successful logon), the flow is considered fully executed only after an authorization code or token is returned.
The complete logon or registration flow varies based on the application configuration in the CIAM console. For example, you can specify whether MFA is required after an account and password logon, and whether the user must complete the profile information (name, phone number, and email address) or change the password.
The fId parameter links the entire logon flow. Whether the next step requires a child flow after the current step is complete is indicated by the flowType parameter under data. For example, if MFA is required after an account and password logon, the following result is returned.
{
"success": true,
"code": "Operation.Success",
"message": "Operation.Success",
"requestId": "165840546xxxxxxxx$8a183b2c-8b93-834a-4e1e-378db7b925da",
"data": {
"fId": "202207212010534049551317948753920_X_BCD",
"flowType": "NEED_TWO_FACTOR",
"additional": {
"phoneNumber": "159xxxx4245"
"email": "xxxx@mail.com"
}
}
}
additional contains data that the next flow may need. This field is optional. For example, if the MFA page needs to display the phone number, the previous flow returns the corresponding content (the details depend on your business). Developers must run the next step of the flow based on flowType and call the relevant API.
Every child flow has a flow type and a flow identifier. The flow identifier is fId, and the flow type is flowType.When an API has a child flow, the API response always contains the corresponding flowType.Developers must run the next child flow based on flowType. The following table describes the flowType values:
|
FlowType value |
Use case |
Description |
|
NEED_TWO_FACTOR |
Logon authentication |
MFA is required. |
|
NEED_UPDATE_PASSWORD |
A password change is required. |
|
|
NEED_BIND_SOCIAL_ACCOUNT |
A social account must be linked. |
|
|
NEED_BIND_PHONE_NUMBER |
A phone number must be linked. |
|
|
NEED_BIND_EMAIL |
An email address must be linked. |
|
|
NEED_SET_USERNAME |
A username must be set. |
|
|
NEED_LOGIN_OR_REGISTOR |
Logon or registration is required. |
|
|
NEED_COMPLETE_ACCOUNT_ATTR |
Account attributes must be completed. |
|
|
NEED_COMPLETE_EXTENSION_ATTR |
Extension attributes must be completed. |
|
|
USER_TWO_FACTOR_AUTH |
User operations |
MFA for critical operations. |
|
USER_UPDATE_DEVICE |
The user updates the device information. |
|
|
USER_UPDATE_EMAIL |
The user changes the email address. |
|
|
USER_UPDATE_PWD |
The user changes the password. |
|
|
USER_UPDATE_PHONE |
The user changes the phone number. |
|
|
USER_UPDATE_SOCIAL |
The user changes the third-party account. |
|
|
USER_UNSUBSCRIBE |
Account cancellation. |
4. SSO flow
CIAM implements single sign-on (SSO) based on the standard authorization code flow.
The business system redirects the user to the CIAM authentication address (you can include the redirectUrl and state parameters). After CIAM authentication is complete, CIAM calls back the business system to complete SSO (the state parameter is not processed).
Request example
https://xxxx.aliyun.com?code=xxxx&state=xxxx
Response example
The business system handles the redirect based on the redirectUrl parameter in data.
{
"success": true,
"code": "Operation.Success",
"message": "Operation.Success",
"requestId": "165778288****$bebbd27b-e9c3-db44-b06f-adbc5ef0****",
"data": {
"redirectUrl": "https://xxxx.aliyun.com?code=xxxx&state=xxxx"
}
}
5. Terms
|
Term |
Description |
|
OAuth 2.0 |
OAuth is a standardized authorization protocol. It is commonly used to let internet users grant a website or application access to their information on other websites without providing a password. OAuth 2.0 provides specific authorization flows for web applications, desktop applications, mobile phones, and smart devices, and is more secure than OAuth 1.0. |
|
OIDC |
OpenID Connect is a simple identity layer on top of the OAuth 2.0 protocol. It lets a client verify the identity of the end user based on the authentication performed by the authorization server, and get basic profile information about the end user in an interoperable, REST-like manner. OpenID Connect supports a wide range of clients, including web-based clients, mobile clients, and JavaScript clients. |
|
code (authorization code) |
A temporary ticket for entering different systems. It is single-use and valid for a very short time. It corresponds to the authorization code in the OAuth protocol. |
|
Single sign-on (SSO) |
Single Sign-On. A user needs to log on only once to access all applications. As applications evolved, SSO has taken multiple implementation forms. In the context of IDaaS, only identity federation mechanisms based on standard protocols such as SAML and OIDC are referred to as single sign-on. |
|
id_token |
id_token is an identity token. You can parse the content of id_token to get information about the currently logged-on account. |
|
access_token |
An authorization token, which is used to call the APIs provided by CIAM. |
|
refresh_token |
A refresh token. After the access_token expires, you can use refresh_token to get a new token. |
|
idaasAppId |
The unique identifier of an IDaaS application. You can get it from the application list in the IDaaS console. |
|
enterpriseAuthId |
The unique identifier of an IDaaS authentication source. You can get it from the authentication source list in the IDaaS console. |
|
Multi-factor authentication (MFA/2FA) |
Multi-Factor Authentication (MFA) and Two-Factor Authentication (2FA) require the user to provide multiple authentication factors at logon to cross-check the identity of the visitor. Because passwords have inherent security weaknesses, MFA is commonly used to strengthen account-and-password logon. IDaaS supports enabling MFA with SMS, email, or a one-time password (OTP) for account and password authentication. |
|
Authentication source |
IDaaS uses authentication sources to represent social authentication sources and security authentication sources. Administrators only need to configure the connection settings of an authentication source to complete the integration. Users can then log on to the platform by using their existing account and password from these authentication sources, or by scanning a code. |
6. Scope definitions
In the OAuth 2.0 protocol, a scope indicates the range of protected resources that the access token authorized by the user can access. A protected resource can perform different operations and return different information based on the scope value of the access token provided in the request and other parameters. To pass multiple scopes, separate them with spaces, for example, openid profile phone.
In the OIDC protocol, a scope can also control the claims of the id_token or the content returned by the userinfo endpoint. For example, if the phone scope is passed during authorization, the user information returns phone_number and phone_number_verified.
In CIAM, scopes fall into two types. The first type is defined in the OIDC and OAuth 2.0 protocols and is named in lowercase letters. The second type controls access permissions for CIAM APIs (resources) and is named in uppercase letters.
CIAM supports and provides the following scopes:
|
Scope name |
Permission |
Description |
Grant method |
|
APPLICATION_API |
Read |
Grants access to application-level APIs. |
Granted to new applications by default. Dynamic configuration is allowed in the permission settings of the application details. |
|
MANAGEMENT_APPLICATION_API |
Read/Write |
Grants access to administrator-level APIs. |
Dynamic configuration is allowed only in the permission settings of the application details. |
|
USER_API |
Read/Write |
Grants access to user-level APIs. |
Dynamic configuration is not allowed. This permission is granted to applications by default. |
|
openid |
Read |
An OIDC scope. This scope is required for the token endpoint to return |
|
|
profile |
Read |
Grants permission to read the default attributes of the user, for example, |
|
|
|
Read |
Grants permission to read the email address of the user, and returns |
|
|
phone |
Read |
Grants permission to read the phone number of the user, and returns |
After the user completes logon authentication, the token endpoint returns the corresponding tokens (access_token, refresh_token, and id_token). The access token (access_token) is granted the USER_API scope by default, so that user-level APIs can be called with the user access token. After the user access token expires, the client can refresh the application token. To refresh a user token, you must explicitly pass USER_API in the scope parameter. The refreshed user access token can then continue to access user-level APIs.
7. response_type definitions
In the OAuth 2.0 protocol, response_type indicates the authorization flow required by the authorization service (CIAM), including which parameters CIAM returns. The OAuth 2.0 protocol also defines the valid values of response_type:
|
response_type |
Description |
|
code |
The authorization code flow. The authorization code (code) is returned after authentication is complete. |
|
token |
The implicit grant flow. The user token information is returned after authentication is complete. |
When a user registers or logs on, if the response_type parameter in the request is outside the valid values defined by the OAuth 2.0 protocol, CIAM defaults response_type to token.