
# 调用API报"Incorrect IAM authentication information"
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": "APIG.0301", 
  "request_id": "******" 
}
```
**可能原因**
签名认证算法使用有问题，客户端计算的签名结果与API网关计算的签名结果不同。
**解决方法**
1. 下载[js版本](https://obs.cn-north-1.myhwclouds.com/apig-sdk/ApiGateway-javascript-sdk.zip)，查看可视化签名SDK，获取签名字符串。
2. 解压压缩包，使用浏览器打开"demo.html"文件。
3. 获取x-sdk-date值，x-sdk-date值必须与当前时间相差在15min以内。 
   1. 在键盘中按下"F12"，并在页面中选择"Sources \> Snippets \> New snippet"。
   
   2. 将以下代码复制到右侧的Script snippet中，然后在左侧右键Script snippet名称，选择"Run"后，"Console"中打印的值就是x-sdk-date值。
   
   
   ![](https://support.huaweicloud.com/apig_faq/zh-cn_image_0000001484037253.png "点击放大")
   ```
   function twoChar(s) {
       if (s >= 10) {
           return "" + s
       } else {
           return "0" + s
       }
   }
   function getTime() {
       var date = new Date();
       return "" + date.getUTCFullYear() + twoChar(date.getUTCMonth() + 1) + twoChar(date.getUTCDate()) + "T" +
           twoChar(date.getUTCHours()) + twoChar(date.getUTCMinutes()) + twoChar(date.getUTCSeconds()) + "Z"
   }
   getTime()
   ```
   
   
4. 将x-sdk-date添加到Headers中，并填写其余参数，单击"debug"获取签名字符串。 
   ![](https://support.huaweicloud.com/apig_faq/zh-cn_image_0000002155559794.png "点击放大")
   非get\\delete\\head请求，需要携带body体，需要在上图Body框中添加body（格式与发送请求的body一致）。
   
   
5. 比较本地代码中签名结果与js可视化签名结果。 
   例如排查java语言签名代码中的**canonicalRequest** 、**stringToSign** 、**authorizationHeader**值，与js可视化签名字符串是否一致。
   ![](https://support.huaweicloud.com/apig_faq/zh-cn_image_0000001483842941.png "点击放大")
   
   
 #### 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": "APIG.0301", 
  "request_id": "******" 
}
```
**可能原因**
- aksk签名计算错误。
- ak对应的sk不匹配。请检查使用的sk是否正确。
- aksk频繁出现鉴权出错，连续错误5次以上，被锁定5分钟（5分钟内鉴权失败，误以为是异常的鉴权请求）。请在5分钟之后重试。
**解决方法**
- 请参考[Incorrect IAM authentication information: verify aksk signature fail]解决方法。
- 请检查使用的sk是否正确。
- 请在5分钟之后重试。
 #### Incorrect IAM authentication information: decrypt token fail
```
{
  "error_msg": "Incorrect IAM authentication information: decrypt token fail",
  "error_code": "APIG.0301",
  "request_id": "******"
}
```
**可能原因**
用户的API所属IAM认证，TOKEN解析失败。
**解决方法**
- 检查获取的token是否为对应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": "APIG.0301",
"request_id": "******"
}
```
**可能原因**
用户的API所属IAM认证，使用AK/SK签名方式访问，但是AK不存在。
**解决方法**
检查AK填写是否正确。
