私はawsコグニトに全く新しいです、そして、これらのガイドは全部の場所にあり、私は失われています。私のawsアカウントで私はアイデンティティプールを作ったが、今私はアンドロイドアプリから新しいユーザーを作成しようとしているが、ユーザーを作成できないか、コグニートプールに接続できない。私はあなたの指導のためにこの書き込みと希望をしているかどうかはわかりません!アンドロイドにCognito IDプールを設定するにはどうすればよいですか?
ここまでは私がこれまで持っていたものです。私は、モバイルハブを使用する場合
public class aws extends AppCompatActivity
{
private EditText firstName,lastName,email,password;
private Button loginButton;
private String poolId,clientId,clientSecret;
CognitoUserPool userPool;
CognitoUserAttributes userAttributes;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
CognitoCachingCredentialsProvider credentialsProvider = new
CognitoCachingCredentialsProvider(
getApplicationContext(), // Context
"IDENTITY POOL_ID", // Identity Pool ID
MY_REGION // Region
);
CognitoSyncManager syncClient = new CognitoSyncManager(
getApplicationContext(), // Context
MY_REGION, // Region
credentialsProvider
);
Dataset dataset = syncClient.openOrCreateDataset("myDataset");
dataset.put("myKey", "myValue");
dataset.synchronize(new DefaultSyncCallback() {
@Override
public void onSuccess(Dataset dataset, List newRecords) {
//Your handler code here
}
});
poolId = "MY_POOL_ID";
clientId = "MY_CLIENT_ID";
clientSecret = "MY_CLIENT_SECRET";
ClientConfiguration clientConfiguration = new ClientConfiguration();
// Create a CognitoUserPool object to refer to your user pool
userPool = new CognitoUserPool(getBaseContext(), poolId, clientId, clientSecret, clientConfiguration);
bindActivity();
}
private void bindActivity()
{
firstName = (EditText) findViewById(R.id.register_firstNameET);
lastName = (EditText) findViewById(R.id.register_lastNameET);
email = (EditText) findViewById(R.id.register_emailET);
password = (EditText) findViewById(R.id.register_passwordET);
loginButton = (Button) findViewById(R.id.intro_register_zivit_button);
loginButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
setUpCognito();
}
});
}
private void setUpCognito()
{
// Create a CognitoUserAttributes object and add user attributes
userAttributes = new CognitoUserAttributes();
// Add the user attributes. Attributes are added as key-value pairs
// Adding user's given name.
// Note that the key is "given_name" which is the OIDC claim for given name
userAttributes.addAttribute("given_name", firstName.getText().toString());
// Adding user's lastName
userAttributes.addAttribute("family_Name", lastName.getText().toString());
// Adding user's email address
userAttributes.addAttribute("email", email.getText().toString());
setUpCognitoHandler();
}
private void setUpCognitoHandler()
{
SignUpHandler signupCallback = new SignUpHandler() {
@Override
public void onSuccess(CognitoUser cognitoUser, boolean userConfirmed, CognitoUserCodeDeliveryDetails cognitoUserCodeDeliveryDetails)
{
Log.d("myCognito","sign up succeeded!");
// Sign-up was successful
// Check if this user (cognitoUser) needs to be confirmed
if(!userConfirmed)
{
Log.d("myCognito","not confirmed! Need to confirm");
confirmUser();
// This user must be confirmed and a confirmation code was sent to the user
// cognitoUserCodeDeliveryDetails will indicate where the confirmation code was sent
// Get the confirmation code from user
}
else {
Log.d("myCognito","confirmed!");
// The user has already been confirmed
}
}
@Override
public void onFailure(Exception exception)
{
Log.d("myCognito","sign up failed!");
// Sign-up failed, check exception for the cause
}
};
userPool.signUpInBackground("user1ID", password.getText().toString(), userAttributes, null, signupCallback);
}
private void confirmUser()
{
// Callback handler for confirmSignUp API
GenericHandler confirmationCallback = new GenericHandler() {
@Override
public void onSuccess() {
// User was successfully confirmed
Log.d("myCognito","Confirmed User Success!");
}
@Override
public void onFailure(Exception exception) {
// User confirmation failed. Check exception for the cause.
Log.d("myCognito","Confirmed User faileure :(");
}
};
}
}
このクラスを作成する方法については本当に混乱して再びイム、コードは、すべてのサンプルアプリで場所を超えていました。
もhttps://github.com/awslabs/aws-sdk-android-samples/tree/master/AmazonCognitoYourUserPoolsDemoこのgithubのサンプルコードを試しています – skarfa