[英]Cognito Facebook social login with Angular 6: How to use returned code to authenticate user in amplify Auth
I have an angular 6 app and am trying to configure social signin (facebook) with amplify from the docs. 我有一个有角度的6应用程序,正在尝试配置从文档放大的社交登录(facebook)。
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-social-idp.html https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-social-idp.html
I implemented the steps required and then generated the url to trigger hosted login. 我执行了所需的步骤,然后生成了用于触发托管登录的URL。
https://<your_user_pool_domain>/login?response_type=code&client_id=<your_client_id>&redirect_uri=https://www.example.com
This redirected me to facebook and then redirected back to my site as expected with the code in the url. 这将我重定向到facebook,然后按预期的那样通过URL中的代码重定向回我的网站。
https://<mysite>/browse?code=1bfabc0e-f4cd-4889-8811-eaaa71rf6e35#_=_
I can't find any documentation on how I exchange that code for JWT using the amplify library. 我找不到任何有关如何使用amplify库将代码替换为JWT的文档。
https://aws-amplify.github.io/amplify-js/media/angular_guide https://aws-amplify.github.io/amplify-js/media/angular_guide
I've implemented basic cognito login using the Authenticaor 我已经使用Authenticaor实现了基本的认知登录
<amplify-authenticator></amplify-authenticator>
And when the password and username are submitted I can see in the http response the accessToken and idToken being returned. 提交密码和用户名后,我可以在http响应中看到正在返回的accessToken和idToken。
Auth.signIn(username, password)
.then(user => console.log(user))
.catch(err => console.log(err));
I have tried looking through AmplifyService and Auth methods but can't find anything which allows me to submit a code instead of username and password. 我尝试查看AmplifyService和Auth方法,但找不到任何可以提交代码而不是用户名和密码的内容。
Thanks in advance 提前致谢
accessToken
instead of code
. accessToken
而不是code
。 accessToken
to API to change it to long-lived (60 days) token: accessToken
发送到API,以将其更改为寿命长(60天)的令牌: public function grantFacebookAccess(Request $request Facebook $fb) { $accessToken = $request->get('accessToken'); $oAuth2Client = $fb->getOAuth2Client(); $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); $params = "first_name,last_name,age_range,gender"; $user = $fb->get('/me?fields='.$params, $longLivedAccessToken)->getGraphUser(); print_r($user); }
Facebook class is from facebook/graph-sdk
(check this: https://quantizd.com/facebook-php-sdk-with-laravel/ ) Facebook类来自
facebook/graph-sdk
(请检查: https : //quantizd.com/facebook-php-sdk-with-laravel/ )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.