TL; DR
为什么 authenticate
(或 login
)与AWS Cognito / AWS Cognito Identity Provider中的 SignUp
或 ChangePassword
相同?
我很难理解如何将AWS Cognito实现到API流程中 . 我对此进行了广泛的研究,感觉功能如此明显,我必须误解一些东西 .
此API将用于Android,iOS和SPA . 我想象通过我的api的基本流程, endpoints 是这样的:
/v1.0/authenticate/
它会接受user / pwd,然后服务器上的PHP会做这样的事情:
require 'vendor/autoload.php';
$sdk = new Aws\Sdk([
'region' => 'us-east-1',
'version' => 'latest'
]);
$client = $sdk->createCognitoIdentity(['profile' => 'app-test-cognito']);
$result = $client->login([
'ClientId' => '6p16oao60fvakje31lexabcmplgecliecd99ntid',
'Username' => $user,
'Password' => $pwd]);
并且 $result
将是一个类似的json字符串
{
"result": "success",
"token": "<the token>"
}
并且 token
将返回给客户端,客户端将其存储在localStorage / memory中,并在每次其他API调用时将其返回,直到它过期为止,使用 Authorization: Bearer <token>
. 我认为令牌是一个JWT,我可以测试每次调用的到期而不必离开我的API,还包括一个不可变的userId,并且可以通过使用基于API的秘密或签名测试进行解密来信任 .
但是很少或根本没有迹象表明存在这样的事情,除了最近的博客文章,使用Javascript,这表明有一个名为'authenticateUser'的JS方法:
https://mobile.awsblog.com/post/Tx2O14ZY8A5LFHT/Accessing-Your-User-Pools-using-the-Amazon-Cognito-Identity-SDK-for-JavaScript(我在这个SO问题中找到了这个链接:What is the REST (or CLI) API for logging in to Amazon Cognito user pools,这与我的相似,我会允许,但不是重复) .
但是,我去了他们的Github回购和did a search for 'authenticateUser',并没有找到这样的方法 . 我也did the same search in the PHP repo.不 .
顺便说一下,这个(下面)是一个真实的,工作 Signup
所以看起来(对我来说)它会跟随这样一个简单的身份验证也会起作用 . 我错过了什么?
require 'vendor/autoload.php';
$sdk = new Aws\Sdk([
'region' => 'us-east-1',
'version' => 'latest'
]);
$client = $sdk->createCognitoIdentityProvider(['profile' => 'app-test-cognito']);
$result = $client->signUp([
'ClientId' => '6p16oao60fvakje31lexabcmplgecliecd99ntid',
'Username' => 'fakeexampleusername',
'Password' => 'a#--sldjf383af09aw3jJJJL',
'UserAttributes' => [
[
'Name' => 'email',
'Value'=> 'me@example.com'
],
],
]); // based on pool settings, even sends out an email automatically.
注意:我还检查了Auth0,它看起来很棒,但没有和SDK登录,(你必须转发到他们的服务器并使用他们提供的表格......); Stormpath超出了价格范围 .
谢谢你的帮助!
1 回答
没有简单的“身份验证”API . auth流程以“InitiateAuth”调用和一系列RespondToAuthChallenge开始 . 当所有挑战(例如:MFA)完成后,只有那时RespondToAuthChallenge将返回令牌 .
描述这个的文档在这里:http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html