Hướng dẫn sử dụng đăng nhập với FB, GG Cognito
Step 1: Register app (FB)
Create a developer account with Facebook.
Sign in with your Facebook credentials.
From the My Apps menu, choose Create New App.
Enter a name for your Facebook app and choose Create App ID.
On the left navigation bar, choose Settings, and then choose Basic.
Note the App ID and the App Secret. You will use them in the next section.
Choose + Add Platform from the bottom of the page.
Choose Website.
Under Website, enter a sign-in URL for your app client endpoint into Site URL. Your sign-in URL should be in the following format:
https://your_user_pool_domain/login?response_type=code&client_id=your_app_client_id&redirect_uri=your_callback_url
Choose Save changes.
For App Domains, enter your user pool domain.
https://your_user_pool_domain
Choose Save changes.
From the navigation bar, choose Products, and then Set up from Facebook Login.
From the navigation bar, choose Facebook Login and then Settings. Enter your redirect URL into Valid OAuth Redirect URIs. The redirect URL will consist of your user pool domain with the
/oauth2/idpresponse
endpoint.https://your_user_pool_domain/oauth2/idpresponse
Choose Save changes.
Bước 2: Configure ở cognito
Chọn sign-in experience
Chọn Federated identity provider sign-in >Add identity provider > Facebook
Configure như dưới đây:
Testing:
App integration > App clients and analytics > Chọn app
Lưu ý: Nếu gặp lỗi:
thì tức là domain đang sai hoặc thiếu, cần kiểm tra lại ở những đoạn sau:
Under Website, enter a sign-in URL for your app client endpoint into Site URL. Your sign-in URL should be in the following format:
https://your_user_pool_domain/login?response_type=code&client_id=your_app_client_id&redirect_uri=your_callback_url
For App Domains, enter your user pool domain.
https://your_user_pool_domain
From the navigation bar, choose Facebook Login and then Settings. Enter your redirect URL into Valid OAuth Redirect URIs. The redirect URL will consist of your user pool domain with the
/oauth2/idpresponse
endpoint.https://your_user_pool_domain/oauth2/idpresponse
Khi cả 3 đúng rồi thì sẽ khắc phục được lỗi trên!
Mở rộng: register app với 1 số MXH khác: [https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-configuring-federation-with-social-idp.html]
Đăng nhập với google:
Bước 1: Tạo app google:
Chọn như hình dưới và chọn tao 0Authen 2.0 app
Sau khi tạo app, thì nhấn vào credentials
Authorized JavaScript origins field.
https://<your-user-pool-domain>
Authorized Redirect URIs field.
https://<your-user-pool-domain>/oauth2/idpresponse