cognito_idp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3d8c5449a8a464b8b744fb1d916c38c12dfb9a31ad70e2cb3a2f8a4757ad627d
4
+ data.tar.gz: bc4e834f797c2c677b600eb3ffd6efd5151a087b0b974381cf33699c6898dc21
5
+ SHA512:
6
+ metadata.gz: 999d3d47a672c0de5891b5cbe865d54d3deeffcd1e5394dd49667cc4199249fa9f06518552ce8467279db01ca972082085e4344371ebcebd345c0262e6af7169
7
+ data.tar.gz: aab452ad535d4379cc28490d239f03db2991e07b849ecae0052775e7f97ba667b956eebb5853dc027d3b0b5b5b1dd06a5f96c04edcc67417c2a1955a859c8b3f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ inherit_gem:
3
+ standard: config/base.yml
4
+
5
+ require:
6
+ - standard
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-11-29
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at richard@appercept.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Appercept Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # CognitoIdp
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cognito_idp/client`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/appercept/cognito_idp-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/appercept/cognito_idp-client/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the CognitoIdp::Client project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cognito_idp-client/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CognitoIdp
4
+ class AuthorizationUri
5
+ attr_accessor :client_id, :code_challenge_method, :code_challenge, :domain,
6
+ :idp_identifier, :identity_provider, :nonce, :redirect_uri, :response_type,
7
+ :scope, :state
8
+
9
+ def initialize(client_id:, domain:, redirect_uri:, response_type: :code, **options)
10
+ @code_challenge_method = options[:code_challenge_method]
11
+ @code_challenge = options[:code_challenge]
12
+ @client_id = client_id
13
+ @domain = domain
14
+ @identity_provider = options[:identity_provider]
15
+ @idp_identifier = options[:idp_identifier]
16
+ @nonce = options[:nonce]
17
+ @redirect_uri = redirect_uri
18
+ @response_type = response_type
19
+ @scope = options[:scope]
20
+ @state = options[:state]
21
+ end
22
+
23
+ def to_s
24
+ URI("https://#{domain}/oauth2/authorize").tap do |uri|
25
+ uri.query = URI.encode_www_form(params)
26
+ end.to_s
27
+ end
28
+
29
+ private
30
+
31
+ def params
32
+ {
33
+ client_id: client_id,
34
+ code_challenge_method: code_challenge_method,
35
+ code_challenge: code_challenge,
36
+ identity_provider: identity_provider,
37
+ idp_identifier: idp_identifier,
38
+ nonce: nonce,
39
+ redirect_uri: redirect_uri,
40
+ response_type: response_type,
41
+ scope: scope_string,
42
+ state: state
43
+ }.compact
44
+ end
45
+
46
+ def scope_string
47
+ return nil if scope.nil?
48
+
49
+ Array(scope).join(" ")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module CognitoIdp
6
+ class Client
7
+ attr_accessor :adapter, :client_id, :client_secret, :domain
8
+
9
+ def initialize(client_id:, domain:, client_secret: nil, adapter: Faraday.default_adapter, stubs: nil)
10
+ @adapter = adapter
11
+ @client_id = client_id
12
+ @client_secret = client_secret
13
+ @domain = domain
14
+ @stubs = stubs
15
+ end
16
+
17
+ def authorization_uri(redirect_uri:, **options)
18
+ AuthorizationUri.new(
19
+ client_id: client_id,
20
+ domain: domain,
21
+ redirect_uri: redirect_uri,
22
+ **options
23
+ ).to_s
24
+ end
25
+
26
+ def get_token(grant_type:, **options)
27
+ params = {
28
+ client_id: client_id,
29
+ code: options[:code],
30
+ code_verifier: options[:code_verifier],
31
+ grant_type: grant_type,
32
+ redirect_uri: options[:redirect_uri],
33
+ refresh_token: options[:refresh_token],
34
+ scope: options[:scope]
35
+ }.compact
36
+ response = connection.post("/oauth2/token", params, basic_authorization_headers)
37
+ return unless response.success?
38
+
39
+ token = Token.new(response.body)
40
+ yield(token) if block_given?
41
+ token
42
+ end
43
+
44
+ def get_user_info(token)
45
+ access_token = case token
46
+ when Token
47
+ token.access_token
48
+ else
49
+ token
50
+ end
51
+ response = connection.post("/oauth2/userInfo", nil, {"Authorization" => "Bearer #{access_token}"})
52
+ return unless response.success?
53
+
54
+ user_info = UserInfo.new(response.body)
55
+ yield(user_info) if block_given?
56
+ user_info
57
+ end
58
+
59
+ def logout_uri(**options)
60
+ LogoutUri.new(
61
+ client_id: client_id,
62
+ domain: domain,
63
+ **options
64
+ ).to_s
65
+ end
66
+
67
+ private
68
+
69
+ def connection
70
+ @connection ||= Faraday.new do |conn|
71
+ conn.url_prefix = "https://#{domain}"
72
+ conn.request :url_encoded
73
+ conn.response :json, content_type: "application/json"
74
+ conn.adapter adapter, @stubs
75
+ end
76
+ end
77
+
78
+ def basic_authorization_headers
79
+ return if client_secret.nil?
80
+
81
+ client_id_and_secret = "#{client_id}:#{client_secret}"
82
+ {"Authorization" => "Basic #{Base64.urlsafe_encode64(client_id_and_secret)}"}
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CognitoIdp
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CognitoIdp
4
+ class LogoutUri
5
+ attr_accessor :client_id, :domain, :logout_uri, :redirect_uri, :response_type, :scope, :state
6
+
7
+ def initialize(client_id:, domain:, **options)
8
+ @client_id = client_id
9
+ @domain = domain
10
+ @logout_uri = options[:logout_uri]
11
+ @redirect_uri = options[:redirect_uri]
12
+ @response_type = options[:response_type]
13
+ @scope = options[:scope]
14
+ @state = options[:state]
15
+ end
16
+
17
+ def to_s
18
+ URI("https://#{domain}/logout").tap do |uri|
19
+ uri.query = URI.encode_www_form(params)
20
+ end.to_s
21
+ end
22
+
23
+ private
24
+
25
+ def params
26
+ {
27
+ client_id: client_id,
28
+ logout_uri: logout_uri,
29
+ redirect_uri: redirect_uri,
30
+ response_type: response_type,
31
+ scope: scope_string,
32
+ state: state
33
+ }.compact
34
+ end
35
+
36
+ def scope_string
37
+ return nil if scope.nil?
38
+
39
+ Array(scope).join(" ")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CognitoIdp
4
+ class Token
5
+ attr_reader :access_token, :id_token, :token_type, :expires_at, :expires_in
6
+
7
+ def initialize(token_hash)
8
+ token_hash.transform_keys(&:to_sym).tap do |values|
9
+ @access_token = values[:access_token]
10
+ @id_token = values[:id_token]
11
+ @token_type = values[:token_type]
12
+ @expires_in = values[:expires_in]
13
+ end
14
+ @expires_at = Time.now + expires_in unless expires_in.nil?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module CognitoIdp
6
+ class UserInfo
7
+ def initialize(attributes)
8
+ @attributes = OpenStruct.new(attributes)
9
+ end
10
+
11
+ def method_missing(method, ...)
12
+ attribute = @attributes.send(method, ...)
13
+ attribute.is_a?(Hash) ? OpenStruct.new(attribute) : attribute
14
+ end
15
+
16
+ def respond_to_missing?(method, include_private = false)
17
+ @attributes.key?(method)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CognitoIdp
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cognito_idp/version"
4
+
5
+ module CognitoIdp
6
+ autoload :AuthorizationUri, "cognito_idp/authorization_uri"
7
+ autoload :Client, "cognito_idp/client"
8
+ autoload :LogoutUri, "cognito_idp/logout_uri"
9
+ autoload :Token, "cognito_idp/token"
10
+ autoload :UserInfo, "cognito_idp/user_info"
11
+ end
@@ -0,0 +1,6 @@
1
+ module CognitoIdp
2
+ module Client
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cognito_idp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Hatherall
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ description: Client for interacting with Amazon Cognito IdP (User Pools) endpoints.
28
+ email:
29
+ - richard@appercept.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - ".standard.yml"
37
+ - CHANGELOG.md
38
+ - CODE_OF_CONDUCT.md
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - lib/cognito_idp.rb
43
+ - lib/cognito_idp/authorization_uri.rb
44
+ - lib/cognito_idp/client.rb
45
+ - lib/cognito_idp/error.rb
46
+ - lib/cognito_idp/logout_uri.rb
47
+ - lib/cognito_idp/token.rb
48
+ - lib/cognito_idp/user_info.rb
49
+ - lib/cognito_idp/version.rb
50
+ - sig/cognito_idp/client.rbs
51
+ homepage: https://github.com/appercept/cognito_idp-ruby
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/appercept/cognito_idp-ruby
56
+ source_code_uri: https://github.com/appercept/cognito_idp-ruby
57
+ changelog_uri: https://github.com/appercept/cognito_idp-ruby/CHANGELOG.md
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.6.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.4.22
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Amazon Cognito IdP (User Pools) Client
77
+ test_files: []