cognito-sync-service 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.example +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +58 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +8 -0
- data/DEVELOPMENT.md +4 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +138 -0
- data/LICENSE.txt +21 -0
- data/README.md +202 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/cognito-sync-service-0.2.0.gem +0 -0
- data/cognito-sync-service-0.3.0.gem +0 -0
- data/cognito-sync-service-0.3.1.gem +0 -0
- data/cognito_sync_service.gemspec +53 -0
- data/doc/ca_create!.md +39 -0
- data/doc/ca_delete!.md +25 -0
- data/doc/ca_disable!.md +25 -0
- data/doc/ca_find!.md +52 -0
- data/doc/ca_initiate_auth!.md +46 -0
- data/doc/ca_respond_to_auth_challenge!.md +46 -0
- data/doc/ca_update!.md +43 -0
- data/lib/cognito-sync-service.rb +79 -0
- data/lib/cognito-sync-service/version.rb +5 -0
- data/lib/cognito_attributes_converter.rb +68 -0
- metadata +32 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8adff1ff81cd0fc655dd6e0337f2a0b90fb441bdafbeb423d286b11170817454
|
|
4
|
+
data.tar.gz: baff1f55ef80cabcbe4b221300bd006e5546f28817a5a17f0c3a28e56d94d9ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec518067768c51bcfce2146673ca20cd467604afcc7b2b05f6a73197c35497bcdf47624f8294ae40039da6d14e302e9fa4d510ddf7f5d6454450e9a299cd0ac9
|
|
7
|
+
data.tar.gz: 4c60d0a5f6ffeea2f8ce040a8511379aa946828f7a957643dbd190d6ba425f5fe6572e701a08f7549fced563ef0cfc9196ffb1fa0037b157ae16f9faa2a57789
|
data/.env.example
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
Exclude:
|
|
3
|
+
- 'bin/*'
|
|
4
|
+
- '*.gemspec'
|
|
5
|
+
- 'Rakefile'
|
|
6
|
+
|
|
7
|
+
ModuleLength:
|
|
8
|
+
Enabled: false
|
|
9
|
+
|
|
10
|
+
LineLength:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
StringLiterals:
|
|
14
|
+
EnforcedStyle: single_quotes
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
17
|
+
Layout/DotPosition:
|
|
18
|
+
EnforcedStyle: leading
|
|
19
|
+
Enabled: true
|
|
20
|
+
|
|
21
|
+
Documentation:
|
|
22
|
+
Enabled: false
|
|
23
|
+
|
|
24
|
+
Naming/MemoizedInstanceVariableName:
|
|
25
|
+
Enabled: false
|
|
26
|
+
|
|
27
|
+
Metrics/AbcSize:
|
|
28
|
+
Max: 40
|
|
29
|
+
Enabled: true
|
|
30
|
+
|
|
31
|
+
Metrics/BlockLength:
|
|
32
|
+
CountComments: false
|
|
33
|
+
Max: 300
|
|
34
|
+
Enabled: true
|
|
35
|
+
|
|
36
|
+
Metrics/ClassLength:
|
|
37
|
+
CountComments: false
|
|
38
|
+
Max: 320
|
|
39
|
+
Enabled: true
|
|
40
|
+
|
|
41
|
+
Metrics/PerceivedComplexity:
|
|
42
|
+
Max: 12
|
|
43
|
+
Enabled: true
|
|
44
|
+
|
|
45
|
+
Metrics/CyclomaticComplexity:
|
|
46
|
+
Max: 12
|
|
47
|
+
Enabled: true
|
|
48
|
+
|
|
49
|
+
Metrics/ParameterLists:
|
|
50
|
+
Max: 10
|
|
51
|
+
|
|
52
|
+
Metrics/MethodLength:
|
|
53
|
+
CountComments: false
|
|
54
|
+
Max: 30
|
|
55
|
+
Enabled: true
|
|
56
|
+
|
|
57
|
+
Naming/UncommunicativeMethodParamName:
|
|
58
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at mark.osipenko@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
1. Fork it ( https://github.com/[username]/cognito-sync-service )
|
|
3
|
+
2. Run `spec` and `rubocop` (don't forget add spec_credentials to you local project folder)
|
|
4
|
+
3. Create your feature branch (git checkout -b my-new-feature)
|
|
5
|
+
4. Commit your changes (git commit -am 'Add some feature')
|
|
6
|
+
5. Push to the branch (git push origin my-new-feature)
|
|
7
|
+
6. Create a new Pull Request
|
|
8
|
+
7. Run `spec` and `rubocop` again
|
data/DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
|
|
2
|
+
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.
|
|
3
|
+
|
|
4
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/Gemfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
group :development, :test do
|
|
6
|
+
gem 'aws-sdk-cognitoidentity', '~> 1.0.0.rc7'
|
|
7
|
+
gem 'aws-sdk-cognitoidentityprovider', '~> 1.12'
|
|
8
|
+
gem 'aws-sdk-cognitosync', '~> 1.6'
|
|
9
|
+
gem 'aws-sdk-ec2', '~> 1'
|
|
10
|
+
gem 'aws-sdk-s3', '~> 1'
|
|
11
|
+
gem 'aws-sdk-ses', '~> 1.6'
|
|
12
|
+
|
|
13
|
+
gem 'pry', '~> 0.10', require: false
|
|
14
|
+
gem 'pry-byebug', '~> 3.4'
|
|
15
|
+
gem 'pry-doc', '~> 1.0.0', require: false
|
|
16
|
+
gem 'rb-readline'
|
|
17
|
+
|
|
18
|
+
gem 'factory_bot', '~> 4.8'
|
|
19
|
+
gem 'rspec', '~> 3.6'
|
|
20
|
+
gem 'rubocop', require: false
|
|
21
|
+
gem 'rubocop-rspec', require: false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
group :test do
|
|
25
|
+
gem 'rspec-its', '~> 1.2'
|
|
26
|
+
gem 'rspec-simplecov', '~> 0.2'
|
|
27
|
+
gem 'simplecov', '~> 0.14'
|
|
28
|
+
gem 'simplecov-console'
|
|
29
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
activesupport (5.2.3)
|
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
6
|
+
i18n (>= 0.7, < 2)
|
|
7
|
+
minitest (~> 5.1)
|
|
8
|
+
tzinfo (~> 1.1)
|
|
9
|
+
ansi (1.5.0)
|
|
10
|
+
ast (2.4.0)
|
|
11
|
+
aws-eventstream (1.0.3)
|
|
12
|
+
aws-partitions (1.195.0)
|
|
13
|
+
aws-sdk-cognitoidentity (1.0.1)
|
|
14
|
+
aws-sdk-core (~> 3)
|
|
15
|
+
aws-sigv4 (~> 1.0)
|
|
16
|
+
aws-sdk-cognitoidentityprovider (1.25.0)
|
|
17
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
|
18
|
+
aws-sigv4 (~> 1.1)
|
|
19
|
+
aws-sdk-cognitosync (1.15.0)
|
|
20
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
|
21
|
+
aws-sigv4 (~> 1.1)
|
|
22
|
+
aws-sdk-core (3.61.2)
|
|
23
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
|
24
|
+
aws-partitions (~> 1.0)
|
|
25
|
+
aws-sigv4 (~> 1.1)
|
|
26
|
+
jmespath (~> 1.0)
|
|
27
|
+
aws-sdk-ec2 (1.102.0)
|
|
28
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
|
29
|
+
aws-sigv4 (~> 1.1)
|
|
30
|
+
aws-sdk-kms (1.24.0)
|
|
31
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
|
32
|
+
aws-sigv4 (~> 1.1)
|
|
33
|
+
aws-sdk-s3 (1.46.0)
|
|
34
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
|
35
|
+
aws-sdk-kms (~> 1)
|
|
36
|
+
aws-sigv4 (~> 1.1)
|
|
37
|
+
aws-sdk-ses (1.25.0)
|
|
38
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
|
39
|
+
aws-sigv4 (~> 1.1)
|
|
40
|
+
aws-sigv4 (1.1.0)
|
|
41
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
|
42
|
+
byebug (11.0.1)
|
|
43
|
+
coderay (1.1.2)
|
|
44
|
+
concurrent-ruby (1.1.5)
|
|
45
|
+
diff-lcs (1.3)
|
|
46
|
+
docile (1.3.2)
|
|
47
|
+
factory_bot (4.11.1)
|
|
48
|
+
activesupport (>= 3.0.0)
|
|
49
|
+
i18n (1.6.0)
|
|
50
|
+
concurrent-ruby (~> 1.0)
|
|
51
|
+
jaro_winkler (1.5.3)
|
|
52
|
+
jmespath (1.4.0)
|
|
53
|
+
json (2.2.0)
|
|
54
|
+
method_source (0.9.2)
|
|
55
|
+
minitest (5.11.3)
|
|
56
|
+
parallel (1.17.0)
|
|
57
|
+
parser (2.6.3.0)
|
|
58
|
+
ast (~> 2.4.0)
|
|
59
|
+
pry (0.12.2)
|
|
60
|
+
coderay (~> 1.1.0)
|
|
61
|
+
method_source (~> 0.9.0)
|
|
62
|
+
pry-byebug (3.7.0)
|
|
63
|
+
byebug (~> 11.0)
|
|
64
|
+
pry (~> 0.10)
|
|
65
|
+
pry-doc (1.0.0)
|
|
66
|
+
pry (~> 0.11)
|
|
67
|
+
yard (~> 0.9.11)
|
|
68
|
+
rainbow (3.0.0)
|
|
69
|
+
rb-readline (0.5.5)
|
|
70
|
+
rspec (3.8.0)
|
|
71
|
+
rspec-core (~> 3.8.0)
|
|
72
|
+
rspec-expectations (~> 3.8.0)
|
|
73
|
+
rspec-mocks (~> 3.8.0)
|
|
74
|
+
rspec-core (3.8.2)
|
|
75
|
+
rspec-support (~> 3.8.0)
|
|
76
|
+
rspec-expectations (3.8.4)
|
|
77
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
78
|
+
rspec-support (~> 3.8.0)
|
|
79
|
+
rspec-its (1.3.0)
|
|
80
|
+
rspec-core (>= 3.0.0)
|
|
81
|
+
rspec-expectations (>= 3.0.0)
|
|
82
|
+
rspec-mocks (3.8.1)
|
|
83
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
84
|
+
rspec-support (~> 3.8.0)
|
|
85
|
+
rspec-simplecov (0.2.2)
|
|
86
|
+
rspec-support (3.8.2)
|
|
87
|
+
rubocop (0.73.0)
|
|
88
|
+
jaro_winkler (~> 1.5.1)
|
|
89
|
+
parallel (~> 1.10)
|
|
90
|
+
parser (>= 2.6)
|
|
91
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
92
|
+
ruby-progressbar (~> 1.7)
|
|
93
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
|
94
|
+
rubocop-rspec (1.33.0)
|
|
95
|
+
rubocop (>= 0.60.0)
|
|
96
|
+
ruby-progressbar (1.10.1)
|
|
97
|
+
simplecov (0.17.0)
|
|
98
|
+
docile (~> 1.1)
|
|
99
|
+
json (>= 1.8, < 3)
|
|
100
|
+
simplecov-html (~> 0.10.0)
|
|
101
|
+
simplecov-console (0.5.0)
|
|
102
|
+
ansi
|
|
103
|
+
simplecov
|
|
104
|
+
terminal-table
|
|
105
|
+
simplecov-html (0.10.2)
|
|
106
|
+
terminal-table (1.8.0)
|
|
107
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
108
|
+
thread_safe (0.3.6)
|
|
109
|
+
tzinfo (1.2.5)
|
|
110
|
+
thread_safe (~> 0.1)
|
|
111
|
+
unicode-display_width (1.6.0)
|
|
112
|
+
yard (0.9.20)
|
|
113
|
+
|
|
114
|
+
PLATFORMS
|
|
115
|
+
ruby
|
|
116
|
+
|
|
117
|
+
DEPENDENCIES
|
|
118
|
+
aws-sdk-cognitoidentity (~> 1.0.0.rc7)
|
|
119
|
+
aws-sdk-cognitoidentityprovider (~> 1.12)
|
|
120
|
+
aws-sdk-cognitosync (~> 1.6)
|
|
121
|
+
aws-sdk-ec2 (~> 1)
|
|
122
|
+
aws-sdk-s3 (~> 1)
|
|
123
|
+
aws-sdk-ses (~> 1.6)
|
|
124
|
+
factory_bot (~> 4.8)
|
|
125
|
+
pry (~> 0.10)
|
|
126
|
+
pry-byebug (~> 3.4)
|
|
127
|
+
pry-doc (~> 1.0.0)
|
|
128
|
+
rb-readline
|
|
129
|
+
rspec (~> 3.6)
|
|
130
|
+
rspec-its (~> 1.2)
|
|
131
|
+
rspec-simplecov (~> 0.2)
|
|
132
|
+
rubocop
|
|
133
|
+
rubocop-rspec
|
|
134
|
+
simplecov (~> 0.14)
|
|
135
|
+
simplecov-console
|
|
136
|
+
|
|
137
|
+
BUNDLED WITH
|
|
138
|
+
2.0.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Mark Osipenko
|
|
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,202 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
Aws Cognito user pool synchronizer
|
|
4
|
+
|
|
5
|
+
- [CognitoSyncService](#cognitoSyncService)
|
|
6
|
+
- [Installation](#installation)
|
|
7
|
+
- [Usage](#usage)
|
|
8
|
+
- [Development](#development)
|
|
9
|
+
- [Contributing](#contributing)
|
|
10
|
+
- [Contacts](#contacts)
|
|
11
|
+
- [License](#license)
|
|
12
|
+
- [Status](#status)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Add this line to your application's Gemfile:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'cognito-sync-service', '~> 0.3.0'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
And then execute:
|
|
23
|
+
|
|
24
|
+
$ bundle
|
|
25
|
+
|
|
26
|
+
Or install it yourself as:
|
|
27
|
+
|
|
28
|
+
$ gem install cognito-sync-service
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
[AWS Cognito](https://aws.amazon.com/ru/cognito/) let use [list of methods](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/index.html) or this [SDK methods for ruby](https://docs.aws.amazon.com/sdkforruby/api/Aws/CognitoIdentity/Client.html).
|
|
33
|
+
|
|
34
|
+
In common case you need __CRUD__ functionality, __synchronization__, between you DB and Cognito pools and __handling authorization__.
|
|
35
|
+
|
|
36
|
+
#### With this gem you can implement:
|
|
37
|
+
1. __CRUD__ functionality from you application
|
|
38
|
+
2. `(WIP)` __Synchronize__ you database users with user_pools
|
|
39
|
+
3. `(WIP)`__Handling authorization__
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Step 1
|
|
43
|
+
> Add required lib to you module or class
|
|
44
|
+
```ruby
|
|
45
|
+
require 'aws-sdk-cognitoidentityprovider'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
> Create you __cognito provider__ method in this module for example
|
|
49
|
+
>
|
|
50
|
+
> for rails:
|
|
51
|
+
```ruby
|
|
52
|
+
|
|
53
|
+
def cognito_provider
|
|
54
|
+
::Aws::CognitoIdentityProvider::Client.new(
|
|
55
|
+
access_key_id: Rails.application.credentials.dig(:access_key_id),
|
|
56
|
+
secret_access_key: Rails.application.credentials.dig(:secret_access_key),
|
|
57
|
+
region: Rails.application.credentials.dig(Rails.env.to_sym, :region)
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
```
|
|
61
|
+
> or with `ENV` variables
|
|
62
|
+
```ruby
|
|
63
|
+
def cognito_provider
|
|
64
|
+
::Aws::CognitoIdentityProvider::Client.new(
|
|
65
|
+
access_key_id: ENV['access_key_id'],
|
|
66
|
+
secret_access_key: ENV['secret_access_key'],
|
|
67
|
+
region: ENV['region']
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
> or come up with any other way to implement the method __cognito_prodiver__
|
|
72
|
+
```ruby
|
|
73
|
+
def cognito_provider
|
|
74
|
+
# your code
|
|
75
|
+
end
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Step 2
|
|
79
|
+
> Define two methods that will return `pool_id` and `cliend_pool_id` with `web_pool_id` and `web_client_id` names
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
def web_pool_id
|
|
83
|
+
@web_pool_id ||= ENV['aws']['pool_id']
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def web_client_id
|
|
87
|
+
@web_client_id ||= ENV['aws']['client_id']
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
> or come up with any other way to implement the method __cognito_prodiver__
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
def web_pool_id
|
|
95
|
+
'us-east-1_DaexV9pOc' # Pool Id example
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def web_client_id
|
|
99
|
+
'6d1rss9carten3pkl0134658g5p' # Client id example
|
|
100
|
+
end
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Step 3
|
|
104
|
+
|
|
105
|
+
> Above methods should be `extend` ~~not included~~ to you class
|
|
106
|
+
>
|
|
107
|
+
> In other words, the methods should be available to the `class` but not to the instance.
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
# example with User class
|
|
111
|
+
User.cognito_provider # => #<Aws::CognitoIdentityProvider::Client>
|
|
112
|
+
User.web_poool_id # => 'us-east-1_DaexV9pOc'
|
|
113
|
+
User.web_client_id # => '6d1rss9carten3pkl0134658g5p'
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Step 4
|
|
117
|
+
> Add required lib to you class
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
require 'cognito-sync-service'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
> extend cognito sync service in you class
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
extend CognitoSyncService
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Primitive example
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
require 'aws-sdk-cognitoidentityprovider'
|
|
133
|
+
require 'cognito-sync-service'
|
|
134
|
+
|
|
135
|
+
class User
|
|
136
|
+
extend CognitoSyncService
|
|
137
|
+
|
|
138
|
+
def self.cognito_provider
|
|
139
|
+
::Aws::CognitoIdentityProvider::Client.new( access_key_id: "access_key_id", secret_access_key: "secret_access_key", region: "region")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def self.web_pool_id
|
|
143
|
+
@web_pool_id ||= "pool_id"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def self.web_client_id
|
|
147
|
+
@web_client_id ||= "client_id"
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
User.ca_create!({phone_number: "+1111111111"}, "+1111111111")
|
|
152
|
+
# => {
|
|
153
|
+
# "username"=>"fd09f027-bebf-4f43-abf9-248130145107f",
|
|
154
|
+
# "user_create_date"=>2077-77-11 16:27:14 +0300,
|
|
155
|
+
# "user_last_modified_date"=>2077-77-26 16:27:14 +0300,
|
|
156
|
+
# "enabled"=>true,
|
|
157
|
+
# "user_status"=>"FORCE_CHANGE_PASSWORD",
|
|
158
|
+
# "phone_number"=>"+1111111111"
|
|
159
|
+
#}
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## List of methods
|
|
164
|
+
|
|
165
|
+
*naming note:*
|
|
166
|
+
> 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
|
|
167
|
+
|
|
168
|
+
`ca`_action => `cognito_admin`_action
|
|
169
|
+
|
|
170
|
+
`c`_action => `cognito`_action
|
|
171
|
+
|
|
172
|
+
- [#ca_create!](doc/ca_create!.md)
|
|
173
|
+
- [#ca_update!](doc/ca_update!.md)
|
|
174
|
+
- [#ca_delete!](doc/ca_delete!.md)
|
|
175
|
+
- [#ca_disable!](doc/ca_disable!.md)
|
|
176
|
+
- [#ca_find!](doc/ca_find!.md)
|
|
177
|
+
- [#ca_initiate_auth!](doc/ca_initiate_auth!.md)
|
|
178
|
+
- [#ca_respond_to_auth_challenge!](doc/ca_respond_to_auth_challenge!.md)
|
|
179
|
+
|
|
180
|
+
## Development
|
|
181
|
+
|
|
182
|
+
See [DEVELOPMENT.md](https://github.com/MarkOsipenko/cognito-sync-service/blob/master/DEVELOPMENT.md).
|
|
183
|
+
|
|
184
|
+
## Contributing
|
|
185
|
+
|
|
186
|
+
See [CONTRIBUTING.md](https://github.com/MarkOsipenko/cognito-sync-service/blob/master/CONTRIBUTING.md).
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
191
|
+
|
|
192
|
+
## Code of Conduct
|
|
193
|
+
|
|
194
|
+
Everyone interacting in the CognitoSyncService project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/MarkOsipenko/cognito-sync-service/blob/master/CODE_OF_CONDUCT.md).
|
|
195
|
+
## Contacts
|
|
196
|
+
|
|
197
|
+
https://7devs.co/contact?section=contact-form
|
|
198
|
+
https://t.me/hakmatmao
|
|
199
|
+
|
|
200
|
+
## Status
|
|
201
|
+
[](https://codeclimate.com/github/MarkOsipenko/cognito-sync-service/maintainability)
|
|
202
|
+
[](https://codeclimate.com/github/MarkOsipenko/cognito-sync-service/test_coverage)
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'cognito-sync-service'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'cognito-sync-service/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'cognito-sync-service'
|
|
9
|
+
spec.version = CognitoSyncService::VERSION
|
|
10
|
+
spec.authors = ['Mark Osipenko']
|
|
11
|
+
spec.email = ['mark.osipenko@gmail.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Aws Cognito user pool synchronizer'
|
|
14
|
+
spec.description = 'With this gem you can implement: CRUD functionality from you application, synchronize you database users with user_pools, handling authorization'
|
|
15
|
+
spec.homepage = 'https://github.com/7DevsApps/cognito-sync-service'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org.
|
|
19
|
+
# To allow pushes either set the 'allowed_push_host'
|
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
21
|
+
if spec.respond_to?(:metadata)
|
|
22
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
23
|
+
spec.metadata['source_code_uri'] = 'https://github.com/7DevsApps/cognito-sync-service'
|
|
24
|
+
spec.metadata['changelog_uri'] = 'https://github.com/7DevsApps/cognito-sync-service'
|
|
25
|
+
else
|
|
26
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
|
27
|
+
'public gem pushes.'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
32
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
34
|
+
end
|
|
35
|
+
spec.bindir = 'exe'
|
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
37
|
+
spec.require_paths = ['lib']
|
|
38
|
+
|
|
39
|
+
spec.add_dependency 'aws-sdk-cognitoidentity', '~> 1.0'
|
|
40
|
+
spec.add_dependency 'aws-sdk-cognitoidentityprovider', '~> 1.12'
|
|
41
|
+
spec.add_dependency 'aws-sdk-cognitosync', '~> 1.6'
|
|
42
|
+
spec.add_dependency 'aws-sdk-ec2', '~> 1'
|
|
43
|
+
spec.add_dependency 'aws-sdk-s3', '~> 1'
|
|
44
|
+
spec.add_dependency 'aws-sdk-ses', '~> 1.6'
|
|
45
|
+
|
|
46
|
+
spec.add_dependency 'pry', '~> 0.10'
|
|
47
|
+
spec.add_dependency 'pry-byebug', '~> 3.4'
|
|
48
|
+
spec.add_dependency 'pry-doc', '~> 1.0.0'
|
|
49
|
+
|
|
50
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
51
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
52
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
53
|
+
end
|
data/doc/ca_create!.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
__*#ca_create!(username)*__
|
|
4
|
+
|
|
5
|
+
### Synopsys
|
|
6
|
+
|
|
7
|
+
> In order to create user on Cognito
|
|
8
|
+
> - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
|
|
9
|
+
>
|
|
10
|
+
> Also check this doc [admin-create-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-create-user.html) method
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
class UserExample
|
|
16
|
+
extend ::CognitoSyncService
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
attrs = {
|
|
20
|
+
{ email: 'useremail@example.com' },
|
|
21
|
+
{ phone_number: '+1111111111' }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
UserExample.ca_create!(attrs, attrs[:phone_number])
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
__Output__
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
{
|
|
31
|
+
"username"=>"fd99f027-bebf-4f43-abf9-24829f45107f",
|
|
32
|
+
"user_create_date"=>2019-07-26 16:27:14 +0300,
|
|
33
|
+
"user_last_modified_date"=>2019-07-26 16:27:14 +0300,
|
|
34
|
+
"enabled"=>true,
|
|
35
|
+
"user_status"=>"FORCE_CHANGE_PASSWORD",
|
|
36
|
+
"phone_number"=>"+3333333333"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
```
|
data/doc/ca_delete!.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
__*#ca_delete!(username)*__
|
|
4
|
+
|
|
5
|
+
### Synopsys
|
|
6
|
+
|
|
7
|
+
> Delete user from cognito pool.
|
|
8
|
+
>
|
|
9
|
+
> Also check this doc [admin-delete-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-delete-user.html) method
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
class UserExample
|
|
15
|
+
extend ::CognitoSyncService
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
UserExample.ca_delete!(username)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
__Output__
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
{}
|
|
25
|
+
```
|
data/doc/ca_disable!.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
__*#ca_disable!(username)*__
|
|
4
|
+
|
|
5
|
+
### Synopsys
|
|
6
|
+
|
|
7
|
+
> Disable user in cognito pool.
|
|
8
|
+
>
|
|
9
|
+
> Also check this doc [admin-disable-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-disable-user.html) method
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
class UserExample
|
|
15
|
+
extend ::CognitoSyncService
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
UserExample.ca_disable!(username)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
__Output__
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
{}
|
|
25
|
+
```
|
data/doc/ca_find!.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
__*#ca_find!(username)*__
|
|
4
|
+
|
|
5
|
+
### Synopsys
|
|
6
|
+
|
|
7
|
+
> In order to find user on Cognito pool
|
|
8
|
+
> - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
|
|
9
|
+
|
|
10
|
+
Cognito return data in format with __user_attributes__ key
|
|
11
|
+
# cognito-idp example
|
|
12
|
+
```
|
|
13
|
+
<struct Aws::CognitoIdentityProvider::Types::AdminGetUserResponse
|
|
14
|
+
username="98fa7330-a5bb-4aed-a89a-17eed002f238",
|
|
15
|
+
user_attributes= [
|
|
16
|
+
#<struct Aws::CognitoIdentityProvider::Types::AttributeType name="sub", value="98fa7330-a5bb-4aed-a89a-17eed002f238">,
|
|
17
|
+
#<struct Aws::CognitoIdentityProvider::Types::AttributeType name="phone_number", value="+3333333333">
|
|
18
|
+
],
|
|
19
|
+
user_create_date=2019-07-29 13:06:30 +0300,
|
|
20
|
+
user_last_modified_date=2019-07-29 13:06:30 +0300,
|
|
21
|
+
enabled=true,
|
|
22
|
+
user_status="FORCE_CHANGE_PASSWORD",
|
|
23
|
+
mfa_options=nil,
|
|
24
|
+
preferred_mfa_setting=nil,
|
|
25
|
+
user_mfa_setting_list=nil>
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
>
|
|
29
|
+
>
|
|
30
|
+
> Also check this doc [admin-get-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-get-user.html) method
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
class UserExample
|
|
36
|
+
extend CognitoSyncService
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
UserExample.ca_find!('+123456789')
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
__Output__
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
{
|
|
46
|
+
"enabled"=>true,
|
|
47
|
+
"phone_number"=>"+123456789",
|
|
48
|
+
"user_create_date"=>2019-07-26 15:48:06.130000114 +0300,
|
|
49
|
+
"user_status"=>"FORCE_CHANGE_PASSWORD",
|
|
50
|
+
"username"=>"dae4900d-0984-4ac0-9ab0-14505e52d50c"
|
|
51
|
+
}
|
|
52
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
## [WIP] Now used [hardcoded auth_flow](https://github.com/MarkOsipenko/cognito-sync-service/blob/master/lib/cognito-sync-service.rb#L53) inside __#ca_initiate_auth!__. We expect this method will be more flexible in future
|
|
4
|
+
|
|
5
|
+
__*#ca_initiate_auth!(username, password)*__
|
|
6
|
+
|
|
7
|
+
### Synopsys
|
|
8
|
+
|
|
9
|
+
> In order to perform the authentication flow, as an administrator on Cognito
|
|
10
|
+
> - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
|
|
11
|
+
>
|
|
12
|
+
> Also check this doc [admin-initiate-auth](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-initiate-auth.html) method
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
class UserExample
|
|
18
|
+
extend ::CognitoSyncService
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
result = UserExample.ca_initiate_auth!(username, password)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
__Output__
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
#<struct Aws::CognitoIdentityProvider::Types::AdminInitiateAuthResponse
|
|
28
|
+
challenge_name="NEW_PASSWORD_REQUIRED",
|
|
29
|
+
session="E_-IQ-PFywvo2Q0_od1LFrIc5VxsNuMVq_Idjwvry8wmmtwKri2my2VJwr7tu45jXucSwIG0SRzestDK13slda_fdRR_AkNLsBT9AMqKtm7avy6Dq0QRKOjBdnjsMEKn4bClX9LO",
|
|
30
|
+
challenge_parameters={"USER_ID_FOR_SRP"=>"bbd455ea-e07a-382d-a7b5-7f04ef8827aa", "requiredAttributes"=>"[]", "userAttributes"=>"{\"email\":\"qwe@qwe.com\"}"},
|
|
31
|
+
authentication_result=nil>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
__Note:__
|
|
35
|
+
|
|
36
|
+
> If you need to retreive values from ```result``` you can simply call it by its keys like:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
result.challenge_name #=> "NEW_PASSWORD_REQUIRED"
|
|
40
|
+
result.session #=> "E_-IQ-PFywvo2Q0_od1LFrIc5VxsNuMVq_Idjwvry8wmmtwKri2my2VJwr7tu45jXucSwIG0SRzestDK13slda_fdRR_AkNLsBT9AMqKtm7avy6Dq0QRKOjBdnjsMEKn4bClX9LO"
|
|
41
|
+
result.challenge_parameters #=> {"USER_ID_FOR_SRP"=>"bbd455ea-e07a-382d-a7b5-7f04ef8827aa", "requiredAttributes"=>"[]", "userAttributes"=>"{\"email\":\"qwe@qwe.com\"}"}
|
|
42
|
+
result.authentication_result #=> nil
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
>In this case ```authentication_result``` is ```nil``` because of particular auth flow when user account in Cognito has not been confirmed yet.
|
|
46
|
+
```authentication_result``` is only returned if the caller does not need to pass another challenge. If the caller does need to pass another challenge before it gets tokens, ChallengeName , ChallengeParameters , and Session are returned.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
## [WIP] Now used [hardcoded challenge_name](https://github.com/MarkOsipenko/cognito-sync-service/blob/master/lib/cognito-sync-service.rb#L66) inside __#ca_respond_to_auth_challenge!__. We expect this method will be more flexible in future
|
|
4
|
+
|
|
5
|
+
__*#ca_respond_to_auth_challenge!(username, password, session)*__
|
|
6
|
+
|
|
7
|
+
__Note:__
|
|
8
|
+
|
|
9
|
+
>The session is issued by calling #ca_initiate_auth! method.
|
|
10
|
+
|
|
11
|
+
### Synopsys
|
|
12
|
+
|
|
13
|
+
> In order to confirm account status by password, as an administrator on Cognito
|
|
14
|
+
> - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
|
|
15
|
+
>
|
|
16
|
+
> Also check this doc [admin-respond-to-auth-challenge](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-respond-to-auth-challenge.html) method
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
class UserExample
|
|
22
|
+
extend ::CognitoSyncService
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
result = UserExample.ca_respond_to_auth_challenge!(username, password, session)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
__Output__
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
=> #<struct Aws::CognitoIdentityProvider::Types::AdminRespondToAuthChallengeResponse
|
|
32
|
+
challenge_name=nil,
|
|
33
|
+
session=nil,
|
|
34
|
+
challenge_parameters={},
|
|
35
|
+
authentication_result=
|
|
36
|
+
#<struct Aws::CognitoIdentityProvider::Types::AuthenticationResultType
|
|
37
|
+
access_token=
|
|
38
|
+
"eyJraWQiOiJ3T0RTTmYyTXRheDJPM24lD2xMc1RoM1hoOXV6V3BBcEpubjdMMlwvMXo4bz0iLCJhbGciOiJSUzI1NiJ9cHgmlc6WWxXPw36GuQ91jiTisnvtJWus-XvOOcLK4qsQ",
|
|
39
|
+
expires_in=3600,
|
|
40
|
+
token_type="Bearer",
|
|
41
|
+
refresh_token=
|
|
42
|
+
"eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2-Dmc6dms9iukp_YUfeO6Vj-P9sOom_khf3FWTMz1Mb2dI8vjhvG_kK8Gu-5rw",
|
|
43
|
+
id_token=
|
|
44
|
+
"eyJraWQiOiJSejZRdXRPbXVlNk1vdEZpUm83M1lsTWJSZjc4Qxv4MUk0K29BeDhRNmxzPSIsImFsZyI6IlJTMjU2In0.hftrLf9--JjgZYAREDXYM8aJkLkeuXCSnM5fkOqYn8DQ",
|
|
45
|
+
new_device_metadata=nil>>
|
|
46
|
+
```
|
data/doc/ca_update!.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# CognitoSyncService
|
|
2
|
+
|
|
3
|
+
__*#ca_update!(username)*__
|
|
4
|
+
|
|
5
|
+
### Synopsys
|
|
6
|
+
|
|
7
|
+
> In order to update user on Cognito
|
|
8
|
+
> - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
|
|
9
|
+
>
|
|
10
|
+
> Also check this doc [admin-update-user-attributes](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-update-user-attributes.html) method
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
`Attention!!!`
|
|
15
|
+
changing username (alias for you login) not tested yet
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
class UserExample
|
|
19
|
+
extend ::CognitoSyncService
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
attrs = {
|
|
23
|
+
{ email: 'usernewemail@example.com' },
|
|
24
|
+
{ phone_number: '+1111111111' }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
UserExample.ca_update!(attrs, attrs[:phone_number])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
__Output__
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
{
|
|
34
|
+
"email"=>"example2@gmail.com",
|
|
35
|
+
"username"=>"01f29e86-f9ff-4b30-a8d6-977e07d07abb",
|
|
36
|
+
"user_create_date"=>2019-07-29 17:14:44 +0300,
|
|
37
|
+
"user_last_modified_date"=>2019-07-29 17:15:04 +0300,
|
|
38
|
+
"enabled"=>true,
|
|
39
|
+
"user_status"=>"FORCE_CHANGE_PASSWORD",
|
|
40
|
+
"phone_number"=>"+111111111"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cognito-sync-service/version'
|
|
4
|
+
require 'cognito_attributes_converter.rb'
|
|
5
|
+
# require 'cognito_pools_initializer.rb'
|
|
6
|
+
# require 'cognito_provider.rb'
|
|
7
|
+
|
|
8
|
+
module CognitoSyncService
|
|
9
|
+
include ::CognitoAttributesConverter
|
|
10
|
+
|
|
11
|
+
# username - can be email, phone_number or custom string depend on you cognito pool settings
|
|
12
|
+
# attrs - hash of user attributes which will be saved in cognito pool
|
|
13
|
+
# attrs = { email: 'qwe@qwe,com', phone_number: '+12......0'}
|
|
14
|
+
def ca_create!(attrs, username, temporary_password = nil)
|
|
15
|
+
user_attributes = {
|
|
16
|
+
user_pool_id: web_pool_id,
|
|
17
|
+
username: username,
|
|
18
|
+
user_attributes: convert_to_cognito(attrs),
|
|
19
|
+
temporary_password: temporary_password
|
|
20
|
+
}.compact
|
|
21
|
+
|
|
22
|
+
user = cognito_provider.admin_create_user(user_attributes).user
|
|
23
|
+
|
|
24
|
+
convert_from_cognito(user)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# user can be delete by email or phone_number depend on cognito pool settings
|
|
28
|
+
def ca_delete!(username)
|
|
29
|
+
cognito_provider.admin_delete_user(user_pool_id: web_pool_id, username: username)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# user can be find by email or phone_number depend on cognito pool settings
|
|
33
|
+
def ca_find!(username)
|
|
34
|
+
user = cognito_provider.admin_get_user(user_pool_id: web_pool_id, username: username)
|
|
35
|
+
convert_from_cognito(user)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# username - can be email, phone_number or custom string depend on cognito pool settings
|
|
39
|
+
# attrs - hash of user attributes which will be saved in cognito pool
|
|
40
|
+
# attrs = { email: 'qwe@qwe,com', phone_number: '+12......0'}
|
|
41
|
+
def ca_update!(attrs, username)
|
|
42
|
+
c_attributes = convert_to_cognito(attrs)
|
|
43
|
+
cognito_provider.admin_update_user_attributes(user_pool_id: web_pool_id, username: username, user_attributes: c_attributes)
|
|
44
|
+
ca_find!(username)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# user can be disable by email or phone_number depend on cognito pool settings
|
|
48
|
+
def ca_disable!(username)
|
|
49
|
+
cognito_provider.admin_disable_user(user_pool_id: web_pool_id, username: username)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# user can be authenticated by email or phone_number depend on cognito pool settings
|
|
53
|
+
# password can be constant or temporary
|
|
54
|
+
# "auth_flow" arg may differ depend on you authorization rules, we hardcode ADMIN_NO_SRP_AUTH like a common case
|
|
55
|
+
# In future this action be more flexible
|
|
56
|
+
# List of auth_flow args here - https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/initiate-auth.html
|
|
57
|
+
def ca_initiate_auth!(username, password)
|
|
58
|
+
cognito_provider.admin_initiate_auth(
|
|
59
|
+
user_pool_id: web_pool_id,
|
|
60
|
+
client_id: web_client_id,
|
|
61
|
+
auth_flow: 'ADMIN_NO_SRP_AUTH',
|
|
62
|
+
auth_parameters: {
|
|
63
|
+
USERNAME: username,
|
|
64
|
+
PASSWORD: password
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# for now this method works only for password confirmation flow
|
|
70
|
+
def ca_respond_to_auth_challenge!(username, password, session)
|
|
71
|
+
cognito_provider.admin_respond_to_auth_challenge(
|
|
72
|
+
user_pool_id: web_pool_id,
|
|
73
|
+
client_id: web_client_id,
|
|
74
|
+
challenge_name: 'NEW_PASSWORD_REQUIRED',
|
|
75
|
+
session: session,
|
|
76
|
+
challenge_responses: { USERNAME: username, NEW_PASSWORD: password }
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CognitoAttributesConverter
|
|
4
|
+
def convert_to_cognito(attrs)
|
|
5
|
+
cognito_attrs = attrs.map { |k, v| [k, v] }.to_h
|
|
6
|
+
|
|
7
|
+
cognito_attrs.map do |k, v|
|
|
8
|
+
{ name: cognito_key_name(k), value: v } if cognito_key?(k) && v
|
|
9
|
+
end.compact
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# name of attribute in cognito pool
|
|
13
|
+
def cognito_key_name(key)
|
|
14
|
+
return "custom:#{key}" if list_cognito_custom_attr_keys.include?(key.to_s)
|
|
15
|
+
|
|
16
|
+
key.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def convert_from_cognito(user_struct)
|
|
20
|
+
cognito_attrs = user_struct.to_h
|
|
21
|
+
|
|
22
|
+
user_attributes(cognito_attrs)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def user_attributes(cognito_attrs)
|
|
26
|
+
if cognito_attrs.key?(:user_attributes)
|
|
27
|
+
user_attrs = cognito_attrs.delete(:user_attributes)
|
|
28
|
+
common_attrs = cognito_attrs
|
|
29
|
+
elsif cognito_attrs.key?(:attributes)
|
|
30
|
+
user_attrs = cognito_attrs.delete(:attributes)
|
|
31
|
+
common_attrs = cognito_attrs
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
list_cognito_attr_keys.map do |key|
|
|
35
|
+
(user_attrs.find do |a|
|
|
36
|
+
common_attrs[key.to_s] = a[:value] if a[:name] == cognito_key_name(key)
|
|
37
|
+
end)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
Hash[common_attrs.map { |k, v| [k.to_s, v] }]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def cognito_key?(key)
|
|
44
|
+
list_cognito_attr_keys.include?(key.to_s)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def list_cognito_attr_keys
|
|
48
|
+
list_cognito_default_attr_keys + list_cognito_custom_attr_keys
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def list_cognito_default_attr_keys
|
|
52
|
+
cognito_default_attr_keys.map(&:to_s)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def list_cognito_custom_attr_keys
|
|
56
|
+
cognito_custom_attr_keys.map(&:to_s)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# redefine this methods in you model if you want to store special attributes
|
|
60
|
+
def cognito_default_attr_keys
|
|
61
|
+
%w[email phone_number]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# redefine this methods in you model if you want to store special custom attributes
|
|
65
|
+
def cognito_custom_attr_keys
|
|
66
|
+
%w[]
|
|
67
|
+
end
|
|
68
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cognito-sync-service
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mark Osipenko
|
|
@@ -185,7 +185,36 @@ email:
|
|
|
185
185
|
executables: []
|
|
186
186
|
extensions: []
|
|
187
187
|
extra_rdoc_files: []
|
|
188
|
-
files:
|
|
188
|
+
files:
|
|
189
|
+
- ".env.example"
|
|
190
|
+
- ".gitignore"
|
|
191
|
+
- ".rspec"
|
|
192
|
+
- ".rubocop.yml"
|
|
193
|
+
- ".travis.yml"
|
|
194
|
+
- CODE_OF_CONDUCT.md
|
|
195
|
+
- CONTRIBUTING.md
|
|
196
|
+
- DEVELOPMENT.md
|
|
197
|
+
- Gemfile
|
|
198
|
+
- Gemfile.lock
|
|
199
|
+
- LICENSE.txt
|
|
200
|
+
- README.md
|
|
201
|
+
- Rakefile
|
|
202
|
+
- bin/console
|
|
203
|
+
- bin/setup
|
|
204
|
+
- cognito-sync-service-0.2.0.gem
|
|
205
|
+
- cognito-sync-service-0.3.0.gem
|
|
206
|
+
- cognito-sync-service-0.3.1.gem
|
|
207
|
+
- cognito_sync_service.gemspec
|
|
208
|
+
- doc/ca_create!.md
|
|
209
|
+
- doc/ca_delete!.md
|
|
210
|
+
- doc/ca_disable!.md
|
|
211
|
+
- doc/ca_find!.md
|
|
212
|
+
- doc/ca_initiate_auth!.md
|
|
213
|
+
- doc/ca_respond_to_auth_challenge!.md
|
|
214
|
+
- doc/ca_update!.md
|
|
215
|
+
- lib/cognito-sync-service.rb
|
|
216
|
+
- lib/cognito-sync-service/version.rb
|
|
217
|
+
- lib/cognito_attributes_converter.rb
|
|
189
218
|
homepage: https://github.com/7DevsApps/cognito-sync-service
|
|
190
219
|
licenses:
|
|
191
220
|
- MIT
|
|
@@ -208,8 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
208
237
|
- !ruby/object:Gem::Version
|
|
209
238
|
version: '0'
|
|
210
239
|
requirements: []
|
|
211
|
-
|
|
212
|
-
rubygems_version: 2.7.6
|
|
240
|
+
rubygems_version: 3.0.4
|
|
213
241
|
signing_key:
|
|
214
242
|
specification_version: 4
|
|
215
243
|
summary: Aws Cognito user pool synchronizer
|