amazon_cognito_identity_dart 0.0.1 copy "amazon_cognito_identity_dart: ^0.0.1" to clipboard
amazon_cognito_identity_dart: ^0.0.1 copied to clipboard

outdated

Unofficial Amazon Cognito Identity Provider Dart SDK

Unofficial Amazon Cognito Identity SDK for Dart #

Unofficial Amazon Cognito Identity SDK written in Dart for Dart.

Rewrite of amazon-cognito-identity-js in Dart.

Please note that this package is not production ready.

Usage #

Use Case 1. Registering a user with the application. One needs to create a CognitoUserPool object by providing a UserPoolId and a ClientId and signing up by using a username, password, attribute list, and validation data.

import 'package:amazon_cognito_identity_dart/cognito_user_pool.dart';
import 'package:amazon_cognito_identity_dart/attribute_arg.dart';

final userPool = new CognitoUserPool(
  'ap-southeast-1_xxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxxxxxxxx'
);
final userAttributes = [
  new AttributeArg(name: 'first_name', value: 'Jimmy'),
  new AttributeArg(name: 'last_name', value: 'Wong'),
];

var data;
try {
  data = await userPool.signUp(
    'email@inspire.my',
    'Password001',

    userAttributes: userAttributes, // ..optional
  );
} catch (e) {
  print(e);
}

Use case 2. Confirming a registered, unauthenticated user using a confirmation code received via SMS/email.

import 'package:amazon_cognito_identity_dart/cognito_user_pool.dart';
import 'package:amazon_cognito_identity_dart/cognito_user.dart';

final userPool = new CognitoUserPool(
  'ap-southeast-1_xxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxxxxxxxx'
);

final cognitoUser = new CognitoUser(
  'email@inspire.my',
  pool,
);

var result;
try {
  result = await cognitoUser.confirmRegistration('123456');
} catch (e) {
  print(e);
}


print(result);

Use case 3. Resending a confirmation code via SMS/email for confirming registration for unauthenticated users.

import 'package:amazon_cognito_identity_dart/cognito_user.dart';
import 'package:amazon_cognito_identity_dart/cognito_user_pool.dart';

final userPool = new CognitoUserPool(
  'ap-southeast-1_xxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxxxxxxxx'
);
final cognitoUser = new CognitoUser(
  'email@inspire.my',
  pool,
);
final String status;
try {
  status = await cognitoUser.resendConfirmationCode();
} catch (e) {
  print(e);
}

Use case 4. Authenticating a user and establishing a user session with the Amazon Cognito Identity service.

import 'package:amazon_cognito_identity_dart/cognito_user.dart';
import 'package:amazon_cognito_identity_dart/cognito_user_pool.dart';
import 'package:amazon_cognito_identity_dart/cognito_user_session.dart';

final userPool = new CognitoUserPool(
  'ap-southeast-1_xxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxxxxxxxx'
);
final cognitoUser = new CognitoUser(
  'email@inspire.my',
  pool,
);
final authDetails = new AuthenticationDetails(
  username: 'email@inspire.my',
  password: 'Password001',
);
CognitoUserSession session;
try {
  session = await cognitoUser.authenticateUser(authDetails);
} on CognitoUserNewPasswordRequiredException catch (e) {
  // handle New Password challenge
} on CognitoUserMfaRequiredException catch (e) {
  // handle SMS_MFA challenge
} on CognitoUserSelectMfaTypeException catch (e) {
  // handle SELECT_MFA_TYPE challenge
} on CognitoUserMfaSetupException catch (e) {
  // handle MFA_SETUP challenge
} on CognitoUserTotpRequiredException catch (e) {
  // handle SOFTWARE_TOKEN_MFA challenge
} on CognitoUserCustomChallengeException catch (e) {
  // handle CUSTOM_CHALLENGE challenge
} on CognitoUserConfirmationNecessaryException catch (e) {
  // handle User Confirmation Necessary
} catch (e) {
  print(e);
}
print(session.getAccessToken().getJwtToken());

Use case 14. Signing out from the application.

cognitoUser.signOut();

Use case 15. Global signout for authenticated users (invalidates all issued tokens).

await cognitoUser.globalSignOut();
34
likes
0
pub points
69%
popularity

Publisher

unverified uploader

Unofficial Amazon Cognito Identity Provider Dart SDK

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

crypto, http, secure_string

More

Packages that depend on amazon_cognito_identity_dart