doorkeeper_hub 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/doorkeeper_hub/callbacks_controller.rb +5 -4
- data/app/controllers/doorkeeper_hub/omniauth_callbacks_controller.rb +1 -1
- data/lib/doorkeeper_hub/configurator.rb +15 -0
- data/lib/doorkeeper_hub/saml.rb +29 -0
- data/lib/doorkeeper_hub/version.rb +1 -1
- data/lib/doorkeeper_hub.rb +9 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e23d3e5083949341c37c8232317c3522835d48c407ebc2f6800a2212b5e3eff
|
4
|
+
data.tar.gz: 216e1277207ae9f51da9cb537b74f6ac0a0949bfe89a49a24e757c6a68ba8937
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bed5ad5532c7919d3838a41405f7ccd8d3204e54becef917a5364117e9c5d710b10279a87e2c045466851f6ad3cf93a67ca42048b663043688b383478fb55388
|
7
|
+
data.tar.gz: 9040b8be14c6a28bfc47091e1c3b6fad189be2758b3eaf253c73bef1d6c0ae3ff0a2695fb1e8fac7ca921021a9557a0491bb9b2c6e95e2a61d91ba08e31989d6
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module DoorkeeperHub
|
2
2
|
class CallbacksController < ActionController::Base
|
3
|
-
|
4
3
|
def activation
|
5
|
-
return if params[:access_token] !=
|
4
|
+
return if params[:access_token] != DoorkeeperHub.config.service_token
|
6
5
|
# {name, access_token, doorkeeper_token, active, options}
|
7
|
-
|
8
|
-
|
6
|
+
record = DoorkeeperHub.config.scope_model.find_or_initialize_by(
|
7
|
+
DoorkeeperHub.config.doorkeeper_token_name => params[DoorkeeperHub.config.doorkeeper_token_name]
|
8
|
+
)
|
9
|
+
record.update active: params[:active], name: params[:name]
|
9
10
|
render body: nil
|
10
11
|
end
|
11
12
|
end
|
@@ -4,7 +4,7 @@ module DoorkeeperHub
|
|
4
4
|
|
5
5
|
def saml
|
6
6
|
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
7
|
-
@user =
|
7
|
+
@user = DoorkeeperHub.config.user_model.from_omniauth(request.env["omniauth.auth"])
|
8
8
|
|
9
9
|
if @user.present? && @user.persisted?
|
10
10
|
sign_in_and_redirect @user, event: :authentication
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DoorkeeperHub
|
2
|
+
class Configurator
|
3
|
+
attr_accessor :service_token
|
4
|
+
attr_accessor :scope_model
|
5
|
+
attr_accessor :user_model
|
6
|
+
attr_accessor :doorkeeper_token_name
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.service_token = ENV["SERVICE_TOKEN"]
|
10
|
+
self.scope_model = ::Company
|
11
|
+
self.user_model = ::User
|
12
|
+
self.doorkeeper_token_name = :doorkeeper_token
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module DoorkeeperHub
|
4
|
+
module Saml
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.devise :omniauthable, omniauth_providers: %i[saml]
|
9
|
+
end
|
10
|
+
|
11
|
+
def instance_method
|
12
|
+
puts "instance method here"
|
13
|
+
end
|
14
|
+
|
15
|
+
class_methods do
|
16
|
+
def from_omniauth(auth)
|
17
|
+
companies = Company.where(doorkeeper_token: auth.extra.raw_info[:doorkeeper_token])
|
18
|
+
|
19
|
+
return if companies.empty?
|
20
|
+
|
21
|
+
user = where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
22
|
+
user.email = auth.info.email
|
23
|
+
end
|
24
|
+
companies.each { |c| user.users_companies.find_or_create_by(company: c) }
|
25
|
+
user
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/doorkeeper_hub.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require "doorkeeper_hub/version"
|
2
|
+
require 'doorkeeper_hub/configurator'
|
3
|
+
require "doorkeeper_hub/saml"
|
2
4
|
require 'doorkeeper_hub/engine' if defined?(::Rails) && Rails::VERSION::MAJOR > 4
|
3
5
|
|
4
6
|
module DoorkeeperHub
|
5
|
-
|
7
|
+
def self.config
|
8
|
+
@config ||= DoorkeeperHub::Configurator.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
yield config
|
13
|
+
end
|
6
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doorkeeper_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Fan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,7 +85,9 @@ files:
|
|
85
85
|
- bin/setup
|
86
86
|
- doorkeeper_hub.gemspec
|
87
87
|
- lib/doorkeeper_hub.rb
|
88
|
+
- lib/doorkeeper_hub/configurator.rb
|
88
89
|
- lib/doorkeeper_hub/engine.rb
|
90
|
+
- lib/doorkeeper_hub/saml.rb
|
89
91
|
- lib/doorkeeper_hub/version.rb
|
90
92
|
homepage: https://devhub.co
|
91
93
|
licenses:
|