文档

认证器管理

认证器的查询、修改、删除

前提条件

  1. 请先完成阿里云账号注册、实名认证、开通安全认证创建应用

  2. 请完成获取阿里云访问密钥;

  3. 认证器管理适用于 IFAA、WebAuthn、TOTP,如需使用请在应用中勾选认证方式。详情请查看修改应用认证方式。

  4. SDK&Demo下载

获取认证器列表

请求认证器列表, 返回认证器详细信息。

请求参数

名称

类型

必填

示例值

描述

ApplicationExternalId

String

A0000001

应用外部ID,该字段在创建应用时指定,在应用详情页中查看

UserId

String

user-test-1

用户的唯一标识, 例如:userId、手机号、邮箱等

AuthenticatorType

String

TOTP

固定值:TOTP、WEBAUTHN、IFAA

PageNumber

Integer

1

当前开始读取的位置,不设置时默认为1

PageSize

Integer

10

本次读取的最大数据记录数量,不指定时使用默认值

返回数据

名称

类型

示例值

描述

RequestId

String

78514973-F2F7-0B9E-BE46-AC6DFF2E9908

请求ID

TotalCount

Integer

84

认证器总数

PageNumber

Integer

2

读取到的位置

PageSize

Integer

10

每页记录数量,当客户端未提供或提供的数量错误时会返回服务端的值

Authenticators

Map

Authenticator列表,Map<String, List<?>>

Authenticator解析

字段

类型

备注

ApplicationExternalId

String

应用ID

AuthenticatorUuid

String

认证器UUID

CredentialId

String

身份证明ID

AuthenticatorType

String

认证器类型, 如 webauthn

AuthenticatorName

String

身份证明对应的认证器名称

RegisterTime

Long

创建时间,时间戳格式

LastVerifyTime

Long

最后验证时间,如果新注册的则为注册时间,时间戳格式

请求示例

请求方式:POST

https://idaas-doraemon.aliyuncs.com/?Action=ListAuthenticators
&Version=2021-05-20
&ApplicationExternalId=A0000001
&UserId=user-test-1
&<公共请求参数>

正常返回示例 -获取认证器列表通过

{
  "TotalCount": 1,
  "RequestId": "78514973-F2F7-0B9E-BE46-AC6DFF2E9908",
  "PageSize": 10,
  "PageNumber": 1,
  "Authenticator": [
    {
      "RegisterTime": 1632835006133,
      "Type": "TOTP",
      "AuthenticatorUuid": "06828e19c13fcd1ef641d1d53ae8d4a3yVgFUDgy2SK",
      "CredentialId": "9fc55a5d68835fe8efaef3f73306e47e9FzIMsZpjgj",
      "LastVerifyTime": 1632835006133,
      "AuthenticatorName": "TOTP",
      "ApplicationExternalId": "dc515f66fa5aa0fa2a1aa4c85fd86742ePbf2IsWtSk"
    }
  ]
}

错误返回示例 - 请求参数中应用ID错误

{
  "Success": false,
  "Code": "Operation.Failure.Application.ResourceNotExist",
  "Message": "Operation.Failure.Application.ResourceNotExist",
  "RequestId": "1C0EE50A-B3BB-42FD-AB59-E3FE88976982",
  "Data":null
}

查询认证器详情

查询认证器, 返回认证器详细信息。

请求参数

名称

类型

必填

示例值

描述

ApplicationExternalId

String

A0000001

应用外部ID,该字段在创建应用时指定,在应用详情页中查看

AuthenticatorUuid

String

06828e19c13fcd1ef641d1d53ae8d4a3yVgFUDgy2SK

认证器UUID

UserId

String

user-test-1

用户的唯一标识, 例如:userId、手机号、邮箱等

返回数据

名称

类型

示例值

描述

RequestId

String

78514973-F2F7-0B9E-BE46-AC6DFF2E9908

请求ID

Authenticator

Object

Authenticator实体类

Authenticator解析

字段

类型

备注

ApplicationExternalId

String

应用ID

AuthenticatorUuid

String

认证器UUID

CredentialId

String

身份证明ID

AuthenticatorType

String

认证器类型, 如 webauthn

AuthenticatorName

String

身份证明对应的认证器名称

RegisterTime

String

创建时间

LastVerifyTime

String

最后验证时间,如果新注册的则为注册时间

请求示例

请求方式:POST

https://idaas-doraemon.aliyuncs.com/?Action=GetAuthenticator
&Version=2021-05-20
&ApplicationExternalId=A0000001
&ApplicationUuid=A0000001
&UserId=user-test-1
&<公共请求参数>

正常返回示例 -获取认证器详情通过

{
  "RequestId": "E0E92A30-1DB6-0E89-9929-D120DFE11F19",
  "Authenticator": {
    "RegisterTime": 1632835006133,
    "Type": "TOTP",
    "AuthenticatorUuid": "06828e19c13fcd1ef641d1d53ae8d4a3yVgFUDgy2SK",
    "CredentialId": "9fc55a5d68835fe8efaef3f73306e47e9FzIMsZpjgj",
    "LastVerifyTime": 1632835006133,
    "AuthenticatorName": "TOTP"
  }
}

错误返回示例 - 请求参数中应用ID错误

{
  "Success": false,
  "Code": "Operation.Failure.Application.ResourceNotExist",
  "Message": "Operation.Failure.Application.ResourceNotExist",
  "RequestId": "1C0EE50A-B3BB-42FD-AB59-E3FE88976982",
  "Data":null
}

修改认证器

修改认证器。

请求参数

名称

类型

必填

示例值

描述

ApplicationExternalId

String

A0000001

应用外部ID,该字段在创建应用时指定,在应用详情页中查看

AuthenticatorUuid

String

06828e19c13fcd1ef641d1d53ae8d4a3yVgFUDgy2SK

认证器UUID

AuthenticatorName

String

My认证器

认证器名称

UserId

String

user-test-1

用户的唯一标识, 例如:userId、手机号、邮箱等

返回数据

名称

类型

示例值

描述

RequestId

String

78514973-F2F7-0B9E-BE46-AC6DFF2E9908

请求ID

请求示例

请求方式:POST

https://idaas-doraemon.aliyuncs.com/?Action=UpdateAuthenticatorAttribute
&Version=2021-05-20
&ApplicationExternalId=A0000001
&ApplicationUuid=A0000001
&UserId=user-test-1
&AuthenticatorName=My认证器
&<公共请求参数>

正常返回示例 -修改认证器成功

{
  "RequestId": "E0E92A30-1DB6-0E89-9929-D120DFE11F19"
}

错误返回示例 - 请求参数中应用ID错误

{
  "Success": false,
  "Code": "Operation.Failure.Application.ResourceNotExist",
  "Message": "Operation.Failure.Application.ResourceNotExist",
  "RequestId": "1C0EE50A-B3BB-42FD-AB59-E3FE88976982",
  "Data":null
}

删除认证器

删除认证器。

请求参数

名称

类型

必填

示例值

描述

ApplicationExternalId

String

A0000001

应用外部ID,该字段在创建应用时指定,在应用详情页中查看

AuthenticatorUuid

String

06828e19c13fcd1ef641d1d53ae8d4a3yVgFUDgy2SK

认证器UUID

UserId

String

user-test-1

用户的唯一标识, 例如:userId、手机号、邮箱等

返回数据

名称

类型

示例值

描述

RequestId

String

78514973-F2F7-0B9E-BE46-AC6DFF2E9908

请求ID

请求示例

请求方式:POST

https://idaas-doraemon.aliyuncs.com/?Action=DeregisterAuthenticator
&Version=2021-05-20
&ApplicationExternalId=A0000001
&ApplicationUuid=A0000001
&UserId=user-test-1
&AuthenticatorName=My认证器
&<公共请求参数>

正常返回示例 -删除认证器成功

{
  "RequestId": "E0E92A30-1DB6-0E89-9929-D120DFE11F19"
}

错误返回示例 - 请求参数中应用ID错误

{
  "Success": false,
  "Code": "Operation.Failure.Application.ResourceNotExist",
  "Message": "Operation.Failure.Application.ResourceNotExist",
  "RequestId": "1C0EE50A-B3BB-42FD-AB59-E3FE88976982",
  "Data":null
}

代码示例(Java)

需要在一个Java的Maven 项目中引入服务端SDK包, 坐标如下。

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.idaas_doraemon.model.v20210520.ServiceInvokeRequest;
import com.aliyuncs.idaas_doraemon.model.v20210520.ServiceInvokeResponse;
import com.aliyuncs.profile.DefaultProfile;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class IDaaSAuthSample {
    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static IAcsClient createClient(String accessKeyId, String accessKeySecret) throws Exception {
      	// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
        // 此处以把AccessKey 和 AccessKeySecret 保存在环境变量为例说明。您可以根据业务需要,保存到配置文件里。
        // 强烈建议不要把 AccessKey 和 AccessKeySecret 保存到代码里,会存在密钥泄漏风险
      	String accessKeyId = System.getenv("ACCESS_KEY_ID");
        String accessKeySecret = System.getenv("ACCESS_KEY_SECRET");
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-hangzhou",
                accessKeyId,
                accessKeySecret);
        // addEndpoint
        DefaultProfile.addEndpoint("cn-hangzhou",
                "idaas-doraemon",
                "idaas-doraemon.aliyuncs.com");
        // 访问的域名
        return new DefaultAcsClient(profile);
    }

    public static void main(String[] args_) throws Exception {
        // 获取认证器详情
        getAuthenticator();
    }
    public void getAuthenticator() throws Exception {
        IAcsClient client = IDaaSAuthSample.createClient("Your AccessKey", "Your AccessSecret");
        //认证器详情
        GetAuthenticatorRequest request = new GetAuthenticatorRequest();
                request.setApplicationExternalId("应用ID");
                request.setUserId("用户UserId");
                request.setAuthenticatorUuid("认证器UUID");
        // 复制代码运行请自行打印 API 的返回值
        try {
            GetAuthenticatorResponse response = client.getAcsResponse(request);
            System.out.println(JSONObject.toJSON(response.getAuthenticator()).toString());
        } catch (Exception e) {
            //根据e,getCode()判断异常原因
            System.out.println(e);
        }
    }
}

示例代码的maven依赖

  <dependency>
   <groupId>com.aliyun</groupId>
   <artifactId>aliyun-java-sdk-idaas-doraemon</artifactId>
   <version>1.2.4</version>
  </dependency>
  <dependency>
   <groupId>com.aliyun</groupId>
   <artifactId>aliyun-java-sdk-core</artifactId>
   <optional>true</optional>
   <version>[4.4.9,5.0.0)</version>
  </dependency>

  • 本页导读 (0)
文档反馈