biovision-oauth 0.0.201128.0
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +22 -0
- data/app/assets/config/biovision_oauth_manifest.js +0 -0
- data/app/controllers/oauth_controller.rb +26 -0
- data/app/lib/biovision/components/oauth_component.rb +9 -0
- data/app/models/foreign_site.rb +34 -0
- data/app/models/foreign_user.rb +20 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20201127000000_create_oauth_component.rb +49 -0
- data/lib/biovision/oauth.rb +7 -0
- data/lib/biovision/oauth/engine.rb +19 -0
- data/lib/biovision/oauth/version.rb +5 -0
- data/lib/tasks/biovision/oauth_tasks.rake +4 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58299a9672161f625c64eef352414e80fd5fcde97a2f801971cb48f43177542e
|
4
|
+
data.tar.gz: a588979ec66d7c9c74a571427ce04fca8c7af18a997b729c2f032dadabbfdddf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59a7bf98adbd024c685b8cf4396759157df0d5cb94e458538c01175a895f9706757d2c4ebd295a37599c321ec2a10552ace3b84cbae5ad604684e055bbf2dd9d
|
7
|
+
data.tar.gz: 4ba465f0b14e2fb5bd48efece77e26535591e32292eadc43d6278f394813977348b410508603abaf5471b5879f23d8ccd64121d7ecbbb3d81b6fe60cbff72062
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Maxim Khan-Magomedov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Biovision::Oauth
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'biovision-oauth'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install biovision-oauth
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Biovision::Oauth'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("spec/test_app/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Authentication with OAuth
|
4
|
+
class OauthController < ApplicationController
|
5
|
+
include Authentication
|
6
|
+
|
7
|
+
before_action :redirect_authenticated_user
|
8
|
+
before_action :set_foreign_site
|
9
|
+
|
10
|
+
# get /auth/:provider/callback
|
11
|
+
def auth_callback
|
12
|
+
data = request.env['omniauth.auth']
|
13
|
+
user = @foreign_site.authenticate(data, tracking_for_entity)
|
14
|
+
create_token_for_user(user) unless user.banned?
|
15
|
+
|
16
|
+
redirect_to my_path
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def set_foreign_site
|
22
|
+
@foreign_site = ForeignSite[params[:provider]]
|
23
|
+
|
24
|
+
handle_http_503('Cannot set foreign site') if @foreign_site.nil?
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Foreign site for external authentication
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# slug [string]
|
7
|
+
# name [string]
|
8
|
+
# foreign_users_count [integer]
|
9
|
+
class ForeignSite < ApplicationRecord
|
10
|
+
include RequiredUniqueName
|
11
|
+
include RequiredUniqueSlug
|
12
|
+
|
13
|
+
NAME_LIMIT = 50
|
14
|
+
SLUG_LIMIT = 50
|
15
|
+
|
16
|
+
has_many :foreign_users, dependent: :delete_all
|
17
|
+
|
18
|
+
validates_length_of :name, maximum: NAME_LIMIT
|
19
|
+
validates_length_of :slug, maximum: SLUG_LIMIT
|
20
|
+
|
21
|
+
scope :list_for_administration, -> { ordered_by_name }
|
22
|
+
|
23
|
+
# @param [String] slug
|
24
|
+
def self.[](slug)
|
25
|
+
find_by(slug: slug)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param [Hash] data
|
29
|
+
# @param [Hash] tracking
|
30
|
+
def authenticate(data, tracking)
|
31
|
+
user = foreign_users.find_by(slug: data[:uid])&.user
|
32
|
+
user || create_user(data, tracking)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Foreign user
|
4
|
+
#
|
5
|
+
# Attributes:
|
6
|
+
# agent_id [Agent], optional
|
7
|
+
# created_at [DateTime]
|
8
|
+
# data [jsonb]
|
9
|
+
# foreign_site_id [ForeignSite]
|
10
|
+
# ip_address_id [IpAddress], optional
|
11
|
+
# updated_at [DateTime]
|
12
|
+
# user_id [User]
|
13
|
+
# slug [string]
|
14
|
+
class ForeignUser < ApplicationRecord
|
15
|
+
include HasOwner
|
16
|
+
include HasTrack
|
17
|
+
|
18
|
+
belongs_to :foreign_site
|
19
|
+
belongs_to :user
|
20
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Create tables for Users component
|
4
|
+
class CreateOauthComponent < ActiveRecord::Migration[6.0]
|
5
|
+
def up
|
6
|
+
create_component
|
7
|
+
create_foreign_sites unless ForeignSite.table_exists?
|
8
|
+
create_foreign_users unless ForeignUser.table_exists?
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
[ForeignUser, ForeignSite].each do |model|
|
13
|
+
drop_table model.table_name if model.table_exists?
|
14
|
+
end
|
15
|
+
|
16
|
+
BiovisionComponent[Biovision::Components::OauthComponent.slug]&.destroy
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def create_component
|
22
|
+
slug = Biovision::Components::OauthComponent.slug
|
23
|
+
BiovisionComponent.create(slug: slug)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_foreign_sites
|
27
|
+
create_table :foreign_sites, comment: 'Sites for external authentication' do |t|
|
28
|
+
t.string :slug, null: false
|
29
|
+
t.string :name, null: false
|
30
|
+
t.integer :foreign_users_count, default: 0, null: false
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index :foreign_sites, :slug, unique: true
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_foreign_users
|
37
|
+
create_table :foreign_users, comment: 'Users from external sites' do |t|
|
38
|
+
t.references :foreign_site, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
|
39
|
+
t.references :user, null: false, foreign_key: { on_update: :cascade, on_delete: :cascade }
|
40
|
+
t.references :agent, foreign_key: { on_update: :cascade, on_delete: :nullify }
|
41
|
+
t.references :ip_address, foreign_key: { on_update: :cascade, on_delete: :nullify }
|
42
|
+
t.string :slug, null: false
|
43
|
+
t.timestamps
|
44
|
+
t.jsonb :data, default: {}, null: false
|
45
|
+
end
|
46
|
+
|
47
|
+
add_index :foreign_users, :data, using: :gin
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'biovision'
|
4
|
+
|
5
|
+
module Biovision
|
6
|
+
module Oauth
|
7
|
+
# Biovision OAuth engine
|
8
|
+
class Engine < ::Rails::Engine
|
9
|
+
config.generators do |g|
|
10
|
+
g.test_framework :rspec
|
11
|
+
g.fixture_replacement :factory_bot, dir: 'spec/factories'
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer 'sample_engine.factories', after: 'factory_bot.set_factory_paths' do
|
15
|
+
FactoryBot.definition_file_paths << File.expand_path('../../../spec/factories', __FILE__) if defined?(FactoryBot)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: biovision-oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.201128.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxim Khan-Magomedov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.3
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.3.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 6.0.3
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.3.4
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rails-i18n
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '6.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '6.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: biovision
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: database_cleaner
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: factory_bot_rails
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec-rails
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: pg
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
description: OAuth component for Biovision CMS.
|
118
|
+
email:
|
119
|
+
- maxim.km@gmail.com
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- MIT-LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- app/assets/config/biovision_oauth_manifest.js
|
128
|
+
- app/controllers/oauth_controller.rb
|
129
|
+
- app/lib/biovision/components/oauth_component.rb
|
130
|
+
- app/models/foreign_site.rb
|
131
|
+
- app/models/foreign_user.rb
|
132
|
+
- config/routes.rb
|
133
|
+
- db/migrate/20201127000000_create_oauth_component.rb
|
134
|
+
- lib/biovision/oauth.rb
|
135
|
+
- lib/biovision/oauth/engine.rb
|
136
|
+
- lib/biovision/oauth/version.rb
|
137
|
+
- lib/tasks/biovision/oauth_tasks.rake
|
138
|
+
homepage: https://github.com/Biovision/biovision-oauth
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata:
|
142
|
+
allowed_push_host: https://rubygems.org
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubygems_version: 3.1.4
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: OAuth component for Biovision CMS
|
162
|
+
test_files: []
|