capcoauth 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +40 -0
- data/LICENSE +21 -0
- data/README.md +3 -0
- data/Rakefile +20 -0
- data/app/controllers/capcoauth/application_controller.rb +11 -0
- data/app/controllers/capcoauth/application_metal_controller.rb +15 -0
- data/app/controllers/capcoauth/callback_controller.rb +36 -0
- data/app/controllers/capcoauth/login_controller.rb +14 -0
- data/app/controllers/capcoauth/logout_controller.rb +14 -0
- data/capcoauth.gemspec +24 -0
- data/lib/capcoauth/config.rb +71 -0
- data/lib/capcoauth/engine.rb +18 -0
- data/lib/capcoauth/helpers/controller.rb +17 -0
- data/lib/capcoauth/oauth/access_token.rb +17 -0
- data/lib/capcoauth/oauth/token_verifier.rb +27 -0
- data/lib/capcoauth/oauth/ttl_cache.rb +26 -0
- data/lib/capcoauth/rails/helpers.rb +24 -0
- data/lib/capcoauth/rails/routes/mapper.rb +28 -0
- data/lib/capcoauth/rails/routes/mapping.rb +36 -0
- data/lib/capcoauth/rails/routes.rb +68 -0
- data/lib/capcoauth/version.rb +3 -0
- data/lib/capcoauth.rb +22 -0
- data/lib/generators/capcoauth/install_generator.rb +11 -0
- data/lib/generators/capcoauth/templates/README +13 -0
- data/lib/generators/capcoauth/templates/initializer.rb +11 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c28503763c33f4b3e66be0e3193f0bbb44efd8bf
|
4
|
+
data.tar.gz: dbe45f966a2dee70221bbd639fe52e6722378c77
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22964c39f960e54d1d371fb9e5acfe047d4a262fc015a83a657625786ed7af395a2f6ef5b1d0ebb827989ec3783ab19d5c0b08287cadb7a13a46c0e2da6d8c8d
|
7
|
+
data.tar.gz: b1d592b706ced53f4548ce71cc4e51b71cea06fdc3db27cbd832be618c11b97a65db43e91f9950cea2d2094c1d5af58209973c01ed08ba1a8035da0573e3d325
|
data/.gitignore
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
|
38
|
+
# IDE
|
39
|
+
.idea
|
40
|
+
.editorconfig
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Adam Robertson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
desc 'Default: run specs.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc 'Run all specs'
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |config|
|
9
|
+
config.verbose = false
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :capcoauth do
|
13
|
+
# desc 'Install Capcoauth in dummy app'
|
14
|
+
# task :install do
|
15
|
+
# cd 'spec/dummy'
|
16
|
+
# system 'bundle exec rails g capcoauth:install --force'
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
class ApplicationMetalController < ActionController::Metal
|
3
|
+
MODULES = [
|
4
|
+
ActionController::Instrumentation,
|
5
|
+
AbstractController::Rendering,
|
6
|
+
ActionController::Rendering,
|
7
|
+
ActionController::Renderers::All,
|
8
|
+
Helpers::Controller
|
9
|
+
]
|
10
|
+
|
11
|
+
MODULES.each do |mod|
|
12
|
+
include mod
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Capcoauth
|
4
|
+
class CallbackController < Capcoauth::ApplicationController
|
5
|
+
def show
|
6
|
+
# Abort if code not found
|
7
|
+
return redirect_to root_url, alert: 'Authorization was canceled' unless params[:code].present?
|
8
|
+
|
9
|
+
response = HTTParty.post('https://capcoauth.capco.com/oauth/token', {
|
10
|
+
body: {
|
11
|
+
client_id: Capcoauth.configuration.client_id,
|
12
|
+
client_secret: Capcoauth.configuration.client_secret,
|
13
|
+
code: params[:code],
|
14
|
+
grant_type: 'authorization_code',
|
15
|
+
redirect_uri: oauth_callback_url
|
16
|
+
}
|
17
|
+
})
|
18
|
+
|
19
|
+
error_message = 'There was an error logging you in'
|
20
|
+
|
21
|
+
if response.code == 200 and !response.parsed_response['access_token'].blank?
|
22
|
+
@access_token = OAuth::AccessToken.new(response.parsed_response['access_token']).verify
|
23
|
+
|
24
|
+
if @access_token
|
25
|
+
session[:capcoauth_access_token] = @access_token.token
|
26
|
+
session[:capcoauth_user_id] = @access_token.user_id
|
27
|
+
redirect_to session[:previous_url].blank? ? root_url : session.delete(:previous_url)
|
28
|
+
else
|
29
|
+
redirect_to root_url, alert: error_message
|
30
|
+
end
|
31
|
+
else
|
32
|
+
redirect_to root_url, alert: error_message
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Capcoauth
|
4
|
+
class LoginController < Capcoauth::ApplicationController
|
5
|
+
def show
|
6
|
+
if capcoauth_token
|
7
|
+
redirect_to session[:previous_url].blank? ? root_url : session.delete(:previous_url), notice: 'You are already logged in'
|
8
|
+
return
|
9
|
+
end
|
10
|
+
|
11
|
+
redirect_to "https://capcoauth.capco.com/oauth/authorize?client_id=#{Capcoauth.configuration.client_id}&redirect_uri=#{URI.encode(oauth_callback_url)}&response_type=code"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
class LogoutController < Capcoauth::ApplicationController
|
3
|
+
|
4
|
+
def show
|
5
|
+
session.delete(:capcoauth_user_id)
|
6
|
+
if token = session.delete(:capcoauth_access_token)
|
7
|
+
OAuth::TTLCache.delete(token)
|
8
|
+
redirect_to root_url, notice: 'You have been logged out'
|
9
|
+
else
|
10
|
+
redirect_to root_url
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/capcoauth.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'capcoauth/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'capcoauth'
|
7
|
+
s.version = Capcoauth::VERSION
|
8
|
+
s.authors = ['Adam Robertson']
|
9
|
+
s.email = %w'adam.robertson@capco.com'
|
10
|
+
s.homepage = 'https://github.com/arcreative/capcoauth-gem'
|
11
|
+
s.summary = 'Integration with Capcoauth authentication service'
|
12
|
+
s.description = 'capcoauth-gem is a library to integrate Rails applications with Capcoauth authentication service'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
# s.test_files = `git ls-files -- spec/*`.split("\n")
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_dependency 'railties', '~> 4.2'
|
20
|
+
s.add_dependency 'httparty', '~> 0.13'
|
21
|
+
|
22
|
+
s.add_development_dependency 'rake', '~> 10.5'
|
23
|
+
s.add_development_dependency 'rspec-rails', '~> 3.4'
|
24
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
class MissingConfiguration < StandardError
|
3
|
+
def initialize
|
4
|
+
super 'Capcoauth configuration is missing. Please ensure you have an initializer in config/initializers/capcoauth.rb'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure(&block)
|
9
|
+
@config = Config::Builder.new(&block).build
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@config || (fail MissingConfiguration.new)
|
14
|
+
end
|
15
|
+
|
16
|
+
class Config
|
17
|
+
attr_reader :client_id
|
18
|
+
attr_reader :client_secret
|
19
|
+
|
20
|
+
class Builder
|
21
|
+
def initialize(&block)
|
22
|
+
@config = Config.new
|
23
|
+
instance_eval(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def build
|
27
|
+
@config
|
28
|
+
end
|
29
|
+
|
30
|
+
def client_id(client_id)
|
31
|
+
@config.instance_variable_set('@client_id', client_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def client_secret(client_secret)
|
35
|
+
@config.instance_variable_set('@client_secret', client_secret)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module Option
|
40
|
+
def option(name, options = {})
|
41
|
+
attribute = options[:as] || name
|
42
|
+
|
43
|
+
Builder.instance_eval do
|
44
|
+
define_method name do |*args, &block|
|
45
|
+
value = block ? block : args.first
|
46
|
+
|
47
|
+
@config.instance_variable_set(:"@#{attribute}", value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
define_method attribute do |*args|
|
52
|
+
if instance_variable_defined?(:"@#{attribute}")
|
53
|
+
instance_variable_get(:"@#{attribute}")
|
54
|
+
else
|
55
|
+
options[:default]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
public attribute
|
60
|
+
end
|
61
|
+
|
62
|
+
def extended(base)
|
63
|
+
base.send(:private, :option)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
extend Option
|
68
|
+
|
69
|
+
option :token_verify_ttl, default: 10
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
initializer 'capcoauth.params.filter' do |app|
|
4
|
+
parameters = %w'code access_token'
|
5
|
+
app.config.filter_parameters << /^(#{Regexp.union parameters})$/
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer 'capcoauth.routes' do
|
9
|
+
Capcoauth::Rails::Routes.install!
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer 'capcoauth.helpers' do
|
13
|
+
ActiveSupport.on_load(:action_controller) do
|
14
|
+
include Capcoauth::Rails::Helpers
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
module Helpers
|
3
|
+
module Controller
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def capcoauth_token
|
9
|
+
@token ||= OAuth::AccessToken.new(session[:capcoauth_access_token]).verify
|
10
|
+
end
|
11
|
+
|
12
|
+
def oauth_callback_url
|
13
|
+
"#{root_url}auth/callback"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
module OAuth
|
3
|
+
class TokenVerifier
|
4
|
+
def self.verify(access_token)
|
5
|
+
return nil if access_token.blank? or access_token.token.blank?
|
6
|
+
return access_token if TTLCache.valid?(access_token.token)
|
7
|
+
|
8
|
+
# Call Capcoauth
|
9
|
+
response = HTTParty.get('https://capcoauth.capco.com/oauth/token/info', {
|
10
|
+
headers: {
|
11
|
+
'Authorization' => "Bearer #{access_token.token}"
|
12
|
+
}
|
13
|
+
})
|
14
|
+
|
15
|
+
# Set the user_id from the token response
|
16
|
+
if response.code == 200
|
17
|
+
TTLCache.update(access_token.token)
|
18
|
+
access_token.user_id = response.parsed_response['resource_owner_id']
|
19
|
+
access_token
|
20
|
+
else
|
21
|
+
TTLCache.remove(access_token.token)
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
module OAuth
|
3
|
+
class TTLCache
|
4
|
+
@@cache = {}
|
5
|
+
|
6
|
+
def self.valid?(access_token)
|
7
|
+
purge
|
8
|
+
!!@@cache[access_token]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.update(access_token)
|
12
|
+
@@cache[access_token] = Time.zone.now
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.remove(access_token)
|
16
|
+
@@cache.delete(access_token)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.purge
|
20
|
+
@@cache.delete_if do |k, v|
|
21
|
+
Time.zone.now > v + Capcoauth.configuration.token_verify_ttl
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
module Rails
|
3
|
+
module Helpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def verify_authorized!
|
7
|
+
if capcoauth_token
|
8
|
+
session.delete(:previous_url)
|
9
|
+
else
|
10
|
+
session.delete(:capcoauth_access_token)
|
11
|
+
session.delete(:capcoauth_user_id)
|
12
|
+
session[:previous_url] = request.url
|
13
|
+
redirect_to :auth_login
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def capcoauth_token
|
20
|
+
@_capcoauth_token ||= OAuth::AccessToken.new(session[:capcoauth_access_token]).verify
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
module Rails
|
3
|
+
class Routes
|
4
|
+
class Mapper
|
5
|
+
def initialize(mapping = Mapping.new)
|
6
|
+
@mapping = mapping
|
7
|
+
end
|
8
|
+
|
9
|
+
def map(&block)
|
10
|
+
self.instance_eval(&block) if block
|
11
|
+
@mapping
|
12
|
+
end
|
13
|
+
|
14
|
+
def controllers(controller_names = {})
|
15
|
+
@mapping.controllers.merge!(controller_names)
|
16
|
+
end
|
17
|
+
|
18
|
+
def skip_controllers(*controller_names)
|
19
|
+
@mapping.skips = controller_names
|
20
|
+
end
|
21
|
+
|
22
|
+
def as(alias_names = {})
|
23
|
+
@mapping.as.merge!(alias_names)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Capcoauth
|
2
|
+
module Rails
|
3
|
+
class Routes
|
4
|
+
class Mapping
|
5
|
+
attr_accessor :controllers, :as, :skips
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@controllers = {
|
9
|
+
login: 'capcoauth/login',
|
10
|
+
logout: 'capcoauth/logout',
|
11
|
+
callback: 'capcoauth/callback',
|
12
|
+
}
|
13
|
+
|
14
|
+
@as = {
|
15
|
+
login: :login,
|
16
|
+
logout: :logout,
|
17
|
+
callback: :callback
|
18
|
+
}
|
19
|
+
|
20
|
+
@skips = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](routes)
|
24
|
+
{
|
25
|
+
controllers: @controllers[routes],
|
26
|
+
as: @as[routes]
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def skipped?(controller)
|
31
|
+
@skips.include?(controller)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'capcoauth/rails/routes/mapping'
|
2
|
+
require 'capcoauth/rails/routes/mapper'
|
3
|
+
|
4
|
+
module Capcoauth
|
5
|
+
module Rails
|
6
|
+
class Routes
|
7
|
+
module Helper
|
8
|
+
def use_capcoauth(options = {}, &block)
|
9
|
+
Capcoauth::Rails::Routes.new(self, &block).generate_routes!(options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.install!
|
14
|
+
ActionDispatch::Routing::Mapper.send :include, Capcoauth::Rails::Routes::Helper
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_accessor :routes
|
18
|
+
|
19
|
+
def initialize(routes, &block)
|
20
|
+
@routes, @block = routes, block
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_routes!(options)
|
24
|
+
@mapping = Mapper.new.map(&@block)
|
25
|
+
routes.scope options[:scope] || 'auth', as: 'auth' do
|
26
|
+
map_routes(:login, :login_routes)
|
27
|
+
map_routes(:logout, :logout_routes)
|
28
|
+
map_routes(:callback, :callback_routes)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def map_routes(name, method)
|
35
|
+
unless @mapping.skipped?(name)
|
36
|
+
send method, @mapping[name]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def login_routes(mapping)
|
41
|
+
routes.resource(
|
42
|
+
:login,
|
43
|
+
path: 'login',
|
44
|
+
only: [:show], as: mapping[:as],
|
45
|
+
controller: mapping[:controllers]
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def logout_routes(mapping)
|
50
|
+
routes.resource(
|
51
|
+
:logout,
|
52
|
+
path: 'logout',
|
53
|
+
only: [:show, :delete], as: mapping[:as],
|
54
|
+
controller: mapping[:controllers]
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def callback_routes(mapping)
|
59
|
+
routes.resource(
|
60
|
+
:callback,
|
61
|
+
path: 'callback',
|
62
|
+
only: [:show], as: mapping[:as],
|
63
|
+
controller: mapping[:controllers]
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/capcoauth.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'capcoauth/version'
|
2
|
+
require 'capcoauth/engine'
|
3
|
+
require 'capcoauth/config'
|
4
|
+
|
5
|
+
require 'capcoauth/oauth/access_token'
|
6
|
+
require 'capcoauth/oauth/token_verifier'
|
7
|
+
require 'capcoauth/oauth/ttl_cache'
|
8
|
+
|
9
|
+
require 'capcoauth/helpers/controller'
|
10
|
+
|
11
|
+
require 'capcoauth/rails/routes'
|
12
|
+
require 'capcoauth/rails/helpers'
|
13
|
+
|
14
|
+
module Capcoauth
|
15
|
+
def self.configured?
|
16
|
+
@config.present?
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.installed?
|
20
|
+
configured?
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Capcoauth::InstallGenerator < ::Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
desc 'Installs Capcoauth'
|
5
|
+
|
6
|
+
def install
|
7
|
+
template 'initializer.rb', 'config/initializers/capcoauth.rb'
|
8
|
+
route 'use_capcoauth'
|
9
|
+
readme 'README'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
==========================================================================
|
2
|
+
|
3
|
+
Before you can use Capcoauth, you need to enter some configuration details
|
4
|
+
|
5
|
+
* Go to config/initializers/capcoauth.rb and add your client id and secret
|
6
|
+
|
7
|
+
* Add `before_action :verify_authorized!` to your controllers where
|
8
|
+
Necessary. This follows standard `except: [:index]` and
|
9
|
+
`only: [:secret]` Rails ActionController conventions
|
10
|
+
|
11
|
+
Enjoy!
|
12
|
+
|
13
|
+
==========================================================================
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Capcoauth.configure do |config|
|
2
|
+
# CapcOAuth Client ID
|
3
|
+
# config.client_id 'YOUR APPLICATION CLIENT ID'
|
4
|
+
|
5
|
+
# CapcOAuth Client Secret
|
6
|
+
# config.client_secret 'YOUR APPLICATION CLIENT SECRET'
|
7
|
+
|
8
|
+
# Configures how often to check CapcOAuth for access token validity, in seconds. If this value is too high,
|
9
|
+
# application will continue to serve requests to users even after the token is revoked
|
10
|
+
# config.token_verify_ttl 10
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capcoauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.13'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
description: capcoauth-gem is a library to integrate Rails applications with Capcoauth
|
70
|
+
authentication service
|
71
|
+
email:
|
72
|
+
- adam.robertson@capco.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- app/controllers/capcoauth/application_controller.rb
|
82
|
+
- app/controllers/capcoauth/application_metal_controller.rb
|
83
|
+
- app/controllers/capcoauth/callback_controller.rb
|
84
|
+
- app/controllers/capcoauth/login_controller.rb
|
85
|
+
- app/controllers/capcoauth/logout_controller.rb
|
86
|
+
- capcoauth.gemspec
|
87
|
+
- lib/capcoauth.rb
|
88
|
+
- lib/capcoauth/config.rb
|
89
|
+
- lib/capcoauth/engine.rb
|
90
|
+
- lib/capcoauth/helpers/controller.rb
|
91
|
+
- lib/capcoauth/oauth/access_token.rb
|
92
|
+
- lib/capcoauth/oauth/token_verifier.rb
|
93
|
+
- lib/capcoauth/oauth/ttl_cache.rb
|
94
|
+
- lib/capcoauth/rails/helpers.rb
|
95
|
+
- lib/capcoauth/rails/routes.rb
|
96
|
+
- lib/capcoauth/rails/routes/mapper.rb
|
97
|
+
- lib/capcoauth/rails/routes/mapping.rb
|
98
|
+
- lib/capcoauth/version.rb
|
99
|
+
- lib/generators/capcoauth/install_generator.rb
|
100
|
+
- lib/generators/capcoauth/templates/README
|
101
|
+
- lib/generators/capcoauth/templates/initializer.rb
|
102
|
+
homepage: https://github.com/arcreative/capcoauth-gem
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.8
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Integration with Capcoauth authentication service
|
126
|
+
test_files: []
|