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

RN 0.59 and Cognito federated identity OAuth flow failure #3183

Closed
mkrn opened this issue Apr 28, 2019 · 6 comments
Closed

RN 0.59 and Cognito federated identity OAuth flow failure #3183

mkrn opened this issue Apr 28, 2019 · 6 comments
Labels
Auth Related to Auth components/category React Native React Native related issue

Comments

@mkrn
Copy link

mkrn commented Apr 28, 2019

Describe the bug
With newest version of react-native the OAuth flow with Cognito Federated Identity fails to sign in the user.

To Reproduce
Steps to reproduce the behavior:

  1. In a component wrapped with withOAuth HOC use props.facebookSignIn flow.
  2. The flow will get the code from FB but will fail to get the tokens

Expected behavior
Expected the flow to work properly

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • iOS
  • RN 0.59 +
  • aws-amplify 1.1.26
  • aws-amplify-react-native 2.1.10

Smartphone (please complete the following information):

  • iPhone 8plus
  • iOS 12.2
  • RN 0.59 +

Additional context
Add any other context about the problem here.

Sample code


const urlOpener = async (url, redirectUrl) => {
  const { type, url: newUrl } = await WebBrowser.openAuthSessionAsync(url, redirectUrl);

  if (type === 'success') {
    await WebBrowser.dismissBrowser();

    if (Platform.OS === 'ios') {
      return Linking.openURL(newUrl);
    }
  }
};

Amplify.configure({
  Auth: {
     oauth: {
      domain: Config.REACT_APP_COGNITO_DOMAIN,
      scope: ['public_profile', 'email'],
      redirectSignIn: `app://signIn`, 
      redirectSignOut: `app://signOut`,
      responseType: 'code',
      urlOpener,
    }
....

<Button onPress={this.props.facebookSignIn} >

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

@mkrn
Copy link
Author

mkrn commented Apr 28, 2019

This is due to use of URLSearchParams that has been stripped to non-implemented shim in RN 0.59 +

https://github.com/aws-amplify/amplify-js/blob/master/packages/auth/src/OAuth/OAuth.ts#L144
facebook/react-native#23922

Workaround:

index.js

import { polyfillGlobal } from 'react-native/Libraries/Utilities/PolyfillFunctions';

polyfillGlobal('URLSearchParams', () => undefined);
delete global.URLSearchParams;

@manueliglesias
Copy link
Contributor

Thank you for the work-around @mkrn ! 😄

This will be very helpful for other users

@schellack
Copy link

@mkrn thanks for posting that workaround. It looks like deleting the URLSearchParams from global causes other issues, even though it does allow auth to start working again.

After implementing your workaround, did you see errors like the one below? If so, how did you work around it?

Can't find variable: URLSearchParams
_initBody
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:27145:61
Response
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:27309:21
onload
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:27364:31
wrapped
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:152134:28
dispatchEvent
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:29175:31
setReadyState
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:28933:31
__didCompleteResponse
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:28755:29
emit
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:6664:42
__callFunction
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:3120:49
<unknown>
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:2877:31
__guard
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:3074:15
callFunctionReturnFlushedQueue
    AppEntry.bundle?platform=android&dev=true&minify=false&hot=false:2876:21

@loganwedwards
Copy link

@mkrn @schellack I can confirm that updating the code with the polyfill and deleting the global results in the same Can't find variable: URLSearchParams. Is there a 3rd party we could use to polyfill with the same api that was previously used?

@ltankey
Copy link

ltankey commented Jul 2, 2019

If you monkey patch the _handleCodeFlow method to replace how body is compiled (e.g. just return body: body rather than the version that uses URLSearchParams it'll work fine without any polyfills

@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
Auth Related to Auth components/category React Native React Native related issue
Projects
None yet
Development

No branches or pull requests

5 participants