Using Cognito User Pools, without Cognito Federated Identities(identity pools)

后端 未结 4 1523
滥情空心
滥情空心 2021-01-07 09:38

I would like to use only Cognito User Pool, and therefore I want to use identity federation with Cognito User Pools, without Cognito Federated Identities (identity pools).

4条回答
  •  不思量自难忘°
    2021-01-07 10:15

    If you are using your own Custom UI, you will need to create a button/anchor to redirect to the user.

    This is what I use to create a url (JS Code):

    `https://${domain}/oauth2/authorize`,
      `?redirect_uri=${redirectSignIn}`,
      `&response_type=${responseType}`,
      `&client_id=${userPoolWebClientId}`,
      `&identity_provider=${providerName.toString()}`
    

    providerName is either Facebook/Google responseType is either token/code domain your domain in cognito userpool config redirectSignIn your redirect sign in in Cognito User Pool Config

    You will need to call window.location.assign({the url generated above}). When user clicks the button, it will redirect to either Facebook/Google page asking for Account/Permission.

    As for as I know, Facebook/Google dialog for custom UI is not yet supported.

    Example code from AWS Amplify

    import { Auth } from 'aws-amplify';
    
    const config = Auth.configure();
    const { 
        domain,  
        redirectSignIn, 
        redirectSignOut,
        responseType } = config.oauth;
    
    const clientId = config.userPoolWebClientId;
    // The url of the Cognito Hosted UI
    const url = 'https://' + domain + '/login?redirect_uri=' + redirectSignIn + '&response_type=' + responseType + '&client_id=' + clientId;
    
    // Launch hosted UI
    window.location.assign(url);
    

    Link: https://aws-amplify.github.io/docs/js/authentication

    Another thing, you can link federated identity to a user pool account. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#adminLinkProviderForUser-property

提交回复
热议问题