rodauth-oauth 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -407
  3. data/README.md +26 -389
  4. data/doc/release_notes/0_0_1.md +3 -0
  5. data/doc/release_notes/0_0_2.md +15 -0
  6. data/doc/release_notes/0_0_3.md +31 -0
  7. data/doc/release_notes/0_0_4.md +36 -0
  8. data/doc/release_notes/0_0_5.md +36 -0
  9. data/doc/release_notes/0_0_6.md +21 -0
  10. data/doc/release_notes/0_1_0.md +44 -0
  11. data/doc/release_notes/0_2_0.md +43 -0
  12. data/doc/release_notes/0_3_0.md +28 -0
  13. data/doc/release_notes/0_4_0.md +18 -0
  14. data/doc/release_notes/0_4_1.md +9 -0
  15. data/doc/release_notes/0_4_2.md +5 -0
  16. data/doc/release_notes/0_4_3.md +3 -0
  17. data/doc/release_notes/0_5_0.md +11 -0
  18. data/doc/release_notes/0_5_1.md +13 -0
  19. data/doc/release_notes/0_6_0.md +9 -0
  20. data/doc/release_notes/0_6_1.md +6 -0
  21. data/doc/release_notes/0_7_0.md +20 -0
  22. data/doc/release_notes/0_7_1.md +10 -0
  23. data/doc/release_notes/0_7_2.md +21 -0
  24. data/doc/release_notes/0_7_3.md +10 -0
  25. data/doc/release_notes/0_7_4.md +5 -0
  26. data/doc/release_notes/0_8_0.md +37 -0
  27. data/lib/generators/rodauth/oauth/install_generator.rb +1 -1
  28. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/authorize.html.erb +29 -0
  29. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/device_search.html.erb +11 -0
  30. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/device_verification.html.erb +20 -0
  31. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/new_oauth_application.html.erb +50 -0
  32. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_application.html.erb +23 -0
  33. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_application_oauth_tokens.html.erb +38 -0
  34. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_applications.html.erb +29 -0
  35. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_tokens.html.erb +34 -0
  36. data/lib/generators/rodauth/oauth/templates/db/migrate/create_rodauth_oauth.rb +9 -1
  37. data/lib/generators/rodauth/oauth/views_generator.rb +9 -4
  38. data/lib/rodauth/features/oauth.rb +3 -1418
  39. data/lib/rodauth/features/oauth_application_management.rb +209 -0
  40. data/lib/rodauth/features/oauth_assertion_base.rb +96 -0
  41. data/lib/rodauth/features/oauth_authorization_code_grant.rb +249 -0
  42. data/lib/rodauth/features/oauth_authorization_server.rb +0 -0
  43. data/lib/rodauth/features/oauth_base.rb +735 -0
  44. data/lib/rodauth/features/oauth_device_grant.rb +221 -0
  45. data/lib/rodauth/features/oauth_http_mac.rb +3 -21
  46. data/lib/rodauth/features/oauth_implicit_grant.rb +59 -0
  47. data/lib/rodauth/features/oauth_jwt.rb +37 -60
  48. data/lib/rodauth/features/oauth_jwt_bearer_grant.rb +59 -0
  49. data/lib/rodauth/features/oauth_pkce.rb +98 -0
  50. data/lib/rodauth/features/oauth_resource_server.rb +21 -0
  51. data/lib/rodauth/features/oauth_saml_bearer_grant.rb +102 -0
  52. data/lib/rodauth/features/oauth_token_introspection.rb +108 -0
  53. data/lib/rodauth/features/oauth_token_management.rb +77 -0
  54. data/lib/rodauth/features/oauth_token_revocation.rb +109 -0
  55. data/lib/rodauth/features/oidc.rb +4 -3
  56. data/lib/rodauth/oauth/database_extensions.rb +15 -2
  57. data/lib/rodauth/oauth/refinements.rb +48 -0
  58. data/lib/rodauth/oauth/version.rb +1 -1
  59. data/locales/en.yml +28 -12
  60. data/templates/authorize.str +7 -7
  61. data/templates/client_secret_field.str +2 -2
  62. data/templates/description_field.str +1 -1
  63. data/templates/device_search.str +11 -0
  64. data/templates/device_verification.str +24 -0
  65. data/templates/homepage_url_field.str +2 -2
  66. data/templates/jws_jwk_field.str +4 -0
  67. data/templates/jwt_public_key_field.str +4 -0
  68. data/templates/name_field.str +1 -1
  69. data/templates/new_oauth_application.str +9 -0
  70. data/templates/oauth_application.str +7 -3
  71. data/templates/oauth_application_oauth_tokens.str +51 -0
  72. data/templates/oauth_applications.str +2 -2
  73. data/templates/oauth_tokens.str +9 -11
  74. data/templates/redirect_uri_field.str +2 -2
  75. metadata +97 -7
  76. data/lib/rodauth/features/oauth_saml.rb +0 -104
@@ -1,4 +1,4 @@
1
1
  <div class="form-group">
2
- <label for="homepage_url">#{rodauth.homepage_url_label}#{rodauth.input_field_label_suffix}</label>
3
- #{rodauth.input_field_string(rodauth.oauth_application_homepage_url_param, "homepage_url", :type=>"text")}
2
+ <label for="homepage_url">#{rodauth.oauth_applications_homepage_url_label}#{rodauth.input_field_label_suffix}</label>
3
+ #{rodauth.input_field_string(rodauth.oauth_application_homepage_url_param, "homepage-url", :type=>"text")}
4
4
  </div>
@@ -0,0 +1,4 @@
1
+ <div class="form-group">
2
+ <label for="name">#{rodauth.oauth_applications_jws_jwk_label}#{rodauth.input_field_label_suffix}</label>
3
+ #{rodauth.input_field_string(rodauth.oauth_application_jws_jwk_param, "jws_jwk", :type=>"text")}
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div class="form-group">
2
+ <label for="name">#{rodauth.oauth_applications_jwt_public_key_label}#{rodauth.input_field_label_suffix}</label>
3
+ #{rodauth.input_field_string(rodauth.oauth_application_jwt_public_key_param, "jwt_public_key", :type=>"text")}
4
+ </div>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group">
2
- <label for="name">#{rodauth.name_label}#{rodauth.input_field_label_suffix}</label>
2
+ <label for="name">#{rodauth.oauth_applications_name_label}#{rodauth.input_field_label_suffix}</label>
3
3
  #{rodauth.input_field_string(rodauth.oauth_application_name_param, "name", :type=>"text")}
4
4
  </div>
@@ -1,3 +1,4 @@
1
+ <h2>#{rodauth.new_oauth_application_page_title}</h2>
1
2
  <form method="post" action="#{rodauth.oauth_applications_path}" class="rodauth" role="form" id="oauth-application-form">
2
3
  #{rodauth.csrf_tag}
3
4
  #{rodauth.render('name_field')}
@@ -6,5 +7,13 @@
6
7
  #{rodauth.render('redirect_uri_field')}
7
8
  #{rodauth.render('client_secret_field')}
8
9
  #{rodauth.render('scope_field')}
10
+ #{
11
+ if rodauth.features.include?(:oauth_jwt)
12
+ <<-HTML
13
+ #{rodauth.render('jwt_public_key_field')}
14
+ #{rodauth.render('jws_jwk_field')}
15
+ HTML
16
+ end
17
+ }
9
18
  #{rodauth.button(rodauth.oauth_application_button)}
10
19
  </form>
@@ -1,11 +1,15 @@
1
1
  <div id="oauth-application">
2
2
  <dl>
3
3
  #{
4
- (rodauth.oauth_application_required_params + %w[client_id] - %w[client_secret]).map do |param|
5
- "<dt class=\"#{param}\">#{rodauth.send(:"#{param}_label")}</dt>" +
4
+ params = [*rodauth.oauth_application_required_params, "client_id", "client_secret"]
5
+ if rodauth.features.include?(:oauth_jwt)
6
+ params += %w[jws_jwk jwt_public_key]
7
+ end
8
+ params.map do |param|
9
+ "<dt class=\"#{param}\">#{rodauth.send(:"oauth_applications_#{param}_label")}: </dt>" +
6
10
  "<dd class=\"#{param}\">#{@oauth_application[rodauth.send(:"oauth_applications_#{param}_column")]}</dd>"
7
11
  end.join
8
12
  }
9
13
  </dl>
10
- <a href="#{rodauth.oauth_applications_path}/#{@oauth_application[:id]}/#{rodauth.oauth_tokens_path}" class="btn btn-outline-secondary">Oauth Tokens</a>
14
+ <a href="#{rodauth.oauth_applications_path}/#{@oauth_application[rodauth.oauth_applications_id_column]}/#{rodauth.oauth_applications_oauth_tokens_path}" class="btn btn-outline-secondary">#{rodauth.oauth_application_oauth_tokens_page_title}</a>
11
15
  </div>
@@ -0,0 +1,51 @@
1
+ <div id="oauth-tokens">
2
+ #{
3
+ if @oauth_tokens.count.zero?
4
+ "<p>No oauth tokens yet!</p>"
5
+ else
6
+ <<-HTML
7
+ <table class="table">
8
+ <thead>
9
+ <tr>
10
+ <th scope="col">#{rodauth.oauth_tokens_token_label}</th>
11
+ <th scope="col">#{rodauth.oauth_tokens_refresh_token_label}</th>
12
+ <th scope="col">#{rodauth.oauth_tokens_expires_in_label}</th>
13
+ <th scope="col">#{rodauth.oauth_tokens_revoked_at_label}</th>
14
+ <th scope="col">#{rodauth.oauth_tokens_scopes_label}</th>
15
+ <th scope="col"><span class="badge badge-pill badge-dark">#{@oauth_tokens.count}</span>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ #{
20
+ @oauth_tokens.map do |oauth_token|
21
+ <<-HTML
22
+ <tr>
23
+ <td><code class="token">#{oauth_token[rodauth.oauth_tokens_token_column]}</code></td>
24
+ <td><code class="token">#{oauth_token[rodauth.oauth_tokens_refresh_token_column]}</code></td>
25
+ <td>#{oauth_token[rodauth.oauth_tokens_expires_in_column]}</td>
26
+ <td>#{oauth_token[rodauth.oauth_tokens_revoked_at_column]}</td>
27
+ <td>#{oauth_token[rodauth.oauth_tokens_scopes_column]}</td>
28
+ <td>
29
+ #{
30
+ if !oauth_token[rodauth.oauth_tokens_revoked_at_column] && !oauth_token[rodauth.oauth_tokens_token_hash_column]
31
+ <<-HTML
32
+ <form method="post" action="#{rodauth.revoke_path}" class="form-horizontal" role="form" id="revoke-form">
33
+ #{csrf_tag(rodauth.revoke_path) if respond_to?(:csrf_tag)}
34
+ #{rodauth.input_field_string("token_type_hint", "revoke-token-type-hint", :value => "access_token", :type=>"hidden")}
35
+ #{rodauth.input_field_string("token", "revoke-token", :value => oauth_token[rodauth.oauth_tokens_token_column], :type=>"hidden")}
36
+ #{rodauth.button(rodauth.oauth_token_revoke_button)}
37
+ </form>
38
+ HTML
39
+ end
40
+ }
41
+ </td>
42
+ </tr>
43
+ HTML
44
+ end.join
45
+ }
46
+ </tbody>
47
+ </table>
48
+ HTML
49
+ end
50
+ }
51
+ </div>
@@ -1,10 +1,10 @@
1
1
  <div id="oauth-applications">
2
- <a class="btn btn-outline-primary" href="/oauth-applications/new">Register new Oauth Application</a>
2
+ <a class="btn btn-outline-primary" href="/oauth-applications/new">#{rodauth.new_oauth_application_page_title}</a>
3
3
  #{
4
4
  if @oauth_applications.count.zero?
5
5
  "<p>No oauth applications yet!</p>"
6
6
  else
7
- "<ul class=\"list-group\">" +
7
+ "<ul class=\"list-group\">" +
8
8
  @oauth_applications.map do |application|
9
9
  "<li class=\"list-group-item\"><a href=\"/oauth-applications/#{application[:id]}\">#{application[:name]}</a></li>"
10
10
  end.join +
@@ -7,11 +7,11 @@
7
7
  <table class="table">
8
8
  <thead>
9
9
  <tr>
10
- <th scope="col">Token</th>
11
- <th scope="col">Refresh Token</th>
12
- <th scope="col">Expires in</th>
13
- <th scope="col">Revoked at</th>
14
- <th scope="col">Scopes</th>
10
+ <th scope="col">#{rodauth.oauth_applications_name_label}</th>
11
+ <th scope="col">#{rodauth.oauth_tokens_token_label}</th>
12
+ <th scope="col">#{rodauth.oauth_tokens_refresh_token_label}</th>
13
+ <th scope="col">#{rodauth.oauth_tokens_expires_in_label}</th>
14
+ <th scope="col">#{rodauth.oauth_tokens_scopes_label}</th>
15
15
  <th scope="col"><span class="badge badge-pill badge-dark">#{@oauth_tokens.count}</span>
16
16
  </tr>
17
17
  </thead>
@@ -20,19 +20,17 @@
20
20
  @oauth_tokens.map do |oauth_token|
21
21
  <<-HTML
22
22
  <tr>
23
+ <td>#{oauth_token[rodauth.oauth_applications_name_column]}</td>
23
24
  <td><code class="token">#{oauth_token[rodauth.oauth_tokens_token_column]}</code></td>
24
25
  <td><code class="token">#{oauth_token[rodauth.oauth_tokens_refresh_token_column]}</code></td>
25
26
  <td>#{oauth_token[rodauth.oauth_tokens_expires_in_column]}</td>
26
- <td>#{oauth_token[rodauth.oauth_tokens_revoked_at_column]}</td>
27
27
  <td>#{oauth_token[rodauth.oauth_tokens_scopes_column]}</td>
28
28
  <td>
29
29
  #{
30
- if !oauth_token[rodauth.oauth_tokens_revoked_at_column] && !oauth_token[rodauth.oauth_tokens_token_hash_column]
30
+ if !oauth_token[rodauth.oauth_tokens_token_hash_column]
31
31
  <<-HTML
32
- <form method="post" action="#{rodauth.revoke_path}" class="form-horizontal" role="form" id="revoke-form">
33
- #{csrf_tag(rodauth.revoke_path) if respond_to?(:csrf_tag)}
34
- #{rodauth.input_field_string("token_type_hint", "revoke-token-type-hint", :value => "access_token", :type=>"hidden")}
35
- #{rodauth.input_field_string("token", "revoke-token", :value => oauth_token[rodauth.oauth_tokens_token_column], :type=>"hidden")}
32
+ <form method="post" action="#{rodauth.oauth_token_path(oauth_token[rodauth.oauth_tokens_id_column])}" class="form-horizontal" role="form" id="token-revoke-form">
33
+ #{csrf_tag(rodauth.oauth_token_path(oauth_token[rodauth.oauth_tokens_id_column])) if respond_to?(:csrf_tag)}
36
34
  #{rodauth.button(rodauth.oauth_token_revoke_button)}
37
35
  </form>
38
36
  HTML
@@ -1,4 +1,4 @@
1
1
  <div class="form-group">
2
- <label for="redirect_uri">#{rodauth.redirect_uri_label}#{rodauth.input_field_label_suffix}</label>
3
- #{rodauth.input_field_string(rodauth.oauth_application_redirect_uri_param, "redirect_uri", :type=>"text")}
2
+ <label for="redirect_uri">#{rodauth.oauth_applications_redirect_uri_label}#{rodauth.input_field_label_suffix}</label>
3
+ #{rodauth.input_field_string(rodauth.oauth_application_redirect_uri_param, "redirect-uri", :type=>"text")}
4
4
  </div>
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-14 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rodauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
13
27
  description: Implementation of the OAuth 2.0 protocol on top of rodauth.
14
28
  email:
15
29
  - cardoso_tiago@hotmail.com
@@ -19,45 +33,121 @@ extra_rdoc_files:
19
33
  - LICENSE.txt
20
34
  - README.md
21
35
  - CHANGELOG.md
36
+ - doc/release_notes/0_0_1.md
37
+ - doc/release_notes/0_0_2.md
38
+ - doc/release_notes/0_0_3.md
39
+ - doc/release_notes/0_0_4.md
40
+ - doc/release_notes/0_0_5.md
41
+ - doc/release_notes/0_0_6.md
42
+ - doc/release_notes/0_1_0.md
43
+ - doc/release_notes/0_2_0.md
44
+ - doc/release_notes/0_3_0.md
45
+ - doc/release_notes/0_4_0.md
46
+ - doc/release_notes/0_4_1.md
47
+ - doc/release_notes/0_4_2.md
48
+ - doc/release_notes/0_4_3.md
49
+ - doc/release_notes/0_5_0.md
50
+ - doc/release_notes/0_5_1.md
51
+ - doc/release_notes/0_6_0.md
52
+ - doc/release_notes/0_6_1.md
53
+ - doc/release_notes/0_7_0.md
54
+ - doc/release_notes/0_7_1.md
55
+ - doc/release_notes/0_7_2.md
56
+ - doc/release_notes/0_7_3.md
57
+ - doc/release_notes/0_7_4.md
58
+ - doc/release_notes/0_8_0.md
22
59
  files:
23
60
  - CHANGELOG.md
24
61
  - LICENSE.txt
25
62
  - README.md
63
+ - doc/release_notes/0_0_1.md
64
+ - doc/release_notes/0_0_2.md
65
+ - doc/release_notes/0_0_3.md
66
+ - doc/release_notes/0_0_4.md
67
+ - doc/release_notes/0_0_5.md
68
+ - doc/release_notes/0_0_6.md
69
+ - doc/release_notes/0_1_0.md
70
+ - doc/release_notes/0_2_0.md
71
+ - doc/release_notes/0_3_0.md
72
+ - doc/release_notes/0_4_0.md
73
+ - doc/release_notes/0_4_1.md
74
+ - doc/release_notes/0_4_2.md
75
+ - doc/release_notes/0_4_3.md
76
+ - doc/release_notes/0_5_0.md
77
+ - doc/release_notes/0_5_1.md
78
+ - doc/release_notes/0_6_0.md
79
+ - doc/release_notes/0_6_1.md
80
+ - doc/release_notes/0_7_0.md
81
+ - doc/release_notes/0_7_1.md
82
+ - doc/release_notes/0_7_2.md
83
+ - doc/release_notes/0_7_3.md
84
+ - doc/release_notes/0_7_4.md
85
+ - doc/release_notes/0_8_0.md
26
86
  - lib/generators/rodauth/oauth/install_generator.rb
27
87
  - lib/generators/rodauth/oauth/templates/app/models/oauth_application.rb
28
88
  - lib/generators/rodauth/oauth/templates/app/models/oauth_grant.rb
29
89
  - lib/generators/rodauth/oauth/templates/app/models/oauth_token.rb
90
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/authorize.html.erb
91
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/device_search.html.erb
92
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/device_verification.html.erb
93
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/new_oauth_application.html.erb
94
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_application.html.erb
95
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_application_oauth_tokens.html.erb
96
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_applications.html.erb
97
+ - lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_tokens.html.erb
30
98
  - lib/generators/rodauth/oauth/templates/db/migrate/create_rodauth_oauth.rb
31
99
  - lib/generators/rodauth/oauth/views_generator.rb
32
100
  - lib/rodauth/features/oauth.rb
101
+ - lib/rodauth/features/oauth_application_management.rb
102
+ - lib/rodauth/features/oauth_assertion_base.rb
103
+ - lib/rodauth/features/oauth_authorization_code_grant.rb
104
+ - lib/rodauth/features/oauth_authorization_server.rb
105
+ - lib/rodauth/features/oauth_base.rb
106
+ - lib/rodauth/features/oauth_device_grant.rb
33
107
  - lib/rodauth/features/oauth_http_mac.rb
108
+ - lib/rodauth/features/oauth_implicit_grant.rb
34
109
  - lib/rodauth/features/oauth_jwt.rb
35
- - lib/rodauth/features/oauth_saml.rb
110
+ - lib/rodauth/features/oauth_jwt_bearer_grant.rb
111
+ - lib/rodauth/features/oauth_pkce.rb
112
+ - lib/rodauth/features/oauth_resource_server.rb
113
+ - lib/rodauth/features/oauth_saml_bearer_grant.rb
114
+ - lib/rodauth/features/oauth_token_introspection.rb
115
+ - lib/rodauth/features/oauth_token_management.rb
116
+ - lib/rodauth/features/oauth_token_revocation.rb
36
117
  - lib/rodauth/features/oidc.rb
37
118
  - lib/rodauth/oauth.rb
38
119
  - lib/rodauth/oauth/database_extensions.rb
39
120
  - lib/rodauth/oauth/railtie.rb
121
+ - lib/rodauth/oauth/refinements.rb
40
122
  - lib/rodauth/oauth/ttl_store.rb
41
123
  - lib/rodauth/oauth/version.rb
42
124
  - locales/en.yml
43
125
  - templates/authorize.str
44
126
  - templates/client_secret_field.str
45
127
  - templates/description_field.str
128
+ - templates/device_search.str
129
+ - templates/device_verification.str
46
130
  - templates/homepage_url_field.str
131
+ - templates/jws_jwk_field.str
132
+ - templates/jwt_public_key_field.str
47
133
  - templates/name_field.str
48
134
  - templates/new_oauth_application.str
49
135
  - templates/oauth_application.str
136
+ - templates/oauth_application_oauth_tokens.str
50
137
  - templates/oauth_applications.str
51
138
  - templates/oauth_tokens.str
52
139
  - templates/redirect_uri_field.str
53
140
  - templates/scope_field.str
54
141
  homepage: https://gitlab.com/honeyryderchuck/rodauth-oauth
55
142
  licenses:
56
- - Apache 2.0
143
+ - Apache-2.0
57
144
  metadata:
58
- homepage_uri: https://gitlab.com/honeyryderchuck/rodauth-oauth
145
+ homepage_uri: https://honeyryderchuck.gitlab.io/rodauth-oauth/
146
+ documentation_uri: https://honeyryderchuck.gitlab.io/rodauth-oauth/rdoc/
147
+ bug_tracker_uri: https://gitlab.com/honeyryderchuck/rodauth-oauth/issues
59
148
  source_code_uri: https://gitlab.com/honeyryderchuck/rodauth-oauth
60
149
  changelog_uri: https://gitlab.com/honeyryderchuck/rodauth-oauth/-/blob/master/CHANGELOG.md
150
+ rubygems_mfa_required: 'true'
61
151
  post_install_message:
62
152
  rdoc_options: []
63
153
  require_paths:
@@ -73,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
163
  - !ruby/object:Gem::Version
74
164
  version: '0'
75
165
  requirements: []
76
- rubygems_version: 3.2.22
166
+ rubygems_version: 3.2.32
77
167
  signing_key:
78
168
  specification_version: 4
79
169
  summary: Implementation of the OAuth 2.0 protocol on top of rodauth.
@@ -1,104 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- require "onelogin/ruby-saml"
4
-
5
- module Rodauth
6
- Feature.define(:oauth_saml, :OauthSaml) do
7
- depends :oauth
8
-
9
- auth_value_method :oauth_saml_cert_fingerprint, "9E:65:2E:03:06:8D:80:F2:86:C7:6C:77:A1:D9:14:97:0A:4D:F4:4D"
10
- auth_value_method :oauth_saml_cert_fingerprint_algorithm, nil
11
- auth_value_method :oauth_saml_name_identifier_format, "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
12
-
13
- auth_value_method :oauth_saml_security_authn_requests_signed, false
14
- auth_value_method :oauth_saml_security_metadata_signed, false
15
- auth_value_method :oauth_saml_security_digest_method, XMLSecurity::Document::SHA1
16
- auth_value_method :oauth_saml_security_signature_method, XMLSecurity::Document::RSA_SHA1
17
-
18
- SAML_GRANT_TYPE = "http://oauth.net/grant_type/assertion/saml/2.0/bearer"
19
-
20
- # /token
21
-
22
- def require_oauth_application
23
- # requset authentication optional for assertions
24
- return super unless param("grant_type") == SAML_GRANT_TYPE && !param_or_nil("client_id")
25
-
26
- # TODO: invalid grant
27
- authorization_required unless saml_assertion
28
-
29
- redirect_uri = saml_assertion.destination
30
-
31
- @oauth_application = db[oauth_applications_table].where(
32
- oauth_applications_homepage_url_column => saml_assertion.audiences,
33
- oauth_applications_redirect_uri_column => redirect_uri
34
- ).first
35
-
36
- # The Assertion's <Issuer> element MUST contain a unique identifier
37
- # for the entity that issued the Assertion.
38
- authorization_required unless saml_assertion.issuers.all? do |issuer|
39
- issuer.start_with?(@oauth_application[oauth_applications_homepage_url_column])
40
- end
41
-
42
- authorization_required unless @oauth_application
43
- end
44
-
45
- private
46
-
47
- def secret_matches?(oauth_application, secret)
48
- return super unless param_or_nil("assertion")
49
-
50
- true
51
- end
52
-
53
- def saml_assertion
54
- return @saml_assertion if defined?(@saml_assertion)
55
-
56
- @saml_assertion = begin
57
- settings = OneLogin::RubySaml::Settings.new
58
- settings.idp_cert_fingerprint = oauth_saml_cert_fingerprint
59
- settings.idp_cert_fingerprint_algorithm = oauth_saml_cert_fingerprint_algorithm
60
- settings.name_identifier_format = oauth_saml_name_identifier_format
61
- settings.security[:authn_requests_signed] = oauth_saml_security_authn_requests_signed
62
- settings.security[:metadata_signed] = oauth_saml_security_metadata_signed
63
- settings.security[:digest_method] = oauth_saml_security_digest_method
64
- settings.security[:signature_method] = oauth_saml_security_signature_method
65
-
66
- response = OneLogin::RubySaml::Response.new(param("assertion"), settings: settings, skip_recipient_check: true)
67
-
68
- return unless response.is_valid?
69
-
70
- response
71
- end
72
- end
73
-
74
- def validate_oauth_token_params
75
- return super unless param("grant_type") == SAML_GRANT_TYPE
76
-
77
- redirect_response_error("invalid_client") unless param_or_nil("assertion")
78
-
79
- redirect_response_error("invalid_scope") unless check_valid_scopes?
80
- end
81
-
82
- def create_oauth_token
83
- if param("grant_type") == SAML_GRANT_TYPE
84
- create_oauth_token_from_saml_assertion
85
- else
86
- super
87
- end
88
- end
89
-
90
- def create_oauth_token_from_saml_assertion
91
- account = db[accounts_table].where(login_column => saml_assertion.nameid).first
92
-
93
- redirect_response_error("invalid_client") unless oauth_application && account
94
-
95
- create_params = {
96
- oauth_tokens_account_id_column => account[account_id_column],
97
- oauth_tokens_oauth_application_id_column => oauth_application[oauth_applications_id_column],
98
- oauth_tokens_scopes_column => (param_or_nil("scope") || oauth_application[oauth_applications_scopes_column])
99
- }
100
-
101
- generate_oauth_token(create_params, false)
102
- end
103
- end
104
- end