Data Agent Console SSO Integration Guide
This guide helps developers securely embed the Data Agent console into a custom O&M platform or BI portal using Alibaba Cloud Resource Access Management (RAM) and Security Token Service (STS). After integration, users access and use Data Agent features directly from your platform without logging in to their Alibaba Cloud account again. This improves workflow continuity and efficiency.
How It Works
The integration uses temporary credentials based on a RAM role. The process is as follows:
Obtain temporary credentials: Your backend service calls the
AssumeRoleAPI using a preconfigured RAM user’s credentials. It assumes a RAM role with Data Agent permissions and receives temporary credentials (AccessKey ID, AccessKey secret, and SecurityToken).Obtain a sign-in token: Your backend service calls the Alibaba Cloud sign-in service’s
GetSigninTokenAPI using those temporary credentials. It receives a one-time sign-in token (SigninToken).Construct a federated sign-in URL using the retrieved
SigninTokenand the URL of the target Data Agent page.Frontend embedding: The backend returns this joint logon URL to the frontend, which embeds it as the value of the
srcattribute in an<iframe>tag to enable login-free display.
Prerequisites
Before you start development, complete the following configurations:
A RAM user has been created to invoke the Security Token Service.
Log on to the RAM console.
Create a RAM user. Set the access method to Use permanent AccessKey. Save its AccessKey ID and AccessKey secret.
For more information, see Create a RAM user.
Attach the
AliyunSTSAssumeRoleAccesssystem policy to this RAM user. This grants permission to call theAssumeRoleAPI.For more information, see Manage RAM user permissions.
A RAM role has been created to access Data Agent.
In the RAM console, create a RAM role. Set Trusted entity type to Alibaba Cloud account. After creation, record the role’s ARN.
For more information, see Create a RAM role trusted by an Alibaba Cloud account.
Grant the role permissions to access Data Agent. You have two options:
Recommended: Attach the
AliyunDMSDataAgentFullAccesssystem policy for full functionality.Custom: Create a custom policy that grants least privilege. For a list of related APIs, see the Data Agent API overview.
Example custom policy (grants only file analysis permissions):
{ "Version": "1", "Statement": [ { "Action": [ "dms:ListDataAgentSession", "dms:DescribeDataAgentSession", "dms:CreateDataAgent", "dms:UpdateDataAgentSession", "dms:DescribeFileUploadSignature", "dms:ListDataCenterColumn", "dms:EditDataCenterTableColumn", "dms:SaveDataAgentReport", "dms:ListDataCenterTable", "dms:DescribeDataCenterTable", "dms:DescribeDataAgentStatus", "dms:CreateDataAgentSession", "dms:SendChatMessage", "dms:ListFileUpload", "dms:DeleteFileUpload", "dms:DescribeDataCenterDatabase", "dms:RegistryDataAgentUser", "dms:DescribeDataAgentReport", "dms:ListDataCenterDatabase", "dms:GetChatContent", "dms:FileUploadCallback", "dms:ListDataCenterPreviewData" ], "Resource": "*", "Effect": "Allow" } ] }
Development Steps
Obtain temporary credentials in your backend:
In your backend service, use the AccessKey of the previously created RAM user to call the
<a baseurl="t3236779_v1_0_0.xdita" data-node="3314723" data-root="61777" data-tag="xref" href="t2155837.xdita#" id="494fb13160jfy">AssumeRole</a>API.RoleArn: Enter the ARN of the RAM role you created earlier.RoleSessionName: Enter a custom session name. Use your internal user ID for audit tracking.DurationSeconds: Set the validity period of the temporary credentials in seconds.
Obtain a sign-in token in your backend:
Use the temporary credentials (AccessKeyId, AccessKeySecret, and SecurityToken) from the previous step to call the
<a baseurl="t3236779_v1_0_0.xdita" data-node="2041376" data-root="61777" data-tag="xref" href="t1840243.xdita#" id="6a1a7ad32atvz">GetSigninToken</a>API.NoteThe TicketType parameter can be normal or mini. Use mini to embed the content in an iFrame.
The default value is normal. Its domain is https://agent.dms.aliyun.com/.
For BID virtual operators, use mini with the domain https://agent4service.dms.aliyun.com/.
Build the federated sign-in URL in your backend
Construct the final logon-free URL using the following format:
https://signin.aliyun.com/federation?Action=Login &LoginUrl=<URL to redirect after sign-in expires, usually your web app's 302 redirect URL> &Destination=<Target DataAgent page URL https://agent4service.dms.aliyun.com/> &SigninToken=<The sign-in token you obtained>URL parameter reference:
Parameter
Description
Example
ActionSet to
Login.LoginLoginUrlOptional. The URL to redirect to after sign-in expires or when the user signs out. We recommend setting this to a page in your platform.
https://your-platform.com/loginDestinationRequired. The target Data Agent page URL. This must match the
TicketTypeyou used.https://agent4service.dms.aliyun.com/SigninTokenRequired. The sign-in token returned by the GetSigninToken API.
The value returned by the
GetSigninTokenAPI.The frontend uses an
<iframe>for embedding:Your backend returns the full URL from step three to the frontend. Your frontend application sets this URL as the
<iframe>element’ssrcattribute.<iframe src="[Federated sign-in URL from backend]" width="100%" height="800px" frameborder="0"></iframe>
Important Notes
Session timeout: The embedded page’s session lifetime equals the shorter of these two values:
The
DurationSecondsvalue passed to theAssumeRoleAPI.The RAM role’s configured maximum session duration.
Credential security: Follow the principle of least privilege for the RAM user with permanent credentials. Never expose its AccessKey ID or AccessKey secret in frontend code. All operations that use permanent credentials must run in your backend service.
Because this solution uses
<iframe>embedding, submit a ticket to add your platform’s domain to Data Agent’s cross-origin resource sharing (CORS) whitelist.
Appendix
The following Java example shows the core logic and key configuration. Use it to understand and integrate quickly into your project.
Project dependencies:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.aliyun.dms.agent</groupId> <artifactId>data-agent-login-demo</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.15</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.13</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>sts20150401</artifactId> <version>1.1.7</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.83</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>tea-openapi</artifactId> <version>0.3.9</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>tea-console</artifactId> <version>0.0.1</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>tea-util</artifactId> <version>0.2.23</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>credentials-java</artifactId> <version>1.0.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>Configuration file example:
# RAM User's permanent credentials ACCESS_KEY=LTAI5t... SECRET_KEY=your_secret... # RAM Role's ARN ROLE_ARN=acs:ram::...Java sample code:
package com.aliyun.dms.agent; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.aliyun.sts20150401.models.AssumeRoleResponse; import com.aliyun.sts20150401.models.AssumeRoleResponseBody; import com.aliyun.tea.TeaException; import org.apache.http.HttpStatus; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.IOException; import java.net.URISyntaxException; /** * Load configuration from .env file * */ public class ConfigLoader { public static AssumeRoleLoginProperty loadLoginProperty(String env) { try (InputStream input = ConfigLoader.class.getClassLoader().getResourceAsStream(env)) { if (input == null) { throw new RuntimeException("Cannot find .env file"); } Properties prop = new Properties(); prop.load(input); return new AssumeRoleLoginProperty( prop.getProperty("ACCESS_KEY"), prop.getProperty("SECRET_KEY"), prop.getProperty("ROLE_ARN") ); } catch (Exception e) { throw new RuntimeException("Failed to load configuration", e); } } } public class AssumeRoleLoginProperty { private final String key; private final String secret; private final String roleArn; public AssumeRoleLoginProperty(String key, String secret, String roleArn) { this.key = key; this.secret = secret; this.roleArn = roleArn; } public String getKey() { return key; } public String getRoleArn() { return roleArn; } public String getSecret() { return secret; } } public class AgentAssumeRoleLoginHelper { private static final String SIGN_IN_TOKEN_URL = "https://signin4service.aliyun.com/federation"; private static final String SIGN_IN_LOGIN_URL = "https://signin4service.aliyun.com/login.htm"; private static final String DATA_AGENT_URL = "https://signin4service.dms.aliyun.com"; private final AssumeRoleLoginProperty assumeRoleLoginProperty; public AgentAssumeRoleLoginHelper(AssumeRoleLoginProperty assumeRoleLoginProperty) { this.assumeRoleLoginProperty = assumeRoleLoginProperty; } public static void main(String[] args_) throws Exception { try { AssumeRoleLoginProperty property = ConfigLoader.loadLoginProperty(".env"); AgentAssumeRoleLoginHelper helper = new AgentAssumeRoleLoginHelper(property); helper.getLoginUrl("SessionA"); } catch (Exception e) { e.printStackTrace(); } } /** * Get sign-in token using security credentials * <a href="https://help.aliyun.com/document_detail/91913.html">GetSigninToken documentation</a> */ private static String getSignInToken(String accessKeyId, String accessKeySecret, String securityToken) throws IOException, URISyntaxException { URIBuilder builder = new URIBuilder(SIGN_IN_TOKEN_URL); builder.setParameter("Action", "GetSigninToken") .setParameter("AccessKeyId", accessKeyId) .setParameter("AccessKeySecret", accessKeySecret) .setParameter("SecurityToken", securityToken) .setParameter("TicketType", "normal"); // Change from normal to mini HttpGet request = new HttpGet(builder.build()); try (CloseableHttpClient httpclient = HttpClients.createDefault()) { try (CloseableHttpResponse response = httpclient.execute(request)) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String context = EntityUtils.toString(response.getEntity()); JSONObject jsonObject = JSON.parseObject(context); return jsonObject.getString("SigninToken"); } else { System.out.println(response.getStatusLine()); } } } return null; } /** * description : * <p>Initialize the client using credentials</p> * * @return Client * @throws Exception */ public com.aliyun.sts20150401.Client createClient() throws Exception { // For production, use a more secure credential method without AK. See: https://help.aliyun.com/document_detail/378657.html. com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() .setAccessKeyId(assumeRoleLoginProperty.getKey()) .setAccessKeySecret(assumeRoleLoginProperty.getSecret()); // For the endpoint, see https://api.aliyun.com/product/Sts. config.endpoint = "sts.cn-beijing.aliyuncs.com"; return new com.aliyun.sts20150401.Client(config); } private static String buildLoginUrl(String signInToken) throws URISyntaxException { URIBuilder builder = new URIBuilder(SIGN_IN_TOKEN_URL); builder.setParameter("Action", "Login"); // URL to redirect after sign-in expires, usually your web app's 302 redirect URL builder.setParameter("LoginUrl", SIGN_IN_LOGIN_URL); builder.setParameter("Destination", DATA_AGENT_URL); builder.setParameter("SigninToken", signInToken); HttpGet request = new HttpGet(builder.build()); return request.getURI().toString(); } /** * @param sessionName Role session name. You define this value. Usually set to the caller’s identity, such as username. */ public void getLoginUrl(String sessionName) throws Exception { try { /* Step 1 Get temporary AK, SK, and SecurityToken using AssumeRole */ System.out.println("-------------------- AssumeRole --------------------"); com.aliyun.sts20150401.Client client = createClient(); com.aliyun.sts20150401.models.AssumeRoleRequest assumeRoleRequest = new com.aliyun.sts20150401.models.AssumeRoleRequest(); assumeRoleRequest.setRoleArn(assumeRoleLoginProperty.getRoleArn()); assumeRoleRequest.setRoleSessionName(sessionName); assumeRoleRequest.setDurationSeconds(3600L); com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); // Print the API response when running this code. AssumeRoleResponse response = client.assumeRoleWithOptions(assumeRoleRequest, runtime); AssumeRoleResponseBody.AssumeRoleResponseBodyCredentials credentials = response.getBody().getCredentials(); System.out.println("Expiration: " + credentials.getExpiration()); System.out.println("Access Key Id: " + credentials.getAccessKeyId()); System.out.println("Access Key Secret: " + credentials.getAccessKeySecret()); System.out.println("Security Token: " + credentials.getSecurityToken()); /* Step 2 Get SigninToken */ System.out.println("-------------------- GetSigninToken --------------------"); String signInToken = getSignInToken(credentials.getAccessKeyId(), credentials.getAccessKeySecret(), credentials.getSecurityToken()); System.out.println("Your SigninToken is: " + signInToken); /* Step 3 Get login URL */ System.out.println("-------------------- GetLoginUrl --------------------"); String loginUrl = buildLoginUrl(signInToken); System.out.println("Your LoginUrl is: " + loginUrl); } catch (TeaException error) { // This prints errors only for demonstration. Handle exceptions carefully in production. Never ignore them. // Error message System.out.println(error.getMessage()); // Diagnostic link System.out.println(error.getData().get("Recommend")); com.aliyun.teautil.Common.assertAsString(error.message); } catch (Exception _error) { TeaException error = new TeaException(_error.getMessage(), _error); // This prints errors only for demonstration. Handle exceptions carefully in production. Never ignore them. // Error message System.out.println(error.getMessage()); // Diagnostic link System.out.println(error.getData().get("Recommend")); com.aliyun.teautil.Common.assertAsString(error.message); } } }