devise-archangel 0.0.1

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.
@@ -0,0 +1,10 @@
1
+ test/rails_app/log/*
2
+ test/rails_app/tmp/*
3
+ *~
4
+ coverage/*
5
+ *.sqlite3
6
+ .bundle
7
+ rdoc/*
8
+ pkg
9
+ log
10
+ test/tmp/*
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 3.2.6"
6
+ gem "archangel"
7
+ gem "rdoc"
8
+ gem "devise"
9
+
10
+ platforms :jruby do
11
+ gem "activerecord-jdbc-adapter"
12
+ gem "activerecord-jdbcsqlite3-adapter"
13
+ gem "jruby-openssl"
14
+ end
15
+
16
+ platforms :ruby do
17
+ gem "sqlite3"
18
+
19
+ group :mongoid do
20
+ gem "mongoid", "~> 3.0"
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Xavier Bick
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.
@@ -0,0 +1,5 @@
1
+ ## Devise-Archangel
2
+
3
+ An extension to devise to allow authentication with Archangel.
4
+
5
+ Syntax is the same as using Omniauthable, but Archangelable instead.
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ require 'rdoc/task'
5
+
@@ -0,0 +1,30 @@
1
+ class Devise::ArchangelCallbacksController < DeviseController
2
+ prepend_before_filter { request.env["devise.skip_timeout"] = true }
3
+
4
+ def passthru
5
+ render :status => 404, :text => "Not found. Authentication passthru."
6
+ end
7
+
8
+ def failure
9
+ set_flash_message :alert, :failure, :kind => Archangel::Utils.camelize(failed_strategy.name), :reason => failure_message
10
+ redirect_to after_archangel_failure_path_for(resource_name)
11
+ end
12
+
13
+ protected
14
+
15
+ def failed_strategy
16
+ env["archangel.error.strategy"]
17
+ end
18
+
19
+ def failure_message
20
+ exception = env["archangel.error"]
21
+ error = exception.error_reason if exception.respond_to?(:error_reason)
22
+ error ||= exception.error if exception.respond_to?(:error)
23
+ error ||= env["archangel.error.type"].to_s
24
+ error.to_s.humanize if error
25
+ end
26
+
27
+ def after_archangel_failure_path_for(scope)
28
+ new_session_path(scope)
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ <%- if devise_mapping.archangelable? %>
2
+ <%- resource_class.archangel_providers.each do |provider| %>
3
+ <%= link_to "Sign in with #{provider.to_s.titleize}", archangel_authorize_path(resource_name, provider) %><br />
4
+ <% end -%>
5
+ <% end -%>
@@ -0,0 +1,4 @@
1
+ devise:
2
+ archangel_callbacks:
3
+ success: 'Successfully authenticated from %{kind} account.'
4
+ failure: 'Could not authenticate you from %{kind} because "%{reason}".'
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "devise-archangel"
6
+ s.version = Devise::Archangel::VERSION.dup
7
+ s.platform = Gem::Platform::RUBY
8
+ s.summary = "Extension to devise to allow authentication with Archangel"
9
+ s.email = "fxb9500@gmail.com"
10
+ s.homepage = "http://github.com/zeiv/devise-archangel"
11
+ s.description = "Extension to devise to allow authentication with Archangel"
12
+ s.authors = ['Xavier Bick']
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- test/*`.split("\n")
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_dependency("devise")
19
+ end
@@ -0,0 +1,33 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "devise-archangel", :path => ".."
4
+
5
+ gem "rails", "~> 3.1.0"
6
+ gem "devise"
7
+ gem "archangel"
8
+ gem "rdoc"
9
+
10
+ group :test do
11
+ gem "archangel"
12
+ gem "omniauth-openid", "~> 1.0.1"
13
+ gem "webrat", "0.7.2", :require => false
14
+ gem "mocha", :require => false
15
+
16
+ platforms :mri_18 do
17
+ gem "ruby-debug", ">= 0.10.3"
18
+ end
19
+ end
20
+
21
+ platforms :jruby do
22
+ gem "activerecord-jdbc-adapter"
23
+ gem "activerecord-jdbcsqlite3-adapter"
24
+ gem "jruby-openssl"
25
+ end
26
+
27
+ platforms :ruby do
28
+ gem "sqlite3"
29
+
30
+ group :mongoid do
31
+ gem "mongoid", "~> 3.0"
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require 'devise/archangel'
@@ -0,0 +1,54 @@
1
+ begin
2
+ require "archangel"
3
+ require "archangel/version"
4
+ rescue LoadError
5
+ warn "Could not load 'archangel'. Please ensure you have the archangel gem >= 0.0.3 installed and listed in your Gemfile."
6
+ raise
7
+ end
8
+
9
+ #~ unless Archangel::VERSION =~ /^1\./
10
+ #~ raise "You are using an old Archangel version, please ensure you have 0.0.3 version or later installed."
11
+ #~ end
12
+
13
+ # Clean up the default path_prefix. It will be automatically set by Devise.
14
+ Archangel.config.path_prefix = nil
15
+
16
+ Archangel.config.on_failure = Proc.new do |env|
17
+ env['devise.mapping'] = Devise::Mapping.find_by_path!(env['PATH_INFO'], :path)
18
+ controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:archangel_callbacks])
19
+ controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
20
+ controller_klass.action(:failure).call(env)
21
+ end
22
+
23
+ module Devise
24
+
25
+ # Set the archangel path prefix so it can be overriden when
26
+ # Devise is used in a mountable engine
27
+ mattr_accessor :archangel_path_prefix
28
+ @@archangel_path_prefix = nil
29
+
30
+ # archangel configurations.
31
+ mattr_reader :archangel_configs
32
+ @@archangel_configs = ActiveSupport::OrderedHash.new
33
+
34
+ def self.archangel_providers
35
+ archangel_configs.keys
36
+ end
37
+
38
+ # Specify an archangel provider.
39
+ #
40
+ # config.archangel :github, APP_ID, APP_SECRET
41
+ #
42
+ def self.archangel(provider, *args)
43
+ @@helpers << Devise::Archangel::UrlHelpers
44
+ config = Devise::Archangel::Config.new(provider, args)
45
+ @@archangel_configs[config.strategy_name.to_sym] = config
46
+ end
47
+
48
+ module Archangel
49
+ autoload :Config, "devise/archangel/config"
50
+ autoload :UrlHelpers, "devise/archangel/url_helpers"
51
+ end
52
+ end
53
+
54
+ Devise.add_module(:archangelable, :controller => :archangel_callbacks, :route => :archangel_callback)
@@ -0,0 +1,45 @@
1
+ module Devise
2
+ module Archangel
3
+ class StrategyNotFound < NameError
4
+ def initialize(strategy)
5
+ @strategy = strategy
6
+ super("Could not find a strategy with name `#{strategy}'. " \
7
+ "Please ensure it is required or explicitly set it using the :strategy_class option.")
8
+ end
9
+ end
10
+
11
+ class Config
12
+ attr_accessor :strategy
13
+ attr_reader :args, :options, :provider, :strategy_name
14
+
15
+ def initialize(provider, args)
16
+ @provider = provider
17
+ @args = args
18
+ @options = @args.last.is_a?(Hash) ? @args.last : {}
19
+ @strategy = nil
20
+ @strategy_name = options[:name] || @provider
21
+ @strategy_class = options.delete(:strategy_class)
22
+ end
23
+
24
+ def strategy_class
25
+ @strategy_class ||= find_strategy || autoload_strategy
26
+ end
27
+
28
+ def find_strategy
29
+ ::Archangel.strategies.find do |strategy_class|
30
+ strategy_class.to_s =~ /#{::Archangel::Utils.camelize(strategy_name)}$/ ||
31
+ strategy_class.default_options[:name] == strategy_name
32
+ end
33
+ end
34
+
35
+ def autoload_strategy
36
+ name = ::Archangel::Utils.camelize(provider.to_s)
37
+ if ::Archangel::Strategies.const_defined?(name)
38
+ ::Archangel::Strategies.const_get(name)
39
+ else
40
+ raise StrategyNotFound, name
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ module Devise
2
+ module Archangel
3
+ module UrlHelpers
4
+ def self.define_helpers(mapping)
5
+ end
6
+
7
+ def archangel_authorize_path(resource_or_scope, *args)
8
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
9
+ send("#{scope}_archangel_authorize_path", *args)
10
+ end
11
+
12
+ def archangel_callback_path(resource_or_scope, *args)
13
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
14
+ send("#{scope}_archangel_callback_path", *args)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require 'devise/archangel'
2
+
3
+ module Devise
4
+ module Models
5
+ # Adds Archangel support to your model.
6
+ #
7
+ # == Options
8
+ #
9
+ # Oauthable adds the following options to devise_for:
10
+ #
11
+ # * +archangel_providers+: Which providers are avaialble to this model. It expects an array:
12
+ #
13
+ # devise_for :database_authenticatable, :archangelable, :archangel_providers => [:twitter]
14
+ #
15
+ module Archangelable
16
+ extend ActiveSupport::Concern
17
+
18
+ def self.required_fields(klass)
19
+ []
20
+ end
21
+
22
+ module ClassMethods
23
+ Devise::Models.config(self, :archangel_providers)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'devise/rails/routes'
2
+
3
+ module Devise
4
+ class Engine < ::Rails::Engine
5
+
6
+ initializer "devise.archangel" do |app|
7
+ Devise.archangel_configs.each do |provider, config|
8
+ app.middleware.use config.strategy_class, *config.args do |strategy|
9
+ config.strategy = strategy
10
+ end
11
+ end
12
+
13
+ if Devise.archangel_configs.any?
14
+ Devise.include_helpers(Devise::Archangel)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+ alias :as :devise_scope
4
+
5
+ protected
6
+
7
+ def devise_archangel_callback(mapping, controllers) #:nodoc:
8
+ path, @scope[:path] = @scope[:path], nil
9
+ path_prefix = Devise.archangel_path_prefix || "/#{mapping.path}/auth".squeeze("/")
10
+ set_archangel_path_prefix!(path_prefix)
11
+
12
+ providers = Regexp.union(mapping.to.archangel_providers.map(&:to_s))
13
+
14
+ match "#{path_prefix}/:provider",
15
+ :constraints => { :provider => providers },
16
+ :to => "#{controllers[:archangel_callbacks]}#passthru",
17
+ :as => :archangel_authorize
18
+
19
+ match "#{path_prefix}/:action/callback",
20
+ :constraints => { :action => providers },
21
+ :to => controllers[:archangel_callbacks],
22
+ :as => :archangel_callback
23
+ ensure
24
+ @scope[:path] = path
25
+ end
26
+
27
+ def set_archangel_path_prefix!(path_prefix) #:nodoc:
28
+ if ::Archangel.config.path_prefix && ::Archangel.config.path_prefix != path_prefix
29
+ raise "Wrong Archangel configuration. If you are getting this exception, it means that either:\n\n" \
30
+ "1) You are manually setting Archangel.config.path_prefix and it doesn't match the Devise one\n" \
31
+ "2) You are setting :archangelable in more than one model\n" \
32
+ "3) You changed your Devise routes/Archangel setting and haven't restarted your server"
33
+ else
34
+ ::Archangel.config.path_prefix = path_prefix
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ # ==> Archangel
5
+ # Add a new Archangel provider. Check the wiki for more information on setting
6
+ # up on your models and hooks.
7
+ # config.archangel :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
8
+ end
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module Archangel
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-archangel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Xavier Bick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Extension to devise to allow authentication with Archangel
31
+ email: fxb9500@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - MIT-LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - app/controllers/devise/archangel_callbacks_controller.rb
42
+ - app/views/devise/shared/_links.erb
43
+ - config/locales/en.yml
44
+ - devise-archangel.gemspec
45
+ - gemfiles/Gemfile.rails-3.1.x
46
+ - lib/devise-archangel.rb
47
+ - lib/devise/archangel.rb
48
+ - lib/devise/archangel/config.rb
49
+ - lib/devise/archangel/url_helpers.rb
50
+ - lib/devise/models/archangelable.rb
51
+ - lib/devise/rails.rb
52
+ - lib/devise/rails/routes.rb
53
+ - lib/generators/templates/devise.rb
54
+ - lib/version.rb
55
+ homepage: http://github.com/zeiv/devise-archangel
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.24
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Extension to devise to allow authentication with Archangel
79
+ test_files: []
80
+ has_rdoc: