
# IAM认证信息错误
用户在调用使用IAM认证的API时，常见如下IAM认证信息错误：
- [Incorrect IAM authentication information: verify aksk signature fail]
- [Incorrect IAM authentication information: AK access failed to reach the limit,forbidden]
- [Incorrect IAM authentication information: decrypt token fail]
- [Incorrect IAM authentication information: Get secretKey failed]
 #### Incorrect IAM authentication information: verify aksk signature fail
```
{    
  "error_msg": "Incorrect IAM authentication information: verify aksk signature fail, ......   
  "error_code": "APIC.0301", 
  "request_id": "******" 
}
```
**可能原因**
签名认证算法使用有问题，客户端计算的签名结果与ROMA Connect计算的签名结果不同。
**解决方法**
1. 获取ROMA Connect计算的canonicalRequest。
   从报错信息的body获取API网关计算的canonicalRequest：
   ```
   {   
     "error_msg": "Incorrect IAM authentication information: verify aksk signature fail,canonicalRequest:PUT|/v2/******/instances/******/configs/||authorization:SDK-HMAC-SHA256 Access=******, SignedHeaders=authorization;content-length;content-type;host;x-project-id;x-sdk-date, Signature=******|content-length:84|content-type:application/json;charset=UTF-8|host:******|x-project-id:******|x-sdk-date:20201117T072119Z||authorization;content-length;content-type;host;x-project-id;x-sdk-date|******",     
     "error_code": "APIC.0301",     
     "request_id": "******" 
   }
   ```
   把"\|"替换成换行符，得到下面内容：
   ```
   {   
     "error_msg": "Incorrect IAM authentication information: verify aksk signature fail,canonicalRequest:PUT
   /v2/******/instances/******/configs/
     authorization:SDK-HMAC-SHA256 Access=******, SignedHeaders=authorization;content-length;content-type;host;x-project-id;x-sdk-date, Signature=******
     content-length:84
     content-type:application/json;charset=UTF-8
     host:******
     x-project-id:******
     x-sdk-date:20201117T072119Z
     authorization;content-length;content-type;host;x-project-id;x-sdk-date
   ******",     
     "error_code": "APIC.0301",     
     "request_id": "******"
   }
   ```
   
2. 通过打印日志或调试中断的方式得到客户端计算的canonicalRequest，每种语言SDK中计算canonicalRequest的位置如下：
   表1常见语言SDK中计算canonicalRequest的位置 
   | 语言               | 位置                                                                               |
   |:---|:---|
   | java（版本\<3.1.0）  | libs/java-sdk-core-\*.jar中com.cloud.sdk.auth.signer.DefaultSigner.class中的sign函数。 |
   | java（版本\>=3.1.0） | libs/java-sdk-core-\*.jar中com.cloud.sdk.auth.signer.Signer.class中的sign函数。        |
   | cpp              | signer.cpp中的Signer::createSignature函数。                                           |
   | csharp           | signer.cs中的Sign函数。                                                               |
   | c                | signer.c中的sig_sign函数。                                                            |
   | go               | signer.go中的Sign函数。                                                               |
   | js               | signer.js中的Signer.prototype.Sign函数。                                              |
   | php              | signer.php中的Sign函数。                                                              |
   | python           | signer.py中的Sign函数。                                                               |
      
   
3. 比较[1]和[2]中canonicalRequest的域名、方法、协议、路径、query参数、headers参数、body参数等是否一致。
   - 若不一致，常见问题如下：
     - 签名头中有content-type，某些httpclient自动加了"charset=utf-8"。
     
     - 用户使用了代理，经过代理转发后，导致ROMA Connect的url/query/header/body与客户端签名的url/query/header/body不一致。
     
     - GET和DELETE方法，某些httpclient自动忽略body。
     
     - 某些旧的sdk版本，不支持url中的特殊字符。
     
     - 某些旧的sdk版本，不支持query参数同一个key多value（例如 ?a=1\&a=2）。
     
     - 某些旧的sdk版本，不能将query参数放到url中。
     
     - 签名传了user-agent头，实际发送请求使用的是不一样的的user-agent。
     
     - 多个名称相同的header。
     
     - 多个名称相同的query。
     
     - cannonicalRequest里面有authorization头（与签名头冲突）。
      
   
   - 若全部一致，请检查AppSecret或SK是否正确。 常见问题：AppSecret或SK中多填了空格。
     
    
 #### Incorrect IAM authentication information: AK access failed to reach the limit,forbidden
```
{    
  "error_msg": "Incorrect IAM authentication information: AK access failed to reach the limit,forbidden." ......   
  "error_code": "APIC.0301", 
  "request_id": "******" 
}
```
**可能原因**
- AK/SK签名计算错误。请参考[Incorrect IAM authentication information: verify aksk signature fail]解决方法。
- AK对应的SK不匹配。
- AK/SK频繁出现鉴权出错，连续错误5次以上，被锁定5分钟（5分钟内鉴权失败，误以为是异常的鉴权请求）。
- Token鉴权时，Token过期。
 #### Incorrect IAM authentication information: decrypt token fail
```
{
  "error_msg": "Incorrect IAM authentication information: decrypt token fail",
  "error_code": "APIC.0301",
  "request_id": "******"
}
```
**可能原因**
用户的API所属IAM认证，Token解析失败。
**解决办法**
- 检查获取Token的方法，Token是否正确。
- 检查获取Token的环境与调用的环境是否一致。
 
 #### Incorrect IAM authentication information: Get secretKey failed
```
{
"error_msg": "Incorrect IAM authentication information: Get secretKey failed,ak:******,err:ak not exist",
"error_code": "APIC.0301",
"request_id": "******"
}
```
**可能原因**
用户的API所属IAM认证，使用AK/SK签名方式访问，但是AK不存在。
**解决方法**
检查AK填写是否正确。
