Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

federated logins in react-native examples #3302

Closed
senips opened this issue May 17, 2019 · 16 comments
Closed

federated logins in react-native examples #3302

senips opened this issue May 17, 2019 · 16 comments
Labels
pending-close-response-required A response is required for this issue to remain open, it will be closed within the next 7 days. question General question React Native React Native related issue

Comments

@senips
Copy link

senips commented May 17, 2019

** Which Category is your question related to? **
React-Native Auth - Federated

** What AWS Services are you utilizing? **
Cognito

** Provide additional details e.g. code snippets **

First of all, is Amplify really support federated logins for Google and Facebook (not Expo but React-Native)?

Half cooked examples in documentation section of Amplify so please do not send me that link if you are answering it.

So what i need, can Amplify team provide me a Github example where this thing works with React-Native ? Or if anyone has any working example in a repo please share it with me.

request to Amplify team: When documenting your code please do not use just dot dot dot as a fill in gap but provide an actual snippet. For example, where can i see a full structure of aws_exports.js.. meaning Aws.Configure( < what to pass here/what is the schema here> ) ? What if do not want to use to Cognito Pool creation thru CLI but use existing pools or use what my organisation's devops tools for this?

@sammartinez sammartinez added question General question React Native React Native related issue labels May 17, 2019
@loganwedwards
Copy link

@senips I am not part of the Amplify team, but I can fill in from what I have learned. The documentation is confusing for someone who has configured their project to use the Amplify JS lib (for example), but not the Amplify CLI. My use case is that my projects tend to user Serverless and most (or all) of the backend configuration is handled there. There is an Amplify plugin for Serverless, but I have not tried it. The steps I take are:

  1. Configure your backend how you see fit.
  2. Create aws_exports.js and run Amplify.configure(aws_exports). There are some examples on the website on what a manually created exports file would look like. You will need to find the appropriate endpoints, ids, etc.. through the AWS console.

Regarding federated logins, I have found that the only solution to support a 3rd party, e.g., Facebook, is with the hosted UI option. This means that a user will be taken out of the native app experience and guided through a web flow. At the end of the Oauth flow, the user will land back in the app with the necessary tokens and auth state - signedIn.

Here is an example (I am using this code)

import React from 'react'
import { withOAuth } from 'aws-amplify-react-native'
import { View, Button } from 'react-native'

class FacebookAuth extends React.PureComponent {

  render() {
    return (
      <View>
        <Button
          title="Login With Facebook"
          onPress={this.props.facebookSignIn} // this prop is injected with the withOAuth HOC
        />
      </View>
    )
  }
}

export default withOAuth(FacebookAuth)

In one of your root components (that renders FacebookAuth, I just pulled the example from the docs and use Hub.listen(..) to redirect the user on sign in with a federated provider.

Does this partially help, at least?

@ghost
Copy link

ghost commented May 23, 2019

Hey @loganwedwards could you provide the versions of RN & aws-amplify-react-native & aws-amplify you are using? I have the same setup as you, im able to navigate out -> auth with facebook -> navigate back into the app but the Hub.listen() is not triggered and the user is not authenticated.

@loganwedwards
Copy link

@chriscraiclabs Here are the relevant bits pulled from package.json:

 "dependencies": {
    "@aws-amplify/auth": "^1.2.23", // This one might be here by mistake. I can't remember
    "aws-amplify": "1.1.27",
    "aws-amplify-react-native": "^2.1.11",
    "expo": "^32.0.0",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
  },

@senips
Copy link
Author

senips commented May 24, 2019

@loganwedwards I think your proposed solution is meant for Expo which I clearly see from your dependencies. In my case, I would need this to get working with just React-Native apps.

@chriscraiclabs I had this same hub issue not triggered with Hub.listen(). Actually I found that It did not even trigger for just for Cognito pool users so with Social federated logins are out of questions now.

@usmansbk
Copy link

usmansbk commented May 29, 2019

First of all, is Amplify really support federated logins for Google and Facebook (not Expo but React-Native)?

@senips Yes. you have to use packages like react-native-fbsdk for facebook and react-native-google-signin for google. Also you need to provide your refresh token handler, here is google refresh handler gist . You can use it as a template for facebook refresh handler. The AWS docs is a bit misleading about the refresh handlers. Here is a google login component

What if do not want to use to Cognito Pool creation thru CLI but use existing pools or use what my organisation's devops tools for this?

If you're planning to use only federated login without aws userpool then there's an extra step for google during IAM setup. Make sure you have the screens below

IAM
Screenshot (56)

Cognito --> Manage Identity Pools --> Edit XYZ
Screenshot (59)

Make sure you follow the facebook and google dev guide too.

For example, where can i see a full structure of aws_exports.js.. meaning Aws.Configure( < what to pass here/what is the schema here> ) ?

aws_exports.js is automatically generated when you add an aws-amplify service like auth via cli. It's easier and safer than manually creating your own.

@senips
Copy link
Author

senips commented May 30, 2019

Amplify for React-Native does not save any more of developers time or not offering any out of box solution but rather rely on what @usmansbk specified above. I do not know why big time cloud providers like AWS not providing any working components in full but selling Cognito solutions for long time. Just look at how auth0 guys are providing native components, examples and integration aspects. I am thinking of Firebase to see any better before I implement these half cooked amplify stuff with the mix of react-native-fbsdk & google-signin which leads to unnecessary maintenance for me later.

@manueliglesias
Copy link
Contributor

Hi @senips

Take a look at this repo I created when doing some work on the feature. It is almost the same code as in the docs. I just tried it and worked for me, hopefully it works for you too and help you get unblocked.

@usmansbk
Copy link

Hi @senips

Take a look at this repo I created when doing some work on the feature. It is almost the same code as in the docs. I just tried it and worked for me, hopefully it works for you too and help you get unblocked.

@manueliglesias does this work for ejected create-react-native-app or just Expo?

@manueliglesias
Copy link
Contributor

@manueliglesias does this work for ejected create-react-native-app or just Expo?

It was not created with create-react-native-app, it was created with react-native-cli (e.g. npx react-native init MyApp), so no Expo

@undefobj
Copy link
Contributor

@senips I am not part of the Amplify team, but I can fill in from what I have learned. The documentation is confusing for someone who has configured their project to use the Amplify JS lib (for example), but not the Amplify CLI. My use case is that my projects tend to user Serverless and most (or all) of the backend configuration is handled there. There is an Amplify plugin for Serverless, but I have not tried it. The steps I take are:

@loganwedwards are there any specific areas or actions we could take to make this easier? It's a bit of a catch-22 in that we used to have extremely verbose examples of manually building all the samples in the docs from scratch, and then we received feedback was that the docs are too verbose and customers want shorter examples automated by the CLI. Now that we have the reverse there is feedback for the other mechanism. Can you point at a specific section of the docs that could benefit with some other method of configuration explanation?

@manueliglesias manueliglesias added the pending-close-response-required A response is required for this issue to remain open, it will be closed within the next 7 days. label May 30, 2019
@qamatic
Copy link

qamatic commented Jun 11, 2019

@manueliglesias, First of all thanks for your example created in a repo. I understand it better in your version than Amplify. So one question about this const initialUrl = 'myapp://main/'; So is this same for every app or do i have to declare my app? Secondly do i have to set in Cognito console in redirect SignIn url entry?

@loganwedwards
Copy link

@undefobj I do not have a great answer here and I understand the balance in verbosity/conciseness in the docs. What would have helped me is understanding how using Cognito user pools as my authentication mechanism with 3rd party authn could be achieved in a React Native app. I know this is a particular use case, but by no means is it unique. The docs (to me) were confusing in that Cognito authz can be achieved via the hosted UI through a 3rd party identity provider, e.g., Facebook, but not through a typical JS-only Oauth grant. The code I pasted above with a description indicating this is the only means to do this in RN could be helpful.

@stale
Copy link

stale bot commented Jun 18, 2019

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@stale stale bot closed this as completed Jun 18, 2019
@kaitlynbrown
Copy link

kaitlynbrown commented Aug 26, 2019

@undefobj The issue is that you have no actual fully-working examples. Concise documentation is fine (even encouraged), as long as there is a link somewhere to an actual working example on github that doesn't have anything left out.

The other issue is the fragmented nature of the documentation. I recently implemented federated sign in with cognito in a React Native app, and I have a bookmark folder for it with almost a dozen pages saved. To say the least, it was frustrating having to jump between these and try to remember which page had the information I was looking for. A single, step-by-step guide with associated examples would have made things a million times easier. Below is the list of resources I referenced:

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-app-settings.html
https://aws-amplify.github.io/docs/js/cognito-hosted-ui-federated-identity
https://aws-amplify.github.io/docs/js/authentication#oauth-and-federation-overview
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-oidc-idp.html
https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
#1521
#1143
#2833
#1316
#3033

Right now, I'm trying to figure out what to use as a redirect url, and what the correct way is to make it work in both dev (for myself and other devs on the team) and in production (in an Expo app). This documentation doesn't seem to be in any of the above links.

I don't believe this issue should be closed, as there still aren't any official, fully-functional examples anywhere

@dennisrjohn
Copy link

@kaitlynbrown, did you ever figure out what to use as a redirect URL?

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending-close-response-required A response is required for this issue to remain open, it will be closed within the next 7 days. question General question React Native React Native related issue
Projects
None yet
Development

No branches or pull requests

9 participants