oxd-ruby 0.1.3

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.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +116 -0
  9. data/Rakefile +7 -0
  10. data/demosite/.gitignore +17 -0
  11. data/demosite/Gemfile +49 -0
  12. data/demosite/Gemfile.lock +190 -0
  13. data/demosite/README.md +172 -0
  14. data/demosite/Rakefile +6 -0
  15. data/demosite/app/assets/images/.keep +0 -0
  16. data/demosite/app/assets/javascripts/application.js +17 -0
  17. data/demosite/app/assets/javascripts/bootstrap.js.coffee +3 -0
  18. data/demosite/app/assets/stylesheets/application.css +16 -0
  19. data/demosite/app/assets/stylesheets/bootstrap_and_overrides.css +7 -0
  20. data/demosite/app/controllers/application_controller.rb +14 -0
  21. data/demosite/app/controllers/concerns/.keep +0 -0
  22. data/demosite/app/controllers/home_controller.rb +38 -0
  23. data/demosite/app/helpers/application_helper.rb +2 -0
  24. data/demosite/app/mailers/.keep +0 -0
  25. data/demosite/app/models/.keep +0 -0
  26. data/demosite/app/models/concerns/.keep +0 -0
  27. data/demosite/app/views/home/index.html.erb +127 -0
  28. data/demosite/app/views/layouts/application.html.erb +14 -0
  29. data/demosite/bin/bundle +3 -0
  30. data/demosite/bin/rails +9 -0
  31. data/demosite/bin/rake +9 -0
  32. data/demosite/bin/setup +29 -0
  33. data/demosite/bin/spring +15 -0
  34. data/demosite/config.ru +4 -0
  35. data/demosite/config/application.rb +26 -0
  36. data/demosite/config/boot.rb +3 -0
  37. data/demosite/config/database.yml +25 -0
  38. data/demosite/config/environment.rb +5 -0
  39. data/demosite/config/environments/development.rb +41 -0
  40. data/demosite/config/environments/production.rb +79 -0
  41. data/demosite/config/environments/test.rb +42 -0
  42. data/demosite/config/initializers/assets.rb +11 -0
  43. data/demosite/config/initializers/backtrace_silencers.rb +7 -0
  44. data/demosite/config/initializers/cookies_serializer.rb +3 -0
  45. data/demosite/config/initializers/filter_parameter_logging.rb +4 -0
  46. data/demosite/config/initializers/inflections.rb +16 -0
  47. data/demosite/config/initializers/mime_types.rb +4 -0
  48. data/demosite/config/initializers/oxd_config.rb +19 -0
  49. data/demosite/config/initializers/session_store.rb +3 -0
  50. data/demosite/config/initializers/wrap_parameters.rb +14 -0
  51. data/demosite/config/locales/en.bootstrap.yml +23 -0
  52. data/demosite/config/locales/en.yml +23 -0
  53. data/demosite/config/routes.rb +62 -0
  54. data/demosite/config/secrets.yml +22 -0
  55. data/demosite/db/seeds.rb +7 -0
  56. data/demosite/lib/assets/.keep +0 -0
  57. data/demosite/lib/tasks/.keep +0 -0
  58. data/demosite/log/.keep +0 -0
  59. data/demosite/public/404.html +67 -0
  60. data/demosite/public/422.html +67 -0
  61. data/demosite/public/500.html +66 -0
  62. data/demosite/public/favicon.ico +0 -0
  63. data/demosite/public/robots.txt +5 -0
  64. data/demosite/test/controllers/.keep +0 -0
  65. data/demosite/test/fixtures/.keep +0 -0
  66. data/demosite/test/helpers/.keep +0 -0
  67. data/demosite/test/integration/.keep +0 -0
  68. data/demosite/test/mailers/.keep +0 -0
  69. data/demosite/test/models/.keep +0 -0
  70. data/demosite/test/test_helper.rb +10 -0
  71. data/demosite/vendor/assets/javascripts/.keep +0 -0
  72. data/demosite/vendor/assets/stylesheets/.keep +0 -0
  73. data/lib/generators/oxd/config_generator.rb +22 -0
  74. data/lib/generators/oxd/templates/oxd_config.rb +19 -0
  75. data/lib/oxd-ruby.rb +11 -0
  76. data/lib/oxd/client_oxd_commands.rb +147 -0
  77. data/lib/oxd/config.rb +94 -0
  78. data/lib/oxd/oxd_connector.rb +133 -0
  79. data/lib/oxd/version.rb +4 -0
  80. data/oxd-ruby.gemspec +24 -0
  81. metadata +180 -0
@@ -0,0 +1,62 @@
1
+ Rails.application.routes.draw do
2
+
3
+ root 'home#index'
4
+ get '/register_site' => 'home#register_site'
5
+ get '/login' => 'home#login'
6
+ get '/logout' => 'home#logout'
7
+
8
+ # The priority is based upon order of creation: first created -> highest priority.
9
+ # See how all your routes lay out with "rake routes".
10
+
11
+ # You can have the root of your site routed with "root"
12
+ # root 'welcome#index'
13
+
14
+ # Example of regular route:
15
+ # get 'products/:id' => 'catalog#view'
16
+
17
+ # Example of named route that can be invoked with purchase_url(id: product.id)
18
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
19
+
20
+ # Example resource route (maps HTTP verbs to controller actions automatically):
21
+ # resources :products
22
+
23
+ # Example resource route with options:
24
+ # resources :products do
25
+ # member do
26
+ # get 'short'
27
+ # post 'toggle'
28
+ # end
29
+ #
30
+ # collection do
31
+ # get 'sold'
32
+ # end
33
+ # end
34
+
35
+ # Example resource route with sub-resources:
36
+ # resources :products do
37
+ # resources :comments, :sales
38
+ # resource :seller
39
+ # end
40
+
41
+ # Example resource route with more complex sub-resources:
42
+ # resources :products do
43
+ # resources :comments
44
+ # resources :sales do
45
+ # get 'recent', on: :collection
46
+ # end
47
+ # end
48
+
49
+ # Example resource route with concerns:
50
+ # concern :toggleable do
51
+ # post 'toggle'
52
+ # end
53
+ # resources :posts, concerns: :toggleable
54
+ # resources :photos, concerns: :toggleable
55
+
56
+ # Example resource route within a namespace:
57
+ # namespace :admin do
58
+ # # Directs /admin/products/* to Admin::ProductsController
59
+ # # (app/controllers/admin/products_controller.rb)
60
+ # resources :products
61
+ # end
62
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 0f47ceb46a550829fa1fb201733c705efcf764bc393c9c98cc7e912302301dda7683732280ed3d3d4d75aba03649710e4da50149664d87275199ef40a9f154c0
15
+
16
+ test:
17
+ secret_key_base: 0c254aef92862038a4463a9ca3f25e1856fece768c51a57ebb7e6b1e3d465536a2d7ca0322e99a397b7d399ec6139941b7a2876d42ef928b04544e5ca86a1d4a
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+ # Mayor.create(name: 'Emanuel', city: cities.first)
File without changes
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+ fixtures :all
8
+
9
+ # Add more helper methods to be used by all tests here...
10
+ end
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ module Oxd
2
+
3
+ # Generator module for oxd_config.rb
4
+ module Generators
5
+
6
+ # class to generate oxd config file through "rails generate" command
7
+ # @example
8
+ # rails generate oxd:config
9
+ class ConfigGenerator < Rails::Generators::Base
10
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
11
+
12
+ desc <<DESC
13
+ Description:
14
+ Copies Oxd configuration file to your application's initializer directory.
15
+ DESC
16
+ # copies oxd_config.rb template to 'config/initializers/oxd_config.rb'
17
+ def copy_config_file
18
+ template 'oxd_config.rb', 'config/initializers/oxd_config.rb'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # Sample config file
2
+ Oxd.configure do |config|
3
+ config.oxd_host_ip = '127.0.0.1'
4
+ config.oxd_host_port = 8099
5
+ config.authorization_redirect_uri = "https://domain.example.com/callback"
6
+ config.logout_redirect_uri = "https://domain.example.com/callback2"
7
+ config.post_logout_redirect_uri = "https://domain.example.com/logout"
8
+ config.scope = [ "openid", "profile" ]
9
+ config.application_type = "web"
10
+ config.redirect_uris = ["https://domain.example.com/callback" ]
11
+ config.client_jwks_uri = ""
12
+ config.client_token_endpoint_auth_method = ""
13
+ config.client_request_uris = []
14
+ config.contacts = ["example-email@gmail.com"]
15
+ config.grant_types = []
16
+ config.response_types = ["code"]
17
+ config.acr_values = ["basic"]
18
+ config.client_logout_uris = ['https://domain.example.com/logout']
19
+ end
data/lib/oxd-ruby.rb ADDED
@@ -0,0 +1,11 @@
1
+ # load oxd components
2
+ require 'oxd/config'
3
+ require 'oxd/oxd_connector'
4
+ require 'oxd/client_oxd_commands'
5
+
6
+ # @author Inderpal Singh
7
+ # Oxd Module namespace
8
+ # oxd_version 2.4.3
9
+ module Oxd
10
+
11
+ end
@@ -0,0 +1,147 @@
1
+ # @author Inderpal Singh
2
+ # @note supports oxd-version 2.4.3
3
+ module Oxd
4
+
5
+ require 'json'
6
+
7
+ # This class carries out the commands to talk with the oxD server.
8
+ # The oxD request commands are provided as class methods that can be called to send the command
9
+ # to the oxD server via socket and the reponse is returned as a dict by the called method.
10
+ class ClientOxdCommands < OxdConnector
11
+
12
+ # class constructor
13
+ def initialize
14
+ super
15
+ end
16
+
17
+ # @return [String] oxd_id of the registered website
18
+ # method to register the website and generate a unique ID for that website
19
+ def register_site
20
+ if(!@configuration.oxd_id.empty?) # Check if client is already registered
21
+ return @configuration.oxd_id
22
+ else
23
+ @command = 'register_site'
24
+ @configuration.scope = [ "openid", "profile","email"]
25
+ @params = {
26
+ "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
27
+ "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
28
+ "application_type" => @configuration.application_type,
29
+ "redirect_uris" => @configuration.redirect_uris,
30
+ "acr_values" => @configuration.acr_values,
31
+ "scope" => @configuration.scope,
32
+ "client_jwks_uri" => @configuration.client_jwks_uri,
33
+ "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
34
+ "client_request_uris" => @configuration.client_request_uris,
35
+ "contacts" => @configuration.contacts,
36
+ "grant_types" => @configuration.grant_types,
37
+ "response_types"=> @configuration.response_types,
38
+ "client_logout_uris"=> @configuration.client_logout_uris
39
+ }
40
+ request
41
+ @configuration.oxd_id = getResponseData['oxd_id']
42
+ end
43
+ end
44
+
45
+ # @return [String] stored(in oxd_config) oxd_id of the registered website
46
+ def getOxdId
47
+ return @configuration.oxd_id
48
+ end
49
+
50
+ # @param acr_values [Array] OPTIONAL, list of acr values in the order of priority
51
+ # @return [String] authorization_url
52
+ # method to get authorization url that the user must be redirected to for authorization and authentication
53
+ def get_authorization_url(acr_values = [""])
54
+ @command = 'get_authorization_url'
55
+ @params = {
56
+ "oxd_id" => @configuration.oxd_id,
57
+ "acr_values" => acr_values || @configuration.acr_values
58
+ }
59
+ request
60
+ getResponseData['authorization_url']
61
+ end
62
+
63
+ # @param code [String] code obtained from the authorization url callback
64
+ # @param scopes [Array] scopes authorized by the OP, obtained from the authorization url callback
65
+ # @param state [String] state key obtained from the authorization url callback
66
+ # @return [String] access_token
67
+ # method to retrieve access token. It is called after the user authorizes by visiting the authorization url.
68
+ def get_tokens_by_code( code, scopes, state = nil)
69
+ if (code.empty? || scopes.empty? || (!scopes.kind_of? Array))
70
+ logger(:log_msg => "Empty/Wrong value in place of code or scope.")
71
+ end
72
+ @command = 'get_tokens_by_code'
73
+ @params = {
74
+ "oxd_id" => @configuration.oxd_id,
75
+ "code" => code,
76
+ "scopes" => scopes,
77
+ "state" => state
78
+ }
79
+ request
80
+ getResponseData['access_token']
81
+ end
82
+
83
+ # @param access_token [String] access token recieved from the get_tokens_by_code command
84
+ # @return [String] user data claims that are returned by the OP
85
+ # get the information about the user using the access token obtained from the OP
86
+ def get_user_info(access_token)
87
+ if access_token.empty?
88
+ logger(:log_msg => "Empty access code sent for get_user_info", :error => "Empty access code")
89
+ end
90
+ @command = 'get_user_info'
91
+ @params = {
92
+ "oxd_id" => @configuration.oxd_id,
93
+ "access_token" => access_token
94
+ }
95
+ request
96
+ getResponseData['claims']
97
+ end
98
+
99
+ # @param access_token [String] REQUIRED, oxd server will use last used access token
100
+ # @param state [String] OPTIONAL, website state obtained from the authorization url callback
101
+ # @param session_state [String] OPTIONAL, session state obtained from the authorization url callback
102
+ # @return [String] uri
103
+ # method to retrieve logout url from OP. User must be redirected to this url to perform logout
104
+ def get_logout_uri(access_token, state = nil, session_state = nil)
105
+ @command = 'get_logout_uri'
106
+ @params = {
107
+ "oxd_id" => @configuration.oxd_id,
108
+ "id_token_hint" => access_token,
109
+ "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
110
+ "state" => state,
111
+ "session_state" => session_state
112
+ }
113
+ request
114
+ getResponseData['uri']
115
+ end
116
+
117
+ # @return [Boolean] status - if site registration was updated successfully or not
118
+ # method to update the website's information with OpenID Provider.
119
+ # This should be called after changing the values in the oxd_config file.
120
+ def update_site_registration
121
+ @command = 'update_site_registration'
122
+ @params = {
123
+ "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
124
+ "oxd_id" => @configuration.oxd_id,
125
+ "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
126
+ "application_type" => @configuration.application_type,
127
+ "redirect_uris" => @configuration.redirect_uris,
128
+ "acr_values" => @configuration.acr_values,
129
+ "scope" => @configuration.scope,
130
+ "client_jwks_uri" => @configuration.client_jwks_uri,
131
+ "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
132
+ "client_request_uris" => @configuration.client_request_uris,
133
+ "contacts" => @configuration.contacts,
134
+ "grant_types" => @configuration.grant_types,
135
+ "response_types"=> @configuration.response_types,
136
+ "client_logout_uris"=> @configuration.client_logout_uris
137
+ }
138
+ request
139
+ if @response_object['status'] == "ok"
140
+ @configuration.oxd_id = getResponseData['oxd_id']
141
+ return true
142
+ else
143
+ return false
144
+ end
145
+ end
146
+ end
147
+ end