GithubHelp home page GithubHelp logo

happygts / cordova-plugin-aws-user-pool Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 4.0 9.28 MB

This plugin will allow a native communication with the aws userPool

Ruby 7.40% Objective-C 85.43% JavaScript 7.17%
cordova cordova-plugin cordova-ios cordova-ios-plugin aws aws-cognito user-pool signup signout signin

cordova-plugin-aws-user-pool's Introduction

Version 1.1.0

Introduction to the plugin

This plugin exist because there is multiples problemes using the javascript cognito userPool within cordova. For example in some versions of Ios it's not possible to create an account, the connection take to much time and often fail. It was really impossible to find the reasons why it was failing so I decided to do this plugin.

What's this plugin allow you to do

  • Signup users to your cognito userPool
    • with the confirmation you chosed within cognito
  • Set userData during the signup (these data are not supposed to change afterward
  • SignIn user (Online/Offline)
  • Update the password
  • Use CognitoSync linked with your userPool
    • get/set data for a user with Federated Identity

Sample :

Sample' Readme

Usage

  1. Installation :

cordova plugin add cordova-plugin-aws-user-pool

  1. Initialisation :
  this.CognitoIdentityUserPoolId = "eu-west-1_*********";
  this.CognitoIdentityUserPoolAppClientId = "*********************";
  this.CognitoIdentityUserPoolAppClientSecret = "************************";
  this.CognitoArnIdentityPoolId = "eu-west-1:********-****-****-****-************";

  var awsUserPluginInstance = new AwsUserPoolPlugin({"CognitoIdentityUserPoolId": this.CognitoIdentityUserPoolId,
     "CognitoIdentityUserPoolAppClientId": this.CognitoIdentityUserPoolAppClientId,
     "CognitoIdentityUserPoolAppClientSecret": this.CognitoIdentityUserPoolAppClientSecret,
     "arnIdentityPoolId": this.CognitoArnIdentityPoolId, "CognitoRegion": AwsUserPoolPlugin.AwsUserPoolPluginEnum.EuWest1}, function() {
     console.log("connectionPluginInstance Init Ok");
 }, function() {
     console.log("connectionPluginInstance Init Fail");
 });

If you don't use the appClientSecret just set CognitoIdentityUserPoolAppClientSecret to null

The arnIdentityPoolId is here if you use Federated Identity to store data and synchronise them with CognitoSync, if you don't use it set it to null

  1. Signup :
 awsUserPluginInstance.signUp({"id": "UniqueId", "password" : "password",
                               "attributes": [{"oneAttribute" : "its value"}]}, function(res) {
 // Success
 }, function(err) {
   // Error
 });

The Id must be unique, usually I use the email adress and change the @ with an A.

Confirm signUp :

awsUserPluginInstance.confirmSignUp({"id": username, "token": token}, function(res) {
  console.log("User confirmed, you can now signin");
}, function(err) {
  console.log("err :", err.message);
});

Resend confirmation code :

this.awsUserPluginInstance.resendConfirmationCode({"id": username}, function(res) {
    success();
}, function(err) {
    error(err);
});
  1. SignIn :
awsUserPluginInstance.signIn({"username": Username, "password": password}, function(res) {
 // Success
}, function(err) {
 // Error : err
})
  1. SignOut :
awsUserPluginInstance.signOut({}, function(res) {
 // Success
}, function(err) {
 // Error : err
})

Will SignOut the last user connected

  1. Using Federated Identity

After a successfull connection you will be able to create or to open a dataset :

a) Create or Open an existing dataset :

awsUserPluginInstance.signIn({"username": Username, "password": password}, function(res) {
 awsUserPluginInstance.createAWSCognitoDataset({"id": "YourDatasetId"}, function() {
   console.log("dataset ok");
 }, function() {
     console.log("error");
 });
}, function(err) {
 // Error : err
})

b) Get data by key :

awsUserPluginInstance.getUserDataCognitoSync({"key": "yourKey"}, function(data) {
   if (data) {
       console.log("data :", JSON.parse(data));                    
   }
   // will return null if no data are set for this key
}, function() {
 // Error
});

c) Set data by key :

awsUserPluginInstance.setUserDataCognitoSync({"key": "yourKey", "value": JSON.stringify(obj)}, callback, errCallback);
  1. Update password :
this.awsUserPluginInstance.updatePassword({"confirmationCode": "123456", "newPassword": "newPassword"}, function(res) {
  // Success
}, function(err) {
  // Error
})

Framework versions

<framework src="AWSCore" type="podspec" spec=">= 2.5.3" />
<framework src="AWSCognito" type="podspec" spec=">= 2.5.3" />
<framework src="AWSCognitoIdentityProvider" type="podspec" spec=">= 2.5.3" />
<framework src="AWSLambda" type="podspec" spec=">= 2.5.3" />
<framework src="AWSAPIGateway" type="podspec" spec=">= 2.5.3" />

cordova-plugin-aws-user-pool's People

Contributors

happygts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cordova-plugin-aws-user-pool's Issues

failing to integrate in Ionic project

I ran into problems using the JS SDK for Cognito and stumbled across your plugin. This seems like a good workaround to use native processing to get the tokens. then, I can use the tokens in the auth header for all calls to my APIG/Lambda/RDS stack on AWS. But... I am having trouble w/ your plugin. Do you have some more details on the installation of the plugin on a clean cordova app?

I cloned your repo and then did a symlink plugin add. Then, I fiddled w/ getting the cordova build for ios to run. I am currently stuck w/ an ios build from cordova that will not build and deploy in xCode. Any time to help me trouble shoot?

clang: error: linker command failed with exit code 1

cordova build ios produced this after following your steps with the sample app. Searching Google didn't help. Any clues?

cd /Users/davidplappert/Websites/app/cordova-plugin-aws-user-pool/Sample/awsUserPoolPluginSample/platforms/ios
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/davidplappert/.nvm/versions/node/v6.11.3/bin:~/.rbenv/shims:/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:/Users/davidplappert/Qt/5.5/clang_64/bin/:/Users/davidplappert/.terraform_0.6.16:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk -L/Users/davidplappert/Websites/app/cordova-plugin-aws-user-pool/Sample/awsUserPoolPluginSample/platforms/ios/build/emulator -L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSAPIGateway -L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSCognito -L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSCognitoIdentityProvider -L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSCore -L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSLambda -F/Users/davidplappert/Websites/app/cordova-plugin-aws-user-pool/Sample/awsUserPoolPluginSample/platforms/ios/build/emulator -filelist /Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Intermediates.noindex/awsUserPoolPluginSample.build/Debug-iphonesimulator/awsUserPoolPluginSample.build/Objects-normal/x86_64/awsUserPoolPluginSample.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Intermediates.noindex/awsUserPoolPluginSample.build/Debug-iphonesimulator/awsUserPoolPluginSample.build/Objects-normal/x86_64/awsUserPoolPluginSample_lto.o -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -ObjC -ObjC -lAWSAPIGateway -lAWSCognito -lAWSCognitoIdentityProvider -lAWSCore -lAWSLambda -lsqlite3 -lz -framework Foundation -framework SystemConfiguration -framework UIKit -ObjC -lAWSAPIGateway -lAWSCognito -lAWSCognitoIdentityProvider -lAWSCore -lAWSLambda -lsqlite3 -lz -framework Foundation -framework SystemConfiguration -framework UIKit -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Intermediates.noindex/awsUserPoolPluginSample.build/Debug-iphonesimulator/awsUserPoolPluginSample.build/awsUserPoolPluginSample.app.xcent /Users/davidplappert/Websites/app/cordova-plugin-aws-user-pool/Sample/awsUserPoolPluginSample/platforms/ios/build/emulator/libCordova.a -weak_framework SystemConfiguration -Xlinker -dependency_info -Xlinker /Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Intermediates.noindex/awsUserPoolPluginSample.build/Debug-iphonesimulator/awsUserPoolPluginSample.build/Objects-normal/x86_64/awsUserPoolPluginSample_dependency_info.dat -o /Users/davidplappert/Websites/app/cordova-plugin-aws-user-pool/Sample/awsUserPoolPluginSample/platforms/ios/build/emulator/awsUserPoolPluginSample.app/awsUserPoolPluginSample
ld: warning: directory not found for option '-L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSAPIGateway'
ld: warning: directory not found for option '-L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSCognito'
ld: warning: directory not found for option '-L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSCognitoIdentityProvider'
ld: warning: directory not found for option '-L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSCore'
ld: warning: directory not found for option '-L/Users/davidplappert/Library/Developer/Xcode/DerivedData/awsUserPoolPluginSample-eiwhpveylqadgnblkvgfuqemqhjn/Build/Products/Debug-iphonesimulator/AWSLambda'
ld: library not found for -lAWSAPIGateway
clang: error: linker command failed with exit code 1 (use -v to see invocation)```

Class not found

Trying out this package for the first time so if it's something obvious please let me know

I tried to match everything through the sample read me

This is my code:

var awsUserPluginInstance = new AwsUserPoolPlugin({
        "CognitoIdentityUserPoolId": 'ap-southeast-2_xxxxxxxxx',
        "CognitoIdentityUserPoolAppClientId": 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
        "CognitoIdentityUserPoolAppClientSecret": 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        "arnIdentityPoolId": 'ap-southeast-2:xxxxxxxxxxxx',
        "CognitoRegion": AwsUserPoolPlugin.AwsUserPoolPluginEnum.ApSoutheast2
    }, function (res) {
        console.log("connectionPluginInstance Init Ok", res);
    }, function (err) {
        console.error("connectionPluginInstance Init Fail", err);
    });

Which outputs:
bundle.js:71639 connectionPluginInstance Init Fail Class not found

I've tried two user pools as well

EDIT: This was only through android, I'm testing on ios now though it may appear I also have issue #2

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.