rodauth-oauth 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -424
  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/templates/app/views/rodauth/authorize.html.erb +3 -3
  28. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/device_search.html.erb +11 -0
  29. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/device_verification.html.erb +20 -0
  30. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/new_oauth_application.html.erb +22 -10
  31. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_application.html.erb +11 -5
  32. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_application_oauth_tokens.html.erb +38 -0
  33. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_applications.html.erb +5 -5
  34. data/lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_tokens.html.erb +11 -15
  35. data/lib/generators/rodauth/oauth/templates/db/migrate/create_rodauth_oauth.rb +9 -1
  36. data/lib/rodauth/features/oauth.rb +3 -1418
  37. data/lib/rodauth/features/oauth_application_management.rb +209 -0
  38. data/lib/rodauth/features/oauth_assertion_base.rb +96 -0
  39. data/lib/rodauth/features/oauth_authorization_code_grant.rb +249 -0
  40. data/lib/rodauth/features/oauth_authorization_server.rb +0 -0
  41. data/lib/rodauth/features/oauth_base.rb +735 -0
  42. data/lib/rodauth/features/oauth_device_grant.rb +221 -0
  43. data/lib/rodauth/features/oauth_http_mac.rb +3 -21
  44. data/lib/rodauth/features/oauth_implicit_grant.rb +59 -0
  45. data/lib/rodauth/features/oauth_jwt.rb +37 -60
  46. data/lib/rodauth/features/oauth_jwt_bearer_grant.rb +59 -0
  47. data/lib/rodauth/features/oauth_pkce.rb +98 -0
  48. data/lib/rodauth/features/oauth_resource_server.rb +21 -0
  49. data/lib/rodauth/features/oauth_saml_bearer_grant.rb +102 -0
  50. data/lib/rodauth/features/oauth_token_introspection.rb +108 -0
  51. data/lib/rodauth/features/oauth_token_management.rb +77 -0
  52. data/lib/rodauth/features/oauth_token_revocation.rb +109 -0
  53. data/lib/rodauth/features/oidc.rb +4 -3
  54. data/lib/rodauth/oauth/database_extensions.rb +15 -2
  55. data/lib/rodauth/oauth/refinements.rb +48 -0
  56. data/lib/rodauth/oauth/version.rb +1 -1
  57. data/locales/en.yml +28 -12
  58. data/templates/authorize.str +7 -7
  59. data/templates/client_secret_field.str +2 -2
  60. data/templates/description_field.str +1 -1
  61. data/templates/device_search.str +11 -0
  62. data/templates/device_verification.str +24 -0
  63. data/templates/homepage_url_field.str +2 -2
  64. data/templates/jws_jwk_field.str +4 -0
  65. data/templates/jwt_public_key_field.str +4 -0
  66. data/templates/name_field.str +1 -1
  67. data/templates/new_oauth_application.str +9 -0
  68. data/templates/oauth_application.str +7 -3
  69. data/templates/oauth_application_oauth_tokens.str +51 -0
  70. data/templates/oauth_applications.str +2 -2
  71. data/templates/oauth_tokens.str +9 -11
  72. data/templates/redirect_uri_field.str +2 -2
  73. metadata +71 -3
  74. 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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
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: 2022-01-14 00:00:00.000000000 Z
11
+ date: 2022-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rodauth
@@ -33,39 +33,107 @@ extra_rdoc_files:
33
33
  - LICENSE.txt
34
34
  - README.md
35
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
36
59
  files:
37
60
  - CHANGELOG.md
38
61
  - LICENSE.txt
39
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
40
86
  - lib/generators/rodauth/oauth/install_generator.rb
41
87
  - lib/generators/rodauth/oauth/templates/app/models/oauth_application.rb
42
88
  - lib/generators/rodauth/oauth/templates/app/models/oauth_grant.rb
43
89
  - lib/generators/rodauth/oauth/templates/app/models/oauth_token.rb
44
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
45
93
  - lib/generators/rodauth/oauth/templates/app/views/rodauth/new_oauth_application.html.erb
46
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
47
96
  - lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_applications.html.erb
48
97
  - lib/generators/rodauth/oauth/templates/app/views/rodauth/oauth_tokens.html.erb
49
98
  - lib/generators/rodauth/oauth/templates/db/migrate/create_rodauth_oauth.rb
50
99
  - lib/generators/rodauth/oauth/views_generator.rb
51
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
52
107
  - lib/rodauth/features/oauth_http_mac.rb
108
+ - lib/rodauth/features/oauth_implicit_grant.rb
53
109
  - lib/rodauth/features/oauth_jwt.rb
54
- - 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
55
117
  - lib/rodauth/features/oidc.rb
56
118
  - lib/rodauth/oauth.rb
57
119
  - lib/rodauth/oauth/database_extensions.rb
58
120
  - lib/rodauth/oauth/railtie.rb
121
+ - lib/rodauth/oauth/refinements.rb
59
122
  - lib/rodauth/oauth/ttl_store.rb
60
123
  - lib/rodauth/oauth/version.rb
61
124
  - locales/en.yml
62
125
  - templates/authorize.str
63
126
  - templates/client_secret_field.str
64
127
  - templates/description_field.str
128
+ - templates/device_search.str
129
+ - templates/device_verification.str
65
130
  - templates/homepage_url_field.str
131
+ - templates/jws_jwk_field.str
132
+ - templates/jwt_public_key_field.str
66
133
  - templates/name_field.str
67
134
  - templates/new_oauth_application.str
68
135
  - templates/oauth_application.str
136
+ - templates/oauth_application_oauth_tokens.str
69
137
  - templates/oauth_applications.str
70
138
  - templates/oauth_tokens.str
71
139
  - templates/redirect_uri_field.str
@@ -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