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.11k forks source link

Cognito Advanced Security feature support in React Native apps #4223

Open walshj19 opened 4 years ago

walshj19 commented 4 years ago

The Cognito Advanced Security feature requires that client applications provide device information to use the functionality effectively. This functionality is already provided by the Amplify javascript SDK when used in a browser and by the native mobile Amplify SDKs on iOS and Android, can support be added for this when using this SDK in React Native apps.

Amplifiyer commented 4 years ago

@walshj19 AdvancedSecurityDataCollectionFlag is already set to true as default in amplify https://github.com/aws-amplify/amplify-js/blob/master/packages/amazon-cognito-identity-js/src/CognitoUserPool.js#L55-L60 Is the blocker that you can't include the javascript in react native apps? Is it possible to download and cache it locally?

walshj19 commented 4 years ago

That flag is enabled and when using the SDK to login with the Auth.signIn method in a browser client application the device fingerprint information is sent correctly and can be seen in the Cognito Advanced Security event log on a user. When using the same Auth.signIn method in a react native app the user is signed in successfully but on Android(using a real device) the device fingerprint information is not sent and in the event log is listed as "Unknown".

Amplifiyer commented 4 years ago

@walshj19, how are you importing/including the following necessary javascript as per the cognito guide in your react native app?

<script src="https://amazon-cognito-assets._<region>_.amazoncognito.com/amazon-cognito-advanced-security-data.min.js"></script>

Can you please provide the code sample? That script is necessary for enabling the advanced security feature. You can confirm that by logging the global var exported by that script. Add console.log(global.AmazonCognitoAdvancedSecurityData) in your app and let me know if you see an object with a getData() method on it.

anandwahed commented 4 years ago

@Amplifiyer can you explain why we need the above script to be added in the ReactNative app since the aws-amplify JS library should wrap the logic for AdvancedSecurity right ? Also below snippet is the response from Cognito for the CognitoUser object which shows the advancedSecurityDataCollectionFlag

pool: CognitoUserPool
advancedSecurityDataCollectionFlag: true
client: Client {endpoint: "https://cognito-idp.ap-southeast-1.amazonaws.com/", userAgent: "aws-amplify/0.1.x react-native"}
clientId: "XXXXXXXXXXXXXXXXXXXXX"
storage: ƒ MemoryStorage()
userPoolId: "XXXXXXXXXXXXXXXXXXXX"
__proto__: Object
preferredMFA: "NOMFA"
Amplifiyer commented 4 years ago

@anandwahed, as per the Cognito docs, you need both, AdvancedSecurityDataCollectionFlag set to true and the aforementioned script loaded in the scope which provides a global object AmazonCognitoAdvancedSecurityData that has method for data collection required for enabling advanced security features.

anandwahed commented 4 years ago

Hi @Amplifiyer can you guide us how the above script can be loaded in the case of a ReactNative mobile app. Or should we write native bridge code to connect with the Android and iOS SDKs separately in the ReactNative app ?

Amplifiyer commented 4 years ago

@anandwahed, that's what I thought was the issue. Even downloading and caching the file locally in the project is not working since the javascript file is not compatible with the react native environment. I'll follow up with internal cognito team and revert back once I have more information.

anandwahed commented 4 years ago

Hi @Amplifiyer were you able to get any updates regarding this issue?

andrew-makarenko commented 4 years ago

Any news?

s1mrankaur commented 3 years ago

Do we need to include that file explicitly when using amplify with react? @anandwahed

jimmyn commented 2 years ago

Any updates on this issue?

SPopenko commented 1 year ago

Hi @Amplifiyer, do you have any updates for the community?

roryf commented 1 year ago

:tumbleweed:

mariusdotspinu commented 5 months ago

Any news regarding this?