3

Im trying to authenticate AWS Cognito Service to upload images to S3 bucket.I tried to followed "http://docs.aws.amazon.com/cognito/latest/developerguide/developer-authenticated-identities.html", but Im getting confused. I want to authenticate using developer identities as Im not using Cognito services for my login. My class used for authentication is as below:

import AWSCore
class DeveloperAuthenticatedIdentityProvider : AWSCognitoCredentialsProviderHelper {
     override func token() -> AWSTask<NSString> {

          //I have no clue what it returns and there also an error here
          self.identityId = response.identityId
          return AWSTask(result: response.token)

     }
}

I am using my credentials as below:

 let devAuth = DeveloperAuthenticatedIdentityProvider(regionType: .USWest2, identityPoolId: "pool-id", useEnhancedFlow: true, identityProviderManager:nil)
 let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USWest2, identityProvider:devAuth)
 let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider:credentialsProvider)
 AWSServiceManager.default().defaultServiceConfiguration = configuration

And Im uploading to S3 as below:

let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest?.body = fileURL as URL
let awsImageName = "1002_" + UUID().uuidString
uploadRequest?.key = awsImageName + "." + ext
uploadRequest?.bucket = S3BucketName
uploadRequest?.contentType = "image/" + ext
let transferManager = AWSS3TransferManager.default()
 // Perform Upload
transferManager.upload(uploadRequest!).continueWith(block: { (task:AWSTask<AnyObject>) -> AnyObject! in

It works fine without authentication, but I want use it with authentication. Can Someone tell how should I go about?I new to swift and also AWS Cognito Services.

1 Answers1

0

I think you are switching cognitio with IAM. Cognito is used as an identity-provider for your own application or mobile app. It is a cloud identity provider which you can use as a service. You can allow other users to sign up throughout your own UI and combine this with Facebook, Google, ...

IAM is used to identify who can use these cloud services like Cognito, S3, EC2. Which roles are required to use s3 etc.

The reason why it works without authentication is cause you have probably installed the AWS SDK or cli which stores this IAM information. Your application will use it as a fallback.

Take a look at IAM,create a developer role which can access S3 and assume that Role. Get the secret and access keys for your account and you can forget Cognito for now

More info:

http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html

http://docs.aws.amazon.com/cli/latest/userguide/cli-roles.html

Rob Van Pamel
  • 734
  • 1
  • 8
  • 23