Can I create AWS Cognito user login programmatically?

I would like my application to allow users of Facebook, Google, Amazon accounts ... etc. Log in to my app. This works great through AWS Cognito.

However, is there a way for an application to create a login to enter the system programmatically if the user does not have any of these logins?

  • The user will provide an identifier and password, and the application will send the information to the authentication provider to create a new login / account.

  • I would not need to implement my own authentication mechanism and worry about how passwords are stored, etc.

From my research, I believe that there is no way to do this with existing authentication providers or even with other services such as OpenID.

Do you have any other options if I don't want to implement my own name storage and authentication? It would not be necessary to integrate with AWS Cognito.

+5
source share
2 answers

I am a little confused by your question. If you ask:

Can I create new Facebook / Google usernames and passwords programmatically?

Then the answer is no. You must register with Facebook / Google on your site. If you ask:

Is it possible to create a new user with a username and password that exists only in Cognito?

Then the answer is yes. To do this, it depends on whether you are creating a user in a browser or on a server. In the browser, use the Cognito Javascript API . On the server, use the Cognito Admin Server API .

Here is a sample code for creating a new user on the server in Node JS (replace my lines with your tokens, especially those with @ signs):

let params = { UserPoolId: "@ cognito_pool_id@ ", Username: "jhancock", DesiredDeliveryMediums: ["EMAIL"], ForceAliasCreation: false, MessageAction: "SUPPRESS", TemporaryPassword: "somePassword", UserAttributes: [ { Name: "given_name", Value: "John"}, { Name: "family_name", Value: "Hancock"}, { Name: "name", Value: "John Hancock"}, { Name: "email", Value: " john@gmail.com "}, { Name: "phone_number", Value: "+15125551212"} ], }; console.log("Sending params to cognito: " + JSON.stringify(params)); let cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider({region: "us-east-1"}); cognitoIdentityServiceProvider.adminCreateUser(params, function(error, data) { if (error) { console.log("Error adding user to cognito: " + JSON.stringify(error), error.stack); } else { console.log("Received back from cognito: " + JSON.stringify(data)); } } 

Once you get this job, you probably want to see this post on how to change the temporary password to a real one .

+2
source

Hello from my previous experience in implementing authentication on social networks. I would conclude that it is quite difficult to implement. If you do not want to show the web view for user authentication in iOS, you need to use the ACAccountStore iOS ACAccountStore for this, but even this makes it possible to log in so as not to log in.

0
source

Source: https://habr.com/ru/post/1200249/


All Articles