aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

feature request: federatedSignInToUserPool without Hosted UI #6261

Open ruodingt opened 4 years ago

ruodingt commented 4 years ago

First thanks for the team for your great work.

Is your feature request related to a problem? Please describe.

Use Case

Our app is built on top of Ionic + Angular We are using appsync with auth method CognitoUserPool.

Previously our our team has been using normal Auth.signIn(), which works perfectly.

With Auth.signIn, the amplify SDK could automatically pickup the user pool user info and somehow the identity pool credential.

We don't want to use hosted UI since it will destroy our existing UI/UX flow.

We were expecting that Auth.federatedSignin() would have very similar behaviour such that the SDK could automatically created a user in user pool and pickup the identity pool credential.

I did notice that there are 3 different implementations in the doc

All of them return a promise for object, unlike Auth.signIn which returning Promise<CognitoUser | any>.

The thing is that we have no use with those ICredentials as our auth method for appsync has been set to be CognitoUserPool.

I think that the facebook user must federate into user pool first to access appsync stuff properly

Describe the solution you'd like

It would be super awesome if we could have a method called federatedSignInToUserPool such that it can behave like Auth.SignIn except that the input is different.

Concretely, federatedSignInToUserPool will do

Such that we can do, for example:

# Using Facebook SDK to grab facebookResponse
 this.amplify.auth().federatedSignIn('Facebook', facebookResponse, ...)

Describe alternatives you've considered

I read a few thread and I know hosted UI can handle creating new user in user pool and login the user properly. But hostUI is tooooo chunky an dlack of flexibility despite that we tune the css.

It seems the Hosted UI is not open sourced such that we must use that as whole instead of using a segmentation of its components and logic. e.g. only take the facebook login button and facebook fed in logic.

Extra

Please kindly inform me if there is any work around for what I what to achieve here. Or simply tell me it is not possible right now so my team can stop working on workarounds and start thinking about more radical solutions.

I've seen many voice on this topic. Many issues ended up being closed by bots or inconclusive. I hope your lovely ladies and gentlemen could hearing communities voice.

Much appreciated to your help.

Thanks, Ruoding

Gyran commented 3 years ago

This something we really want as well. We have a react native app and we use cognito user pools. We have social logins with and are currently using the hosted ui with from an in app browser. This is not optimal for use, especially for the Facebook case, because our users are often only logged into Facebook in the Facebook app and not in their browser.

So what we want to use react-native-fbsdk to get an authorization token, and then use that to signin to the user pool exactly as described in the first post.

Adding some example code to better illustrate

import { LoginManager, AccessToken } from 'react-native-fbsdk';
import Auth from '@aws-amplify/auth';

const facebookSignIn = async ()  => {
    const response = await LoginManager.logInWithPermissions(['public_profile', 'email']);
    if (response.isCancelled === false) {
        const fbAccessToken = await AccessToken.getCurrentAccessToken();
        if (fbAccessToken) {
            const federatedResponse = {
                token: fbAccessToken.accessToken,
            };
            await Auth.federatedSignIn('facebook', federatedResponse);
            // after this the Amplify hub will send the `signIn` event if providing a valid token
        }
    }
}
mkozjak commented 3 years ago

What is the status on this one? Are there any other ways to implement auth around cognito and have user roles supported if there's no support for that here?

We are using our own login forms and are having cognito user pools implemented, but would like to add support for roles to our users via user pool groups. Admins, Read-Only, etc...

hukus commented 3 years ago

Adding +1 request for this.

We added federatedSignIn method for social signins via Linkedin. Now some of our users are not in user pools and we cannot manipulate thier groups etc... We basically have to rewrite our user management now.

mkozjak commented 3 years ago

@hukus we went ahead and moved away from Amplify to Lambda Authorizers implementing our own custom logic for authorization. Feels weird AWS doesn't care about this feature in Amplify, though.