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

fix(amazon-cognito-identity-js): specify the correct userAgent/deviceName when remembering devices (React Native) #10724

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions .circleci/config.yml
Expand Up @@ -1065,6 +1065,13 @@ jobs:
steps:
- integ_test_rn_ios

integ_rn_ios_device_tracking:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add this also on the workflow section

workflows:
and also required for deploy on
- deploy:

executor: macos-executor
<<: *test_env_vars
working_directory: ~/amplify-js-samples-staging/samples/react-native/auth/deviceTracking
steps:
- integ_test_rn_ios

integ_datastore_auth:
parameters:
scenario:
Expand Down Expand Up @@ -1797,6 +1804,12 @@ workflows:
- build
filters:
<<: *releasable_branches
- integ_rn_ios_device_tracking:
requires:
- integ_setup
- build
filters:
<<: *releasable_branches
# - integ_rn_android_storage:
# requires:
# - integ_setup
Expand Down Expand Up @@ -2002,6 +2015,7 @@ workflows:
- integ_rn_ios_storage_multipart_progress
# - integ_rn_android_storage_multipart_progress
- integ_rn_ios_push_notifications
- integ_rn_ios_device_tracking
# - integ_rn_android_storage
# - integ_rn_ios_datastore_sqlite_adapter
- integ_datastore_auth
Expand Down
9 changes: 7 additions & 2 deletions packages/amazon-cognito-identity-js/src/CognitoUser.js
Expand Up @@ -5,6 +5,7 @@

import { Buffer } from 'buffer';
import { Sha256 } from '@aws-crypto/sha256-js';
import { Platform } from './Platform';

import BigInteger from './BigInteger';
import AuthenticationHelper from './AuthenticationHelper';
Expand Down Expand Up @@ -55,8 +56,12 @@ import StorageHelper from './StorageHelper';
* @param {bool=} userConfirmationNecessary User must be confirmed.
*/

const isBrowser = typeof navigator !== 'undefined';
const userAgent = isBrowser ? navigator.userAgent : 'nodejs';
const isNavigatorAvailable = typeof navigator !== 'undefined';
const userAgent = isNavigatorAvailable
? Platform.isReactNative
? 'react-native'
: navigator.userAgent
: 'nodejs';

/** @class */
export default class CognitoUser {
Expand Down
39 changes: 29 additions & 10 deletions packages/auth/__tests__/mockData.ts
Expand Up @@ -108,32 +108,51 @@ export const mockDeviceArray = [
DeviceLastAuthenticatedDate: 1623954284,
DeviceLastModifiedDate: 1623954285.339,
},
{
DeviceAttributes: [
{
Name: 'device_status',
Value: 'valid',
},
{
Name: 'device_name',
Value: 'react-native',
},
{
Name: 'last_ip_used',
Value: '45.17.45.126',
},
],
DeviceCreateDate: 1623954284.75,
DeviceKey: 'us-west-2_80ede80b-f333-49cd-af42-0ad22d8de9d4',
DeviceLastAuthenticatedDate: 1623954285,
DeviceLastModifiedDate: 1623954285.34,
},
];

export const transformedMockData = [
{
id: 'us-east-2_596db07d-793a-4070-8140-27f321ccf01c',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-east-2_12ac778f-52a4-4fca-a628-237776159c91',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-east-2_4a93aeb3-01af-42d8-891d-ee8aa1549398',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',
},
{
id: 'us-east-2_e0019223-e6b8-453f-a4e7-4e0d69dd4316',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-east-2_1763f940-7136-4133-8cf5-eb073cad06c9',
name:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
name: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36',
},
{
id: 'us-west-2_80ede80b-f333-49cd-af42-0ad22d8de9d4',
name: 'react-native',
},
];