简体   繁体   English

使用Angular 6的Cognito Facebook社交登录:如何使用返回的代码在放大Auth中验证用户身份

[英]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 提前致谢

  1. You can use https://github.com/zyra/ngx-facebook to obtain accessToken instead of code . 您可以使用https://github.com/zyra/ngx-facebook来获取accessToken而不是code
  2. You can send 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.

相关问题 Cognito:在 Angular 中放大用户创建 - Cognito: Amplify user creation in Angular 如何在Django REST Social Auth中使用Angular 5? - How to use Angular 5 with Django REST Social Auth? Angular 2上的Amazon Cognito Facebook登录 - Amazon Cognito facebook login on Angular 2 如何为 AWS Amplify Cognito Auth.SignUp() 方法定义用户 object? - How to define the user object for AWS Amplify Cognito Auth.SignUp() method? 如何从 Angular/Amplify/Cognito 登录页面中删除“使用 AWS 登录”按钮? - How to remove "Sign in with AWS" button from Angular/Amplify/Cognito login page? 如何使用 Amplify 将 angular 应用程序中的 AWS-Cognito 用户池更改为另一个用户池? - How to change AWS-Cognito user pools in an angular app to another user pool, using Amplify? 如何在 Angular 6 中进行社交登录(Facebook、Google、Linkedin 和 Github) - How to do Social Login (Facebook,Google,LInkedin and Github) in Angular 6 使用 Cognito 和 Amplify 的 SSO + Angular - SSO with Cognito and Amplify + Angular Amplify / Cognito:更新用户属性后刷新会话变量(角度) - Amplify / Cognito : refresh session variables after updating user attributes (angular) Angular - 放大 - 将认知用户 object 传递给另一个组件 - Angular - Amplify - Passing cognito user object to another component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM