AWS Lambda / Cognito Authentication - Assumed Auth Role

I am trying to create an iOS application in Swift that uses the following authentication service using AWS Lambda - https://github.com/danilop/LambdAuth

It uses the AWS Mobile SDK for iOS to communicate with DynamoDB and Lambda - http://docs.aws.amazon.com/mobile/sdkforios/developerguide/

Here is a sample code for a website that uses the token returned by the Lambda login function, I believe the Swift code will be something similar - https://github.com/danilop/LambdAuth/blob/master/www/login .html # L69

Here is a cloud function that generates a token for the user - https://github.com/danilop/LambdAuth/blob/master/LambdAuthLogin/index.js#L102

I created an identity pool in AWS Cognito (Federated Identities), and I have two roles: auth and unauth. My application is always the unauth role (arn: aws: sts :: 123123123: Assumed role / _unauth_MOBILEHUB_123123123 / CognitoIdentityCredentials). My users are stored in a dynamodb table using a salty password.

The root of the problem is that I do not know the correct Swift code to write after I get the login token from the service in order to transfer my user to an authenticated role (use auth arn). I want him to use the auth role for every AWS service call (dynamodb, lambda, etc.). I hope someone can point me in the right direction - thanks.

+4
2

Danilo, javascript aws-sdk, :

var creds = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: //hard coded value for your system//
})

AWS.config.update({
    region: 'us-east-1',
    credentials: creds
});

var lambda = new AWS.Lambda();

, , :

creds.params['IdentityId'] = output.identityId;
creds.params['Logins'] = {};
creds.params['Logins']['cognito-identity.amazonaws.com'] = output.token;
creds.expired = true;

output - LambdAuthLogin Lambda.

0

(Facebook, Google, Twitter, Login With Amazon), OIDC, SAML Cognito User Pool.

Amazon Cognito User Pools , . , Lambda Auth ?

-1

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


All Articles