authorio 0.8.1 → 0.8.5

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -0
  3. data/app/assets/stylesheets/authorio/auth.css +55 -1
  4. data/app/controllers/authorio/auth_controller.rb +69 -102
  5. data/app/controllers/authorio/authorio_controller.rb +78 -0
  6. data/app/controllers/authorio/sessions_controller.rb +33 -0
  7. data/app/controllers/authorio/users_controller.rb +34 -0
  8. data/app/helpers/authorio/tag_helper.rb +17 -0
  9. data/app/jobs/authorio/application_job.rb +2 -0
  10. data/app/models/authorio/application_record.rb +2 -0
  11. data/app/models/authorio/request.rb +48 -1
  12. data/app/models/authorio/session.rb +43 -0
  13. data/app/models/authorio/token.rb +23 -1
  14. data/app/models/authorio/user.rb +14 -0
  15. data/app/views/authorio/auth/authorization_interface.html.erb +14 -35
  16. data/app/views/authorio/auth/issue_token.json.jbuilder +7 -0
  17. data/app/views/authorio/auth/send_profile.json.jbuilder +3 -0
  18. data/app/views/authorio/auth/verify_token.json.jbuilder +5 -0
  19. data/app/views/authorio/sessions/new.html.erb +14 -0
  20. data/app/views/authorio/users/_profile.json.jbuilder +10 -0
  21. data/app/views/authorio/users/edit.html.erb +25 -0
  22. data/app/views/authorio/users/show.html.erb +18 -0
  23. data/app/views/authorio/users/verify.html.erb +1 -0
  24. data/app/views/layouts/authorio/main.html.erb +38 -0
  25. data/app/views/shared/_login_form.html.erb +41 -0
  26. data/config/routes.rb +15 -5
  27. data/db/migrate/20210723161041_add_expiry_to_tokens.rb +5 -0
  28. data/db/migrate/20210726164625_create_authorio_sessions.rb +12 -0
  29. data/db/migrate/20210801184120_add_profile_to_users.rb +8 -0
  30. data/db/migrate/20210817010101_change_path_to_username_in_users.rb +7 -0
  31. data/db/migrate/20210831155106_add_code_challenge_to_requests.rb +5 -0
  32. data/lib/authorio/configuration.rb +14 -9
  33. data/lib/authorio/engine.rb +11 -8
  34. data/lib/authorio/exceptions.rb +20 -3
  35. data/lib/authorio/routes.rb +10 -7
  36. data/lib/authorio/version.rb +3 -1
  37. data/lib/authorio.rb +15 -21
  38. data/lib/generators/authorio/install/install_generator.rb +3 -3
  39. data/lib/generators/authorio/install/templates/authorio.rb +22 -8
  40. data/lib/tasks/authorio_tasks.rake +15 -14
  41. metadata +49 -20
  42. data/app/controllers/authorio/application_controller.rb +0 -4
  43. data/app/controllers/authorio/helpers.rb +0 -17
  44. data/app/helpers/authorio/application_helper.rb +0 -4
  45. data/app/helpers/authorio/test_helper.rb +0 -4
  46. data/app/views/layouts/authorio/application.html.erb +0 -15
@@ -0,0 +1,5 @@
1
+ class AddExpiryToTokens < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :authorio_tokens, :expires_at, :datetime
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ class CreateAuthorioSessions < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :authorio_sessions do |t|
4
+ t.references :authorio_user, null: false, foreign_key: true
5
+ t.string :selector
6
+ t.string :hashed_token
7
+ t.datetime :expires_at
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,8 @@
1
+ class AddProfileToUsers < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :authorio_users, :email, :string
4
+ add_column :authorio_users, :full_name, :string
5
+ add_column :authorio_users, :url, :string
6
+ add_column :authorio_users, :photo, :string
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class ChangePathToUsernameInUsers < ActiveRecord::Migration[6.1]
2
+ def change
3
+ change_table :authorio_users do |t|
4
+ t.rename :profile_path, :username
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddCodeChallengeToRequests < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :authorio_requests, :code_challenge, :string
4
+ end
5
+ end
@@ -1,12 +1,17 @@
1
- module Authorio
2
- class Configuration
1
+ # frozen_string_literal: true
3
2
 
4
- attr_accessor :authorization_endpoint, :token_endpoint, :mount_point
3
+ module Authorio
4
+ class Configuration
5
+ attr_accessor :authorization_endpoint, :token_endpoint, :mount_point, :token_expiration,
6
+ :local_session_lifetime, :multiuser
5
7
 
6
- def initialize
7
- @authorization_endpoint = "auth"
8
- @token_endpoint = "token"
9
- @mount_point = "authorio"
10
- end
11
- end
8
+ def initialize
9
+ @authorization_endpoint = 'auth'
10
+ @token_endpoint = 'token'
11
+ @mount_point = 'authorio'
12
+ @token_expiration = 4.weeks
13
+ @local_session_lifetime = nil
14
+ @multiuser = false
15
+ end
16
+ end
12
17
  end
@@ -1,14 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Authorio
2
4
  class Engine < ::Rails::Engine
3
- isolate_namespace Authorio
4
-
5
- initializer "authorio.load_helpers" do |app|
6
- ActionController::Base.send :include, Authorio::Helpers
7
- end
5
+ isolate_namespace Authorio
8
6
 
9
- initializer "authorio.assets.precompile" do |app|
10
- app.config.assets.precompile += %w( authorio/auth.css )
11
- end
7
+ initializer 'authorio.load_helpers' do
8
+ Rails.application.reloader.to_prepare do
9
+ ActionView::Base.send :include, Authorio::TagHelper
10
+ end
11
+ end
12
12
 
13
+ initializer 'authorio.assets.precompile' do |app|
14
+ app.config.assets.precompile += %w[authorio/auth.css authorio/application.css]
15
+ end
13
16
  end
14
17
  end
@@ -1,5 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Authorio
2
- module Exceptions
3
- class InvalidGrant < RuntimeError; end
4
- end
4
+ module Exceptions
5
+ class InvalidGrant < RuntimeError; end
6
+
7
+ class InvalidPassword < RuntimeError; end
8
+
9
+ class SessionReplayAttack < StandardError
10
+ attr_accessor :session
11
+
12
+ def initialize(session)
13
+ super("Session replay attack on user account #{session.authorio_user.id}")
14
+ @session = session
15
+ end
16
+ end
17
+
18
+ class UserNotFound < StandardError; end
19
+
20
+ class TokenExpired < StandardError; end
21
+ end
5
22
  end
@@ -1,9 +1,12 @@
1
- module ActionDispatch::Routing
2
- class Mapper
1
+ # frozen_string_literal: true
3
2
 
4
- # Provide a custom mounting command, just so we can track our own mount point
5
- def authorio_routes
6
- mount Authorio::Engine, at: Authorio.configuration.mount_point
7
- end
8
- end
3
+ module ActionDispatch
4
+ module Routing
5
+ class Mapper
6
+ # Provide a custom mounting command, just so we can track our own mount point
7
+ def authorio_routes
8
+ mount Authorio::Engine, at: Authorio.configuration.mount_point
9
+ end
10
+ end
11
+ end
9
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Authorio
2
- VERSION = '0.8.1'
4
+ VERSION = '0.8.5'
3
5
  end
data/lib/authorio.rb CHANGED
@@ -1,27 +1,21 @@
1
- require "authorio/version"
2
- require "authorio/engine"
3
- require "authorio/configuration"
4
- require "authorio/routes"
5
- require "authorio/exceptions"
1
+ # frozen_string_literal: true
6
2
 
7
- module Authorio
8
- class << self
9
- attr_accessor :configuration, :authorization_path
10
- end
3
+ Dir[File.join(__dir__, 'authorio', '*.rb')].sort.each { |f| require f }
11
4
 
12
- def self.configuration
13
- @configuration ||= Configuration.new
14
- end
5
+ module Authorio
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
15
9
 
16
- def self.configure
17
- yield configuration
18
- end
10
+ def self.configure
11
+ yield configuration
12
+ end
19
13
 
20
- def self.authorization_path
21
- return [Authorio.configuration.mount_point, Authorio.configuration.authorization_endpoint].join("/")
22
- end
14
+ def self.authorization_path
15
+ [Authorio.configuration.mount_point, Authorio.configuration.authorization_endpoint].join('/')
16
+ end
23
17
 
24
- def self.token_path
25
- return [Authorio.configuration.mount_point, Authorio.configuration.token_endpoint].join("/")
26
- end
18
+ def self.token_path
19
+ [Authorio.configuration.mount_point, Authorio.configuration.token_endpoint].join('/')
20
+ end
27
21
  end
@@ -1,17 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Authorio
2
4
  class InstallGenerator < Rails::Generators::Base
3
-
4
5
  def self.source_paths
5
6
  paths = []
6
7
  paths << File.expand_path('../templates', "../../#{__FILE__}")
7
8
  paths << File.expand_path('../templates', "../#{__FILE__}")
8
- paths << File.expand_path('../templates', __FILE__)
9
+ paths << File.expand_path('templates', __dir__)
9
10
  paths.flatten
10
11
  end
11
12
 
12
13
  def add_files
13
14
  template 'authorio.rb', 'config/initializers/authorio.rb'
14
15
  end
15
-
16
16
  end
17
17
  end
@@ -1,15 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Configuration for Authorio IndieAuth authentication
2
4
 
3
5
  Authorio.configure do |config|
6
+ # Mount point for Authorio URLs. Typically you would call this in your routes.rb
7
+ # as mount Authorio::Engine, at: mount_point
8
+ # But Authorio needs to know its own mount point, so we define it here and use a custom mount command in the config
9
+ # config.mount_point = "authorio"
10
+
11
+ # The path where clients will be redirected to provide authentication
12
+ # config.authorization_endpoint = "auth"
13
+
14
+ # The path for token requests
15
+ # config.token_endpoint = "token"
4
16
 
5
- # Mount point for Authorio URLs. Typically you would call this in your routes.rb
6
- # as mount Authorio::Engine, at: mount_point
7
- # But Authorio needs to know its own mount point, so we define it here and use a custom mount command in the config
8
- # config.mount_point = "authorio"
17
+ # Set to true to enable multiple user accounts. By default (in single user mode)
18
+ # there is only one user, and therefore you do not need to enter a username
19
+ # config.multiuser = false
9
20
 
10
- # The path where clients will be redirected to provide authentication
11
- # config.authorization_endpoint = "auth"
21
+ # How long tokens will last before expiring
22
+ # config.token_expiration = 4.weeks
12
23
 
13
- # The path for token requests
14
- # config.token_endpoint = "token"
24
+ # Enable local session lifetime to keep yourself "logged in" to your own server
25
+ # If set to eg:
26
+ # config.local_session_lifetime = 30.days
27
+ # then you will only have to enter your password every 30 days. Default is off (nil)
28
+ # config.local_session_lifetime = nil
15
29
  end
@@ -1,18 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :authorio do
2
- desc "Set password for initial Authorio user"
3
- require 'io/console'
4
+ desc 'Set password for initial Authorio user'
5
+ require 'io/console'
4
6
 
5
- def input_no_echo(prompt)
6
- print("\n#{prompt}")
7
- STDIN.noecho(&:gets).chop
8
- end
7
+ def input_no_echo(prompt)
8
+ print("\n#{prompt}")
9
+ $stdin.noecho(&:gets).chop
10
+ end
9
11
 
10
- task :password => :environment do
11
- passwd = input_no_echo("Enter new password: ")
12
- passwd_confirm = input_no_echo("Confirm password: ")
13
- user = Authorio::User.
14
- create_with(password: passwd, password_confirmation:passwd_confirm).
15
- find_or_create_by!(profile_path: '/')
16
- puts("\nPassword set")
17
- end
12
+ task password: :environment do
13
+ passwd = input_no_echo('Enter new password: ')
14
+ passwd_confirm = input_no_echo('Confirm password: ')
15
+ Authorio::User.create_with(password: passwd, password_confirmation: passwd_confirm)
16
+ .find_or_create_by!(profile_path: '/')
17
+ puts("\nPassword set")
18
+ end
18
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authorio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Meckler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-13 00:00:00.000000000 Z
11
+ date: 2021-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,70 +34,84 @@ dependencies:
34
34
  name: bcrypt
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '3.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: jbuilder
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: factory_bot_rails
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
- - - ">="
65
+ - - "~>"
52
66
  - !ruby/object:Gem::Version
53
67
  version: '6.0'
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
- - - ">="
72
+ - - "~>"
59
73
  - !ruby/object:Gem::Version
60
74
  version: '6.0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: rspec
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
- - - ">="
79
+ - - "~>"
66
80
  - !ruby/object:Gem::Version
67
81
  version: '3.0'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - ">="
86
+ - - "~>"
73
87
  - !ruby/object:Gem::Version
74
88
  version: '3.0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: rspec-rails
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
- - - ">="
93
+ - - "~>"
80
94
  - !ruby/object:Gem::Version
81
95
  version: '5.0'
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
- - - ">="
100
+ - - "~>"
87
101
  - !ruby/object:Gem::Version
88
102
  version: '5.0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: byebug
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
- - - ">="
107
+ - - "~>"
94
108
  - !ruby/object:Gem::Version
95
109
  version: '11.0'
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
- - - ">="
114
+ - - "~>"
101
115
  - !ruby/object:Gem::Version
102
116
  version: '11.0'
103
117
  description: Rails engine to add IndieAuth authentication endpoint functionality
@@ -113,22 +127,37 @@ files:
113
127
  - app/assets/config/authorio_manifest.js
114
128
  - app/assets/stylesheets/authorio/application.css
115
129
  - app/assets/stylesheets/authorio/auth.css
116
- - app/controllers/authorio/application_controller.rb
117
130
  - app/controllers/authorio/auth_controller.rb
118
- - app/controllers/authorio/helpers.rb
119
- - app/helpers/authorio/application_helper.rb
120
- - app/helpers/authorio/test_helper.rb
131
+ - app/controllers/authorio/authorio_controller.rb
132
+ - app/controllers/authorio/sessions_controller.rb
133
+ - app/controllers/authorio/users_controller.rb
134
+ - app/helpers/authorio/tag_helper.rb
121
135
  - app/jobs/authorio/application_job.rb
122
136
  - app/models/authorio/application_record.rb
123
137
  - app/models/authorio/request.rb
138
+ - app/models/authorio/session.rb
124
139
  - app/models/authorio/token.rb
125
140
  - app/models/authorio/user.rb
126
141
  - app/views/authorio/auth/authorization_interface.html.erb
127
- - app/views/layouts/authorio/application.html.erb
142
+ - app/views/authorio/auth/issue_token.json.jbuilder
143
+ - app/views/authorio/auth/send_profile.json.jbuilder
144
+ - app/views/authorio/auth/verify_token.json.jbuilder
145
+ - app/views/authorio/sessions/new.html.erb
146
+ - app/views/authorio/users/_profile.json.jbuilder
147
+ - app/views/authorio/users/edit.html.erb
148
+ - app/views/authorio/users/show.html.erb
149
+ - app/views/authorio/users/verify.html.erb
150
+ - app/views/layouts/authorio/main.html.erb
151
+ - app/views/shared/_login_form.html.erb
128
152
  - config/routes.rb
129
153
  - db/migrate/20210627230156_create_authorio_users.rb
130
154
  - db/migrate/20210627230416_create_authorio_requests.rb
131
155
  - db/migrate/20210707230416_create_authorio_tokens.rb
156
+ - db/migrate/20210723161041_add_expiry_to_tokens.rb
157
+ - db/migrate/20210726164625_create_authorio_sessions.rb
158
+ - db/migrate/20210801184120_add_profile_to_users.rb
159
+ - db/migrate/20210817010101_change_path_to_username_in_users.rb
160
+ - db/migrate/20210831155106_add_code_challenge_to_requests.rb
132
161
  - lib/authorio.rb
133
162
  - lib/authorio/configuration.rb
134
163
  - lib/authorio/engine.rb
@@ -138,12 +167,12 @@ files:
138
167
  - lib/generators/authorio/install/install_generator.rb
139
168
  - lib/generators/authorio/install/templates/authorio.rb
140
169
  - lib/tasks/authorio_tasks.rake
141
- homepage: https://rubygems.org/gems/authorio
170
+ homepage:
142
171
  licenses:
143
172
  - MIT
144
173
  metadata:
145
- homepage_uri: https://rubygems.org/gems/authorio
146
174
  source_code_uri: https://github.com/reiterate-app/authorio
175
+ changelog_uri: https://github.com/reiterate-app/authorio/blob/master/CHANGELOG.md
147
176
  post_install_message:
148
177
  rdoc_options: []
149
178
  require_paths:
@@ -159,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
188
  - !ruby/object:Gem::Version
160
189
  version: '0'
161
190
  requirements: []
162
- rubygems_version: 3.2.11
191
+ rubygems_version: 3.1.6
163
192
  signing_key:
164
193
  specification_version: 4
165
194
  summary: Indieauth Authentication endpoint for Rails