keycloak_rack 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +68 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +220 -0
  6. data/.ruby-version +1 -0
  7. data/.yardopts +7 -0
  8. data/Appraisals +16 -0
  9. data/CHANGELOG.md +10 -0
  10. data/CODE_OF_CONDUCT.md +132 -0
  11. data/Gemfile +5 -0
  12. data/LICENSE +19 -0
  13. data/README.md +288 -0
  14. data/Rakefile +10 -0
  15. data/bin/appraisal +29 -0
  16. data/bin/console +6 -0
  17. data/bin/fix-appraisals +14 -0
  18. data/bin/rake +29 -0
  19. data/bin/rspec +29 -0
  20. data/bin/rubocop +29 -0
  21. data/bin/yard +29 -0
  22. data/bin/yardoc +29 -0
  23. data/bin/yri +29 -0
  24. data/gemfiles/rack_only.gemfile +5 -0
  25. data/gemfiles/rack_only.gemfile.lock +204 -0
  26. data/gemfiles/rails_6_0.gemfile +9 -0
  27. data/gemfiles/rails_6_0.gemfile.lock +323 -0
  28. data/gemfiles/rails_6_1.gemfile +9 -0
  29. data/gemfiles/rails_6_1.gemfile.lock +326 -0
  30. data/keycloak_rack.gemspec +56 -0
  31. data/lib/keycloak_rack.rb +59 -0
  32. data/lib/keycloak_rack/authenticate.rb +115 -0
  33. data/lib/keycloak_rack/authorize_realm.rb +53 -0
  34. data/lib/keycloak_rack/authorize_resource.rb +54 -0
  35. data/lib/keycloak_rack/config.rb +84 -0
  36. data/lib/keycloak_rack/container.rb +53 -0
  37. data/lib/keycloak_rack/decoded_token.rb +191 -0
  38. data/lib/keycloak_rack/flexible_struct.rb +20 -0
  39. data/lib/keycloak_rack/http_client.rb +86 -0
  40. data/lib/keycloak_rack/import.rb +9 -0
  41. data/lib/keycloak_rack/key_fetcher.rb +20 -0
  42. data/lib/keycloak_rack/key_resolver.rb +64 -0
  43. data/lib/keycloak_rack/middleware.rb +132 -0
  44. data/lib/keycloak_rack/railtie.rb +14 -0
  45. data/lib/keycloak_rack/read_token.rb +40 -0
  46. data/lib/keycloak_rack/resource_role_map.rb +8 -0
  47. data/lib/keycloak_rack/role_map.rb +15 -0
  48. data/lib/keycloak_rack/session.rb +44 -0
  49. data/lib/keycloak_rack/skip_authentication.rb +44 -0
  50. data/lib/keycloak_rack/types.rb +42 -0
  51. data/lib/keycloak_rack/version.rb +6 -0
  52. data/lib/keycloak_rack/with_config.rb +15 -0
  53. data/spec/dummy/.ruby-version +1 -0
  54. data/spec/dummy/README.md +24 -0
  55. data/spec/dummy/Rakefile +8 -0
  56. data/spec/dummy/app/controllers/application_controller.rb +22 -0
  57. data/spec/dummy/app/controllers/test_controller.rb +9 -0
  58. data/spec/dummy/config.ru +8 -0
  59. data/spec/dummy/config/application.rb +52 -0
  60. data/spec/dummy/config/boot.rb +3 -0
  61. data/spec/dummy/config/environment.rb +7 -0
  62. data/spec/dummy/config/environments/development.rb +51 -0
  63. data/spec/dummy/config/environments/test.rb +51 -0
  64. data/spec/dummy/config/initializers/application_controller_renderer.rb +9 -0
  65. data/spec/dummy/config/initializers/backtrace_silencers.rb +10 -0
  66. data/spec/dummy/config/initializers/cors.rb +17 -0
  67. data/spec/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  68. data/spec/dummy/config/initializers/inflections.rb +17 -0
  69. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  70. data/spec/dummy/config/initializers/wrap_parameters.rb +11 -0
  71. data/spec/dummy/config/keycloak.yml +12 -0
  72. data/spec/dummy/config/locales/en.yml +33 -0
  73. data/spec/dummy/config/routes.rb +5 -0
  74. data/spec/dummy/public/robots.txt +1 -0
  75. data/spec/dummy/tmp/development_secret.txt +1 -0
  76. data/spec/factories/decoded_token.rb +18 -0
  77. data/spec/factories/session.rb +21 -0
  78. data/spec/factories/token_payload.rb +40 -0
  79. data/spec/keycloak_rack/authorize_realm_spec.rb +15 -0
  80. data/spec/keycloak_rack/authorize_resource_spec.rb +19 -0
  81. data/spec/keycloak_rack/decoded_token_spec.rb +31 -0
  82. data/spec/keycloak_rack/key_resolver_spec.rb +95 -0
  83. data/spec/keycloak_rack/middleware_spec.rb +172 -0
  84. data/spec/keycloak_rack/rails_integration_spec.rb +43 -0
  85. data/spec/keycloak_rack/session_spec.rb +37 -0
  86. data/spec/keycloak_rack/skip_authentication_spec.rb +55 -0
  87. data/spec/spec_helper.rb +101 -0
  88. data/spec/support/contexts/mocked_keycloak.rb +63 -0
  89. data/spec/support/contexts/mocked_rack_application.rb +41 -0
  90. data/spec/support/test_key.pem +27 -0
  91. data/spec/support/token_helper.rb +76 -0
  92. metadata +616 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e2461f59028ba873f75a0988c33c87c282c973607ee1699f4c4b0c02c49eded3
4
+ data.tar.gz: daf5ac5fe45f1c5f3a50cc3d8b5fb21d1b8c7be4a83f994fb5b2f13f8215723f
5
+ SHA512:
6
+ metadata.gz: 56ecde7179d9b918674f8d4554e36b22ddf1f88e0b92eaf497a79199435ee87c2b22aa4a00064df26a596473c054c91e4e0562a2636674e76ff41047100140f0
7
+ data.tar.gz: 3c2dd92e54f8004901a2b0a8b72a1cd5a3ee6f9f7c0fbb2cfb6f17a2b6e3ff89dcabee8383f2ad196006863064006fc1a2f4fe3dc30d0949c6c06c2e63a87862
@@ -0,0 +1,68 @@
1
+ name: "linting & testing"
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - "lib/**"
9
+ - "spec/**"
10
+ - ".github/workflows/main.yml"
11
+ pull_request:
12
+
13
+ jobs:
14
+ lint:
15
+ runs-on: ubuntu-latest
16
+ env:
17
+ APPRAISAL_NAME: rack_only
18
+ BUNDLE_GEMFILE: ./gemfiles/rack_only.gemfile
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: 2.7
24
+ - uses: actions/cache@v2
25
+ with:
26
+ path: vendor/bundle
27
+ key: bundle-use-ruby-ubuntu-latest-2.7-rack_only-${{ hashFiles(format('{0}.lock', env.BUNDLE_GEMFILE)) }}
28
+ restore-keys: |
29
+ bundle-use-ruby-ubuntu-latest-2.7-rack_only
30
+ - name: bundle install
31
+ run: |
32
+ gem update --system
33
+ bundle config deployment true
34
+ bundle config path vendor/bundle
35
+ bundle install --jobs 4
36
+ - name: "Run rubocop"
37
+ run: |
38
+ bin/rubocop
39
+ rspec:
40
+ runs-on: ubuntu-latest
41
+ strategy:
42
+ fail-fast: false
43
+ matrix:
44
+ appraisal_name: [rack_only, rails_6_0, rails_6_1]
45
+ ruby: [2.7, 3.0]
46
+ env:
47
+ APPRAISAL_NAME: ${{ matrix.appraisal_name }}
48
+ BUNDLE_GEMFILE: ${{ format('./gemfiles/{0}.gemfile', matrix.appraisal_name) }}
49
+ steps:
50
+ - uses: actions/checkout@v2
51
+ - uses: ruby/setup-ruby@v1
52
+ with:
53
+ ruby-version: ${{ matrix.ruby }}
54
+ - uses: actions/cache@v2
55
+ with:
56
+ path: vendor/bundle
57
+ key: bundle-use-ruby-ubuntu-latest-${{ matrix.ruby }}-${{ env.APPRAISAL_NAME }}-${{ hashFiles(format('{0}.lock', env.BUNDLE_GEMFILE)) }}
58
+ restore-keys: |
59
+ bundle-use-ruby-ubuntu-latest-${{ matrix.ruby }}-${{ env.APPRAISAL_NAME }}
60
+ - name: bundle install
61
+ run: |
62
+ gem update --system
63
+ bundle config deployment true
64
+ bundle config path vendor/bundle
65
+ bundle install --jobs 4
66
+ - name: "Run RSpec"
67
+ run: |
68
+ bin/rspec
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle
2
+ /coverage
3
+ /doc
4
+ /Gemfile.lock
5
+ /pkg
6
+ /spec/examples.txt
7
+ /.yardoc
8
+ /_yardoc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,220 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - Appraisals
8
+ - "bin/*"
9
+ - "gemfiles/**/*"
10
+ TargetRubyVersion: 2.7
11
+
12
+ Bundler/OrderedGems:
13
+ Enabled: false
14
+
15
+ Gemspec/DateAssignment:
16
+ Enabled: true
17
+
18
+ Layout/ArgumentAlignment:
19
+ Enabled: false
20
+
21
+ Layout/ExtraSpacing:
22
+ AllowForAlignment: true
23
+ AllowBeforeTrailingComments: true
24
+
25
+ Layout/HashAlignment:
26
+ Enabled: false
27
+
28
+ Layout/HeredocIndentation:
29
+ Enabled: false
30
+
31
+ Layout/SpaceAroundOperators:
32
+ AllowForAlignment: true
33
+
34
+ Layout/SpaceInsideArrayLiteralBrackets:
35
+ Enabled: false
36
+
37
+ Layout/LineLength:
38
+ Max: 160
39
+
40
+ Layout/SpaceBeforeBrackets:
41
+ Enabled: true
42
+
43
+ Lint/AmbiguousAssignment:
44
+ Enabled: true
45
+
46
+ Lint/DeprecatedConstants:
47
+ Enabled: true
48
+
49
+ Layout/DotPosition:
50
+ EnforcedStyle: trailing
51
+
52
+ Lint/DuplicateBranch:
53
+ Enabled: false
54
+
55
+ Lint/DuplicateRegexpCharacterClassElement:
56
+ Enabled: true
57
+
58
+ Lint/EmptyBlock:
59
+ Enabled: true
60
+
61
+ Lint/EmptyClass:
62
+ Enabled: true
63
+
64
+ Lint/LambdaWithoutLiteralBlock:
65
+ Enabled: true
66
+
67
+ Lint/NoReturnInBeginEndBlocks:
68
+ Enabled: true
69
+
70
+ Lint/NumberedParameterAssignment:
71
+ Enabled: true
72
+
73
+ Lint/OrAssignmentToConstant:
74
+ Enabled: true
75
+
76
+ Lint/RedundantDirGlobSort:
77
+ Enabled: true
78
+
79
+ Lint/SymbolConversion:
80
+ Enabled: true
81
+
82
+ Lint/ToEnumArguments:
83
+ Enabled: true
84
+
85
+ Lint/TripleQuotes:
86
+ Enabled: true
87
+
88
+ Lint/UnexpectedBlockArity:
89
+ Enabled: true
90
+
91
+ Lint/UnmodifiedReduceAccumulator:
92
+ Enabled: true
93
+
94
+ Lint/UnusedBlockArgument:
95
+ Enabled: false
96
+
97
+ Lint/UnusedMethodArgument:
98
+ Enabled: false
99
+
100
+ Metrics/AbcSize:
101
+ Max: 25
102
+
103
+ # This doesn't work with anything that uses a DSL
104
+ Metrics/BlockLength:
105
+ Enabled: false
106
+
107
+ Metrics/CyclomaticComplexity:
108
+ Max: 15
109
+
110
+ Metrics/MethodLength:
111
+ Max: 20
112
+
113
+ Naming/MethodName:
114
+ Enabled: false
115
+
116
+ Naming/PredicateName:
117
+ ForbiddenPrefixes:
118
+ - is_
119
+
120
+ RSpec/BeforeAfterAll:
121
+ Enabled: false
122
+
123
+ RSpec/DescribeClass:
124
+ Enabled: false
125
+
126
+ RSpec/DescribedClass:
127
+ Enabled: false
128
+
129
+ RSpec/LeadingSubject:
130
+ Enabled: false
131
+
132
+ RSpec/MultipleExpectations:
133
+ Enabled: false
134
+
135
+ RSpec/MultipleMemoizedHelpers:
136
+ Enabled: false
137
+
138
+ RSpec/NestedGroups:
139
+ Enabled: false
140
+
141
+ Style/ArgumentsForwarding:
142
+ Enabled: true
143
+
144
+ Style/ArrayJoin:
145
+ Enabled: false
146
+
147
+ Style/CaseEquality:
148
+ Enabled: false
149
+
150
+ Style/CharacterLiteral:
151
+ Enabled: false
152
+
153
+ Style/ClassCheck:
154
+ Enabled: false
155
+
156
+ Style/CollectionCompact:
157
+ Enabled: true
158
+
159
+ Style/DocumentDynamicEvalDefinition:
160
+ Enabled: true
161
+
162
+ Style/EndlessMethod:
163
+ Enabled: true
164
+
165
+ Style/HashConversion:
166
+ Enabled: true
167
+
168
+ Style/HashExcept:
169
+ Enabled: true
170
+
171
+ Style/IfWithBooleanLiteralBranches:
172
+ Enabled: true
173
+
174
+ Style/Lambda:
175
+ Enabled: false
176
+
177
+ Style/MultilineBlockChain:
178
+ Enabled: false
179
+
180
+ Style/NegatedIfElseCondition:
181
+ Enabled: true
182
+
183
+ Style/NilLambda:
184
+ Enabled: true
185
+
186
+ Style/RedundantArgument:
187
+ Enabled: true
188
+
189
+ Style/RedundantFetchBlock:
190
+ Enabled: false
191
+
192
+ Style/RedundantReturn:
193
+ Enabled: false
194
+
195
+ Style/StringChars:
196
+ Enabled: true
197
+
198
+ Style/StringLiterals:
199
+ Enabled: false
200
+
201
+ Style/SwapValues:
202
+ Enabled: true
203
+
204
+ Style/SymbolArray:
205
+ Enabled: false
206
+
207
+ Style/SymbolProc:
208
+ Enabled: false
209
+
210
+ Style/TrailingCommaInArguments:
211
+ Enabled: false
212
+
213
+ Style/TrailingCommaInArrayLiteral:
214
+ Enabled: false
215
+
216
+ Style/TrailingCommaInHashLiteral:
217
+ Enabled: false
218
+
219
+ Style/TrailingUnderscoreVariable:
220
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.1
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --embed-mixin KeycloakRack::WithConfig
2
+ --plugin junk
3
+ -m markdown -M redcarpet
4
+ lib/**/*.rb
5
+ -
6
+ README.md
7
+
data/Appraisals ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "rack_only" do
4
+ end
5
+
6
+ appraise "rails_6_0" do
7
+ gem "rails", ">= 6", "< 6.1.0"
8
+
9
+ gem "rspec-rails", "5.0.1"
10
+ end
11
+
12
+ appraise "rails_6_1" do
13
+ gem "rails", ">= 6.1.0", "< 6.2.0"
14
+
15
+ gem "rspec-rails", "5.0.1"
16
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2021-04-10
9
+
10
+ * Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
126
+ at [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations