卓:如何检查凭据是否正确? [英] AWS: How to check that credentials are correct?

查看:105
本文介绍了卓:如何检查凭据是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下功能(使用Javascript)应该接受accessKey和secretKey并检查它们是否正确:

The following function (in Javascript) is supposed to accept accessKey and secretKey and check whether they are correct:

function checkKeys(accessKey, secretKey) {
    var cred = new AWS.Credentials(accessKey, secretKey, null);
    cred.get(function(err) {
        if (err) {
            console.log("ERROR!")
        } else {
            console.log("Keys are OK")
        }
    })
}

我希望get()方法在凭据不正确的情况下返回错误.我不知道为什么,但是我提供的凭据并不重要,我从不会收到错误,并且控制台总是打印"Keys OK".

I'd expect that get() method returns an error in case of incorrect credentials. I don't know why, but it doesn't matter what credentials I give, I never get an error, and console always prints "Keys are OK".

推荐答案

您不能真正检查凭据是否正确".考虑用户角色.可能已授权用户进行一个API调用,但无权进行另一个API调用.您唯一可以做的一般事情是确保您拥有的ID +密钥对是具有STS.getCallerIdentity()的有效AWS凭证(请参阅

You cannot really check that credentials are "correct". Think about user roles. User may be authorized to make one API call, but not another. The only generic thing you can do is make sure that ID+key pair you have are valid AWS credentials with STS.getCallerIdentity() (see SDK docs for details). Note that it will return caller details even if this caller has no access to any of the services, so take the results with a grain of salt.

这篇关于卓:如何检查凭据是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆