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.43k stars 2.13k forks source link

React Native: `appleid.apple.com` provider triggers Hosted UI instead of logging in #7712

Closed ds8k closed 3 years ago

ds8k commented 3 years ago

Describe the bug When authenticating a user with native Apple flow, calling Auth.federatedSignIn('appleid.apple.com', { token, expires_at }) triggers a nav to the Amazon hosted UI instead of logging the user in and providing credentials.

Using SignInWithApple works as expected on an Android device.

I've configured things I believe correctly. Following the flow as described here - https://github.com/aws-amplify/amplify-js/issues/5543#issuecomment-624722218

To Reproduce Steps to reproduce the behavior:

Expected behavior After calling federatedSignIn with the appropriate parameters the user is logged in

Code Snippet

const response = await appleAuth.performRequest({
  requestedOperation: appleAuth.Operation.LOGIN,
  requestedScopes: [appleAuth.Scope.EMAIL],
});

const state = await appleAuth.getCredentialStateForUser(response.user);

if (state !== appleAuth.State.AUTHORIZED) {
  throw new Error('User not authorized');
}

// auth stuff
const { email, exp } = decode(response.identityToken);
const result = await Auth.federatedSignIn(
 'appleid.apple.com',
  {
    token: response.identityToken,
    expires_at: exp * 1000 * Date.now(),
  },
);

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

What is Configured? If applicable, please provide what is configured for Amplify CLI:

  System:
    OS: macOS 11.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 87.51 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.1 - ~/.nvm/versions/node/v14.15.1/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.15.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 88.0.4324.146
    Firefox: 85.0.1
    Safari: 14.0.3
  npmPackages:
    @apollo/react-hooks: ^3.0.1 => 3.0.1 
    @apollo/react-testing: ^3.0.1 => 3.0.1 
    @aws-amplify/auth: 3.4.20 => 3.4.20 
    @aws-amplify/core: 3.8.12 => 3.8.12 
    @babel/core: ^7.10.2 => 7.10.2 
    @babel/plugin-proposal-decorators: ^7.12.1 => 7.12.1 
    @babel/runtime: ^7.10.2 => 7.10.2 
    @callosum/react-native-google-ad-manager: 2.0.2 => 2.0.2 
    @invertase/react-native-apple-authentication: ^2.1.0 => 2.1.0 
    @react-native-community/async-storage: ^1.12.1 => 1.12.1 
    @react-native-community/clipboard: ^1.4.0 => 1.4.0 
    @react-native-community/eslint-config: ^2.0.0 => 2.0.0 
    @react-native-community/netinfo: ^5.3.3 => 5.3.3 
    @react-native-community/push-notification-ios: ^1.2.0 => 1.2.0 
    @react-native-firebase/analytics: 7.6.1 => 7.6.1 
    @react-native-firebase/app: ^8.4.1 => 8.4.1 
    @react-native-firebase/crashlytics: 8.4.2 => 8.4.2 
    @react-native-firebase/dynamic-links: 7.5.2 => 7.5.2 
    @react-native-firebase/iid: 7.4.2 => 7.4.2 
    @react-native-firebase/messaging: 7.8.3 => 7.8.3 
    @react-native-picker/picker: ^1.9.2 => 1.9.2 
    @sentry/cli: 1.60.1 => 1.60.1 
    @sentry/react-native: ^1.4.0 => 1.4.0 
    @testing-library/jest-native: ^3.1.0 => 3.1.0 
    @types/detox: ^14.5.2 => 14.5.2 
    @types/i18n-js: ^3.0.1 => 3.0.1 
    @types/jasmine: ^3.5.1 => 3.5.8 
    @types/jest: ^25.2.3 => 25.2.3 
    @types/react: ^17.0.0 => 17.0.0 
    @types/react-native: ^0.63.41 => 0.63.41 
    @types/react-test-renderer: ^16.9.1 => 16.9.1 
    @types/styled-components: ^4.1.19 => 4.1.19 
    @typescript-eslint/eslint-plugin: ^4.10.0 => 4.10.0 
    @typescript-eslint/parser: ^4.10.0 => 4.10.0 
    amazon-cognito-identity-js: 4.5.10 => 4.5.10 
    apollo-cache-inmemory: ^1.6.3 => 1.6.3 
    apollo-cache-persist: ^0.1.1 => 0.1.1 
    apollo-client: ^2.6.8 => 2.6.8 
    apollo-link-context: ^1.0.20 => 1.0.20 
    apollo-link-error: ^1.1.12 => 1.1.12 
    apollo-link-http: ^1.5.16 => 1.5.16 
    apollo-link-persisted-queries: ^0.2.2 => 0.2.2 
    apollo-utilities: ^1.3.2 => 1.3.2 
    async: ^3.2.0 => 3.2.0 
    aws-amplify-react-native: 4.3.1 => 4.3.1 
    babel-jest: ^25.1.0 => 25.5.1 
    base-64: ^0.1.0 => 0.1.0 
    bluebird: ^3.7.2 => 3.7.2 
    date-fns: ^2.0.0-beta.4 => 2.0.1 
    detox: 17.8.3 => 17.8.3 
    eslint: ^7.15.0 => 7.15.0 
    eslint-config-prettier: ^7.0.0 => 7.0.0 
    eslint-plugin-prettier: ^3.3.0 => 3.3.0 
    eslint-plugin-react: ^7.21.5 => 7.21.5 
    eslint-plugin-react-hooks: ^4.2.0 => 4.2.0 
    eventemitter3: ^4.0.0 => 4.0.0 
    fs-extra: ^8.1.0 => 8.1.0 
    graphql: ^14.5.4 => 14.5.4 
    graphql-tag: ^2.10.1 => 2.10.1 
    hermes-engine: 0.5.2-rc1 => 0.5.2-rc1 
    i18n-js: ^3.3.0 => 3.3.0 
    jest: ^26.0.1 => 26.0.1 
    jest-junit: ^10.0.0 => 10.0.0 
    jwt-decode: ^3.1.2 => 3.1.2 
    md5: ^2.2.1 => 2.2.1 
    metro-react-native-babel-preset: ^0.59.0 => 0.59.0 
    mobx: ^6.0.1 => 6.0.1 
    mobx-react-lite: ^3.1.6 => 3.1.6 
    patch-package: ^6.2.2 => 6.2.2 
    postinstall-postinstall: ^2.1.0 => 2.1.0 
    prettier: ^2.2.1 => 2.2.1 
    react: 16.13.1 => 16.13.1 
    react-dom: ^17.0.1 => 17.0.1 
    react-native: 0.63.2 => 0.63.2 
    react-native-action-sheet: ^2.2.0 => 2.2.0 
    react-native-autoheight-webview: ^1.4.2 => 1.4.2 
    react-native-background-fetch: ^3.0.3 => 3.0.3 
    react-native-base64: ^0.1.0 => 0.1.0 
    react-native-branch: ^5.0.0 => 5.0.0 
    react-native-dark-mode: ^0.2.2 => 0.2.2 
    react-native-device-info: ^5.5.4 => 5.5.4 
    react-native-dialog: ^5.6.0 => 5.6.0 
    react-native-fast-image: ^8.1.5 => 8.1.5 
    react-native-gesture-handler: 1.9.0 => 1.9.0 
    react-native-hooks: ^0.9.0 => 0.9.0 
    react-native-htmlview: ^0.15.0 => 0.15.0 
    react-native-image-pan-zoom: 2.1.12 => 2.1.12 
    react-native-inappbrowser-reborn: ^3.3.4 => 3.3.4 
    react-native-jw-media-player: 0.1.47 => 0.1.47 
    react-native-music-control: ^0.12.0 => 0.12.0 
    react-native-orientation-locker: ^1.2.0 => 1.2.0 
    react-native-permissions: ^2.1.5 => 2.1.5 
    react-native-rate: ^1.2.1 => 1.2.1 
    react-native-reanimated: ^1.7.0 => 1.13.1 
    react-native-safe-area-context: ^1.0.2 => 1.0.2 
    react-native-safe-area-view: ^2.0.0 => 2.0.0 
    react-native-scalable-image: ^1.0.0 => 1.0.0 
    react-native-screens: 2.11.0 => 2.11.0 
    react-native-share: ^3.0.0 => 3.0.0 
    react-native-svg: ^12.1.0 => 12.1.0 
    react-native-svg-icon: ^0.8.1 => 0.8.1 
    react-native-testing-library: ^2.0.0 => 2.0.0 
    react-native-track-player: ^1.2.3 => 1.2.3 
    react-native-version-number: ^0.3.6 => 0.3.6 
    react-native-webview: ^9.0.1 => 9.0.1 
    react-native-widget-kit:  0.1.0 
    react-native-youtube-iframe: ^1.2.4 => 1.2.4 
    react-navigation: ^4.4.3 => 4.4.3 
    react-navigation-hooks: ^1.1.0 => 1.1.0 
    react-navigation-stack: ^1.10.3 => 1.10.3 
    react-navigation-tabs: ^2.10.1 => 2.10.1 
    react-test-renderer: 16.13.1 => 16.13.1 
    reanimated-bottom-sheet: ^1.0.0-alpha.22 => 1.0.0-alpha.22 
    redux-persist-filesystem-storage: ^2.2.0 => 2.2.0 
    rn-fetch-blob: ^0.12.0 => 0.12.0 
    scheduler: ^0.19.1 => 0.19.1 
    shortid: ^2.2.15 => 2.2.15 
    string.prototype.matchall: ^4.0.1 => 4.0.1 
    styled-components: ^5.2.0 => 5.2.0 
    ts-jest: ^26.1.0 => 26.1.0 
    typescript: ^4.1.3 => 4.1.3 
    unescape: ^1.0.1 => 1.0.1 
    url-parse: ^1.4.7 => 1.4.7 
  npmGlobalPackages:
    @aws-amplify/cli: 4.41.2
    ios-deploy: 1.11.3
    npm: 6.14.8
amhinson commented 3 years ago

@ds8k It looks like you are missing the 3rd argument for federatedSignIn, which is the user:

const credentials = await Auth.federatedSignIn(
      'appleid.apple.com',
      {
        token: result.identityToken,
        expires_at: decoded.exp * 1000 + new Date().getTime(),
      },
      {
        name: `${result.fullName.givenName} ${result.fullName.familyName}`,
        email: decoded.email,
      },
    );
ds8k commented 3 years ago

@amhinson You're right, I thought I did that but must have dismissed it as not working. Even including that object I still wasn't able to be properly signed in, however I moved on to just using the "SignInWithApple" web flow

github-actions[bot] commented 2 years ago

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.