title: Authenticating application using Cognito and Devise
body: <p>I am trying to implement AWS Cognito into my application for better all round authentication. The system is a Rails application that is currently using Warden/Devise as the method for handling user accounts (Login,Registration).</p>
  
  <p>My goal is to have a AWS UserPool that contains the list of users for the application. When a user is verified using Cognito I wish to then search the tables that we currently use for the role and move the user to the correct area of the system based on the role that they are assigned too.</p>
  
  <p>I have started to implement the logic to handle this but have come up against a brick wall. </p>
  
  <p>Please see below my code.</p>
  
  <p><strong><em>cognito_authenticatable.rb</em></strong></p>
  
  <p>Logic for handling the cognito authentication. All i want to do here is check that the user is registered and return the valid token so i can prefer internal application checks to gather the user role. </p>
  
  <pre><code>def authenticate!
     if params[:login]
        region_name = 'us-east-2'
        user_pool_id = 'us-east-2_Qj78BNQon'
        client_id = '1pv3eno72e51mll3q36cuiojmr'
  
        client = Aws::CognitoIdentityProvider::Client.new(
           region: region_name
        )
  
        resp = client.initiate_auth({
           client_id: client_id,
           auth_flow: "USER_PASSWORD_AUTH",
           auth_parameters: {
             "USERNAME" =&gt; email,
             "PASSWORD" =&gt; password
           }
        })
       end
    end
  </code></pre>
  
  <p><strong><em>divise.rb</em></strong></p>
  
  <p>This code is just to add the new authentication strategy to the applications warden service.</p>
  
  <pre><code>config.warden do |manager|
     manager.strategies.add(:cognito, 
     Devise::Strategies::CognitoAuthenticatable)
     manager.default_strategies(:scope =&gt; :login).unshift :cognito
     manager.default_strategies(:scope =&gt; :login).pop
  end
  </code></pre>
  
  <p>The output error within the console is </p>
  
  <blockquote>
    <p>Aws::Errors::MissingCredentialsError (unable to sign request without credentials set):</p>
    
    <p>config/initializers/cognito_authenticatable.rb:23:in `authenticate!'</p>
  </blockquote>
  
  <p>and here is an image from the localhost application that was running. </p>
  
  <p><a href="https://i.stack.imgur.com/Rghtr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rghtr.png" alt="Webapplication output once i complete the login form."></a></p>
  
  <p>Any help on this would be amazing.</p>
  
  <p>Thanks in advance. </p>