4.2.2 Using user pools with Bayun AWSS3 wrapper 'SecureAuthentication'
User Registration, SignUp Confirmation, SignIn, SignOut needs to be done with SecureAuthentication instance.
Set up your service config
There is no change in setting up Service Config and is same as using standard AWS Mobile SDK.
// Create a user pool with default ClientConfiguration
CognitoUserPool userPool = new CognitoUserPool(context, userPoolId, clientId, clientSecret, cognitoRegion);// Create a user pool with default ClientConfiguration
var userPool: CognitoUserPool =
CognitoUserPool(context, userPoolId, clientId, clientSecret, cognitoRegion)OR
// This will also work
ClientConfiguration clientConfiguration = new ClientConfiguration();
AmazonCognitoIdentityProvider cipClient = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), clientConfiguration);
cipClient.setRegion(Region.getRegion(cognitoRegion));
CognitoUserPool userPool = new CognitoUserPool(context, userPoolId, clientId, clientSecret, cipClient);// This will also work
val clientConfiguration :ClientConfiguration = ClientConfiguration()
val cipClient :AmazonCognitoIdentityProvider = AmazonCognitoIdentityProviderClient( AnonymousAWSCredentials(), clientConfiguration)
cipClient.setRegion(Region.getRegion(cognitoRegion))
val userPool:CognitoUserPool = CognitoUserPool(context, userPoolId, clientId, clientSecret, cipClient)
Set Up the SecureAuthentication object
The SecureAuthentication is a singleton object, and must be provided with context, appId and companyName before using it. This will serve as the object on which all function calls are to be made.
SecureAuthentication secureAuthentication = SecureAuthentication.getInstance();
secureAuthentication.setContext(appContext);
secureAuthentication.setAppId(APP_ID);
secureAuthentication.setAppSecret(APP_SECRET);
secureAuthentication.setApplicationKeySalt(APP_SALT);
secureAuthentication.setCompanyName(companyName);val secureAuthentication = SecureAuthentication.getInstance()
secureAuthentication.setContext(appContext)
secureAuthentication.setAppId(APP_ID)
secureAuthentication.setAppSecret(APP_SECRET);
secureAuthentication.setApplicationKeySalt(APP_SALT);
secureAuthentication.setCompanyName(companyName)Register a User
Use SecureAuthentication's method signUp to register a new user instead of relying on standard AWS Mobile SDK's signUp method.
Confirm Signup
Confirm a users' sign up with the confirmation code using SecureAuthentication's confirmSignUp method. Use this method instead of CognitoUser's method, to confirm signup with both Cognito and Bayun.
Sign in a user
Use SecureAuthentication's signIn method to get a session, using username and password, with both Cognito and Bayun, instead of CognitoUser's method.
Sign out a user
Use SecureAuthentication's signOut method to clear all tokens and logout of Bayun as well, instead of using CognitoUser's method. User will have to go through the authentication process to get tokens.
Last updated
Was this helpful?