No release in over 3 years
Low commit activity in last 3 years
With this gem you can implement: CRUD functionality from you application, synchronize you database users with user_pools, handling authorization
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

CognitoSyncService

logo

Status

Gem Version Maintainability Build Status Test Coverage Inline docs Built with love

Content

  • CognitoSyncService
    • Installation
    • Usage
    • Methods
    • Development
    • Contributing
    • Contacts
    • License
    • Status

Installation

Add this line to your application's Gemfile:

gem 'cognito-sync-service', '~> 1.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cognito-sync-service

Usage

AWS Cognito let use list of methods or this SDK methods for ruby.

In common case you need CRUD functionality, synchronization, between your DB and Cognito pools and handling authorization.

With this gem you can implement:

  1. CRUD functionality from you application
  2. (WIP) Synchronize you database users with user_pools
  3. (WIP)Handling authorization

Step 1

Add required lib to you module or class

require 'aws-sdk-cognitoidentityprovider'

Create you cognito provider method in this module for example

for rails:

def cognito_provider
  ::Aws::CognitoIdentityProvider::Client.new(
    access_key_id: Rails.application.credentials.dig(:access_key_id),
    secret_access_key: Rails.application.credentials.dig(:secret_access_key),
    region: Rails.application.credentials.dig(Rails.env.to_sym, :region)
  )
end

or with ENV variables

def cognito_provider
  ::Aws::CognitoIdentityProvider::Client.new(
    access_key_id: ENV['access_key_id'],
    secret_access_key: ENV['secret_access_key'],
    region: ENV['region']
  )
end

or come up with any other way to implement the method cognito_prodiver

def cognito_provider
	# your code
end

Step 2

Define two methods that will return pool_id and cliend_pool_id with web_pool_id and web_client_id names

  def web_pool_id
    @web_pool_id ||= ENV['aws']['pool_id']
  end

  def web_client_id
    @web_client_id ||= ENV['aws']['client_id']
  end

or come up with any other way to implement the method cognito_prodiver

  def web_pool_id
    'us-east-1_DaexV9pOc' # Pool Id example
  end

  def web_client_id
    '6d1rss9carten3pkl0134658g5p' # Client id example
  end

Step 3

Above methods should be extend not included to you class

In other words, the methods should be available to the class but not to the instance.

# example with User class
User.cognito_provider # => #<Aws::CognitoIdentityProvider::Client>
User.web_poool_id # => 'us-east-1_DaexV9pOc'
User.web_client_id # => '6d1rss9carten3pkl0134658g5p'

Step 4

Add required lib to you class

require 'cognito-sync-service'

extend cognito sync service in you class

extend CognitoSyncService

Primitive example

require 'aws-sdk-cognitoidentityprovider'
require 'cognito-sync-service'

class User
  extend CognitoSyncService

  def self.cognito_provider
    ::Aws::CognitoIdentityProvider::Client.new( access_key_id: "access_key_id", secret_access_key: "secret_access_key", region: "region")
  end

  def self.web_pool_id
    @web_pool_id ||= "pool_id"
  end

  def self.web_client_id
    @web_client_id ||= "client_id"
  end
end

User.ca_create!({phone_number: "+1111111111"}, "+1111111111")
# => {
#  "username"=>"fd09f027-bebf-4f43-abf9-248130145107f",
#  "user_create_date"=>2077-77-11 16:27:14 +0300,
#  "user_last_modified_date"=>2077-77-26 16:27:14 +0300,
#  "enabled"=>true,
#  "user_status"=>"FORCE_CHANGE_PASSWORD",
#  "phone_number"=>"+1111111111"
#}

List of methods

naming note:

methods naming was inspired by cognito naming but we added a prefix for a slight difference and changed the names to more understandable for ruby developers

ca_action => cognito_admin_action

c_action => cognito_action

Development

See DEVELOPMENT.md.

Contributing

See CONTRIBUTING.md.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the CognitoSyncService project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Contacts

https://7devs.co/contact?section=contact-form

https://t.me/hakmatmao