Giter VIP home page Giter VIP logo

react-native-aws-cognito-js's People

Contributors

jmparsons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-aws-cognito-js's Issues

Backporting for old version of RN.

This is a long shot, but I've taken over a project done in RN v .38 and I need to pull the auth to Cognito out of a native package an into a JS lib. I used your library to do this for Android, but unfortunately I'm getting the issue with not being able to find RCTBridgeModule.h in RNAWSCognito.h. And I'm hoping their might be a simple fix that won't require me to do a major upgrade refactor.

To reproduce my issue I did the following:
react-native init sample --version 0.38.0
npm install react-native-aws-cognito-js
react-native link react-native-aws-cognito-js
react-native run-ios

Which fails with:
/node_modules/react-native-aws-cognito-js/ios/RNAWSCognito.h:4:9: fatal error: 'React/RCTBridgeModule.h' file not found #import <React/RCTBridgeModule.h>

Mobile and RN development is not my wheelhouse, but I'm hoping there is some sort of xcode configuration or tricks I can do to get this working and avoid a major overhaul. Thanks in advance for any assistance.

Custom attributes missing in the getUserAttributes response - AWS cognito

const userData = { Username: username, Pool: userPool };
const cognitoUser = new AWS.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.getUserAttributes(function(err, result) {
                        if (err) {
                            alert(err);
                            return;
                        }
                        console.log(result)
                        for (i = 0; i < result.length; i++) {
                            console.log('attribute ' + result[i].getName() + ' has value ' + result[i].getValue());
                        }
                    });

I have a custom field userType. I have set the read, write permission for the custom attribute. But in the response of getUserAttributes i am getting only standard attributes(sub, email_verified, email). How can i retrieve both the standard and custom attributes?

This is my response -

screen shot 2018-02-09 at 12 00 07 pm

facebook token, now whats next

Let's say we want users to sign in into our app. There are 2 ways:

1.) Signup, and login (this will create an account in User Pool)
2.) Facebook login (user will just login to his facebook account)

Now, 1.) works fine, I'm able to have users signup and login. I am having problem in 2.). I was able to get the token from facebook (I am able to integrate facebook login button in my react native app)... Now after we get the token,, I want my users to use this facebook login and just continue using the app.

How do we achieve this? Are we supposed to create a new user in UserPool programatically if users login via facebook? Or we dont have to create the account manually (I assume that once the user logins using his facebook account, the next time he will use the app, he will be remembered)?

My point of confusion is, there is no cognitoUser if we are using federated identities or facebook. Please help me clear this confusion and what would be the best thing to proceed for number 2.

Usage question

Hi guys,

thanks a lot for your great job.
I am trying to integrate amazon login and facebook login using your module, but no luck yet.
Should I go through all the info.plist/AppDeligame and Android specific files?
Could you, please, be more specific about installation and integration steps?

Thanks

Compatibility with RN0.47+

Breaking - remove unused registration of JS modules
Summary: It's now unnecessary to declare which JS modules you want to expose on your package. To upgrade, remove all overrides of createJSModules and keeping calling your JS modules as before.

C:\Users\piust\Documents\terminal\node_modules\react-native-aws-cognito-js\android\src\main\java\com\airlabsinc\RNAWSCognitoPackage.java:18: error: method does not override or implement a method from a supertype
@OverRide
^
1 error
:react-native-aws-cognito-js:compileDebugJavaWithJavac FAILED

reading cognitoUser from MemoryStorage

Let's say users can loggedin, and somewhere we are using the following code (when login is successful)

userPool.storage.sync((err, result) => {
  // MemoryStorage is now updated with AsyncStorage values
});
or

cognitoUser.storage.sync((err, result) => {
  // MemoryStorage is now updated with AsyncStorage values
});

Now, let's say we have a function that will check if user is actually logged in. (App restart)


export const checkIfLoggedIn = () => {
    return (dispatch) => {
        dispatch({ type: DO_NOTHING });
        var userPool = new CognitoUserPool(appConfig);
        var cognitoUser = userPool.getCurrentUser();
        console.log(cognitoUser);
        if (cognitoUser != null) {
            cognitoUser.getSession(function(err, session) {
                if (err) {
                    console.log(err);
                    return;
                }
                console.log('session validity: ' + session.isValid());

                // NOTE: getSession must be called to authenticate user before calling getUserAttributes
                cognitoUser.getUserAttributes(function(err, attributes) {
                    if (err) {
                        // Handle error
                    } else {
                        // Do something with attributes
                        console.log(attributes);
                    }
                });
                
                Actions.main({ type: 'reset' });
            });
        }
    }
};

Why is that cognitoUser is being returned as null? Also why did we enable both userPool or cognitoUser to be sync, cant it be just one of them?

No token recieve in android.

Hello guys,

I have use below mention version.
"react-native": "0.56.0",
"react-native-aws-cognito-js": "0.0.7",
"react": "16.4.1",

Please help me.

Access AWS resources (S3 / DynamoDB) by CognitoIdentityCredentials

Thanks for this great tool! It's really helpful!

Now I'm facing another problem, I'm attempting to follow this guide to access S3 resources

https://aws.amazon.com/blogs/developer/react-native-support-in-the-aws-sdk-for-javascript/

import {
  AWS,
  TransferUtility,
  Config,
  CognitoIdentityCredentials
} from "aws-sdk/dist/aws-sdk-react-native";

......

const s3 = new AWS.S3({
  region: 'us-east-1',
  credentials: Config.credentials
});

However it raised error message
undefined is not an object (evaluating 'new_awsSdkReactNative.AWS.S3')

Shall I use other method to import AWS resources?
Thank you!

CognitoIdentityCredentials return session undefined

I ran the app.js from the example locally. Cognito returns the access token. However, when console logging Config.credentials, I got the following:

CognitoIdentityCredentials {expired: true, expireTime: null, accessKeyId: undefined, sessionToken: undefined, params: Object…}
accessKeyId:undefined
data:null
expireTime:null
expired:true
params:Object
sessionToken:undefined
_clientConfig:Object
_identityId:null
identityId:(...)
secretAccessKey:undefined
get identityId:function get()
set identityId:function set(identityId)
proto:Credentials

How do I get a valid session when an user login ?

Broken on RN 0.47 update

:react-native-aws-cognito-js:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). /app/node_modules/react-native-aws-cognito-js/android/src/main/java/com/airlabsinc/RNAWSCognitoPackage.java:18: error: method does not override or implement a method from a supertype @Override
Simple fix: remove createJSModules method. More on the RN update: https://github.com/facebook/react-native/releases/tag/v0.47.0

Facebook Federated ID Credentials

First of all: Thanks for your great work!

I get a warning if I try to fetch the crendentials via Facebook as identity provider:

        // Add the Facebook access token to the Cognito credentials login map.
        Config.credentials = CognitoIdentityCredentials({
            IdentityPoolId: appConfig.IdentityPoolId,
            Logins: {
                'graph.facebook.com': accessToken // accessToken from FB-SDK
            }
        });

        // Obtain AWS credentials
        Config.credentials.get(e=>console.log(e));

The warning:

Possible Unhandled Promise Rejection (id: 0):
TypeError: this.loadCachedId is not a function
TypeError: this.loadCachedId is not a function
    at CognitoIdentityCredentials (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=true&minify=false:203985:10)
    at LoginMainScreen._onFBSuccess (/js/screens/login/LoginMainScreen.map?platform=android&runModule=false&entryModuleOnly=true&hot=true:147:103)

Did I something wrong? Is it a small issue? Otherwise it is not very important because it works via aws-sdk-react-native

cognitoUser/userPool.storage.sync is not a function

From the README.md I'm using:

userPool.storage.sync((err, result) => {
  // MemoryStorage is now updated with AsyncStorage values
});

or

cognitoUser.storage.sync((err, result) => {
  // MemoryStorage is now updated with AsyncStorage values
});

I played around with the example application without a crash, the result logs 'SUCCESS'.

Here's an example snippet of where I've tried to use it:

const authenticationData = {
      Username: username,
      Password: password,
    };

    var authenticationDetails = new AuthenticationDetails(authenticationData);

    var poolData = {
      UserPoolId: appConfig.UserPoolId,
      ClientId: appConfig.ClientId
    };

    var userPool = new CognitoUserPool(poolData);

    var userData = {
      Username: username,
      Pool: userPool
    };

    var cognitoUser = new CognitoUser(userData);

    cognitoUser.authenticateUser(authenticationDetails, {
      onSuccess: (result) => {
        console.log(`ID.JWT TOKEN =====> ${result.getIdToken().getJwtToken()}`);
        AsyncStorage.setItem('token', result.getIdToken().getJwtToken());
        AWS.config.credentials = new CognitoIdentityCredentials({
          IdentityPoolId: appConfig.IdentityPoolId,
          Logins: {
            [`cognito-idp.${appConfig.region}.amazonaws.com/${appConfig.UserPoolId}`]: result.getIdToken().getJwtToken()
          },
        }, {
          region: 'us-east-1'
        });

        Intercom.logEvent('success_login_user', { username });


        AWS.config.credentials.refresh((error) => {
          if (error) console.log(error);
        });

        cognitoUser.storage.sync((err, res) => {
          if (err) console.log(err);
          console.log(res);
        });

        Intercom.logEvent('success_login_user');
        dispatch({
          type: types.LOGIN_USER_SUCCESS,
          payload: result
        });
  ...
}

_awsSdkReactNative.util.crypto.lib.randomBytes is not a function

I am developing React Native Expo app and tried to use authenticate.
And I got the error as follow.
_awsSdkReactNative.util.crypto.lib.randomBytes is not a function. (In '_awsSdkReactNative.util.crypto.lib.randomBytes(128)', '_awsSdkReactNative.util.crypto.lib.randomBytes' is undefined)

error: a type with the same simple name is already defined by the single-type-import of RNAWSCognitoPackage

Environment

Environment:

  • OS: Linux 4.13
  • Node: 8.9.4
  • Yarn: Not Found
  • npm: 5.6.0
  • Watchman: Not Found
  • Xcode: N/A
  • Android Studio: Not Found

Packages: (wanted => installed)

  • react: 16.3.0-alpha.2 => 16.3.0-alpha.2
  • react-native: 0.54.2 => 0.54.2

Description

When I try $ react-native run-android on android emulator, I get this error:

:app:compileDebugJavaWithJavac
/home/user/app/android/app/src/main/java/com/package/MainApplication.java:8: error: a type with the same simple name is already defined by the single-type-import of RNAWSCognitoPackage
import com.airlabsinc.RNAWSCognitoPackage;
^
1 error
Incremental compilation of 1 classes completed in 0.448 secs.
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10.964 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Then I have 2 imports with the same name in my /home/user/app/android/app/src/main/java/com/package/MainApplication.java
May this cause the issue?
Is this the issue with RN?

package com.package;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.amazonaws.RNAWSCognitoPackage; // 1
import com.amazonaws.amplify.pushnotification.RNPushNotificationPackage;
import com.airlabsinc.RNAWSCognitoPackage; // 2
import com.horcrux.svg.SvgPackage;
import com.toast.ToastPackage;
import com.vdi.VDIPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

Steps to Reproduce

// TO DO

Expected Behavior

Running app on android emulator

Actual Behavior

See error above

Question asked

SO: https://stackoverflow.com/questions/50815811/execution-failed-for-task-appcompiledebugjavawithjavac

react-native: facebook/react-native#19656

RNAWSCognito undefined, and computeModPow is not a function

I encountered undefined error when evaluating RNAWSCognito.computeModPow() in AuthenticationHelper.js, resolved by removing the {},

from

const { RNAWSCognito } = NativeModules;

to

const RNAWSCognito = NativeModules;

But now I encountered RNAWSCognito.computeModPow is not a function. Which dependency do I need for iOS?

The 1st example with mapping doesn't work

Thanks for all the work you've done but am having an issue with mapping.

This part of the first example doesn't seem to work:
Config.credentials = new CognitoIdentityCredentials({ IdentityPoolId: appConfig.IdentityPoolId, Logins: { [cognito-idp.${appConfig.region}.amazonaws.com/${appConfig.UserPoolId}]: result.getIdToken().getJwtToken() } });

On my online dashboard for that userpool I can't see that specific user being logged in.

Same happens when am trying to map back a facebook access token to generate a JWT token from the session.

Any Ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.