nielsm-authlogic_haapi 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,4 @@
1
+
2
+ == 1.0.0 released 2009-07-04
3
+
4
+ * Initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Joe Scharf of QuantiPay (quantipay.com)
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/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ CHANGELOG.rdoc
2
+ MIT-LICENSE
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ init.rb
7
+ lib/authlogic_haapi.rb
8
+ lib/authlogic_haapi/session.rb
9
+ lib/authlogic_haapi/version.rb
10
+ test/fixtures/users.yml
11
+ test/libs/rails_trickery.rb
12
+ test/libs/user.rb
13
+ test/libs/user_session.rb
14
+ test/session_test.rb
15
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,47 @@
1
+ = Authlogic Haapi (Http Auth API)
2
+
3
+ Authlogic Haapi Adds support for HTTP Authentication with an API key instead of username password. You can use it with Active Resource
4
+ like so:
5
+
6
+ require 'rubygems'
7
+ require 'activeresource'
8
+
9
+ API_KEY= 'YourApiKeyHere'
10
+ URL = 'example.com'
11
+
12
+ class Api < ActiveResource::Base
13
+ self.site = URL
14
+ self.user = API_KEY
15
+ end
16
+
17
+ class User < Api
18
+ end
19
+
20
+ users = User.find(:all)
21
+
22
+
23
+ Credits go to Matthew and Saro at http://matthewtodd.org/2009/02/19/using-authlogic-and-active_resource.html for inspiration and guidance.
24
+
25
+ == Helpful links
26
+
27
+ * <b>Authlogic:</b> http://github.com/binarylogic/authlogic
28
+
29
+ == Install and use
30
+
31
+ === 1. Install the Authlogic Haapi gem
32
+
33
+ $ sudo gem install quantipay-authlogic_haapi
34
+
35
+ Now add the gem dependency in your config:
36
+
37
+ config.gem "quantipay-authlogic_haapi", :lib => "authlogic_haapi"
38
+
39
+ Or for older version of rails, install it as a plugin:
40
+
41
+ $ script/plugin install git://github.com/quantipay/authlogic_haapi.git
42
+
43
+ === 2. Configuration options:
44
+
45
+ <b>allow_http_basic_auth_with_api_key, default = true</b> Indicates whether you wish to allow logging in by HTTP Auth using the API Key.
46
+
47
+ Copyright (c) 2009 Joe Scharf of [QuantiPay](http://quantipay.com), released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ ENV['RDOCOPT'] = "-S -f html -T hanna"
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gemspec|
9
+ gemspec.name = "authlogic_haapi"
10
+ gemspec.summary = "Extension of the Authlogic library to add support for HTTP Auth with API Key (single access token)"
11
+ gemspec.email = "joe@quantipay.com"
12
+ gemspec.homepage = "http://github.com/quantipay/authlogic_haapi"
13
+ gemspec.description = "This gem Extends the Authlogic library and allows using an API key (single access token) with active resource as the login method"
14
+ gemspec.authors = ["Joe Scharf"]
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 0
4
+ :patch: 3
@@ -0,0 +1,58 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{nielsm-authlogic_haapi}
5
+ s.version = "1.0.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Joe Scharf"]
9
+ s.date = %q{2009-07-04}
10
+ s.description = %q{This gem Extends the Authlogic library and allows using an API key (single access token) with active resource as the login method}
11
+ s.email = %q{joe@quantipay.com}
12
+ s.extra_rdoc_files = [
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "CHANGELOG.rdoc",
18
+ "MIT-LICENSE",
19
+ "Manifest.txt",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION.yml",
23
+ "authlogic_haapi.gemspec",
24
+ "init.rb",
25
+ "lib/authlogic_haapi.rb",
26
+ "lib/authlogic_haapi/session.rb",
27
+ "lib/authlogic_haapi/version.rb",
28
+ "rails/init.rb",
29
+ "test/fixtures/users.yml",
30
+ "test/libs/rails_trickery.rb",
31
+ "test/libs/user.rb",
32
+ "test/libs/user_session.rb",
33
+ "test/session_test.rb",
34
+ "test/test_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/quantipay/authlogic_haapi}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.4}
40
+ s.summary = %q{Extension of the Authlogic library to add support for HTTP Auth with API Key (single access token)}
41
+ s.test_files = [
42
+ "test/libs/rails_trickery.rb",
43
+ "test/libs/user.rb",
44
+ "test/libs/user_session.rb",
45
+ "test/session_test.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ else
55
+ end
56
+ else
57
+ end
58
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init.rb"
@@ -0,0 +1,5 @@
1
+ require 'authlogic'
2
+ require "authlogic_haapi/version"
3
+ require "authlogic_haapi/session"
4
+
5
+ Authlogic::Session::Base.send(:include, AuthlogicHaapi::Session)
@@ -0,0 +1,45 @@
1
+ module AuthlogicHaapi
2
+ # This module is responsible for allowing login via HTTP Auth using an API Key (Single access token)
3
+ module Session
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ extend Config
7
+ include Methods
8
+ persist :persist_by_http_auth_with_api_key, :if => :persist_by_http_auth_with_api_key?
9
+ end
10
+ end
11
+
12
+ module Config
13
+ # Do you want to allow your users to log in via HTTP basic auth using an API Key (single access token)?
14
+ #
15
+ #
16
+ # * <tt>Default:</tt> true
17
+ # * <tt>Accepts:</tt> Boolean
18
+ def allow_http_basic_auth_with_api_key(value = nil)
19
+ rw_config(:allow_http_basic_auth_with_api_key, value, true)
20
+ end
21
+ alias_method :allow_http_basic_auth_with_api_key=, :allow_http_basic_auth_with_api_key
22
+ end
23
+
24
+ module Methods
25
+
26
+ private
27
+ def persist_by_http_auth_with_api_key?
28
+ allow_http_basic_auth_with_api_key?
29
+ end
30
+
31
+ def persist_by_http_auth_with_api_key
32
+ controller.authenticate_with_http_basic do |api_key,_|
33
+ self.unauthorized_record = search_for_record("find_by_single_access_token", api_key)
34
+ self.valid?
35
+ end
36
+ false
37
+ end
38
+
39
+ def allow_http_basic_auth_with_api_key?
40
+ self.class.allow_http_basic_auth_with_api_key == true
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
1
+ module AuthlogicHaapi
2
+ # A class for describing the current version of a library. The version
3
+ # consists of three parts: the +major+ number, the +minor+ number, and the
4
+ # +tiny+ (or +patch+) number.
5
+ class Version
6
+ include Comparable
7
+
8
+ # A convenience method for instantiating a new Version instance with the
9
+ # given +major+, +minor+, and +tiny+ components.
10
+ def self.[](major, minor, tiny)
11
+ new(major, minor, tiny)
12
+ end
13
+
14
+ attr_reader :major, :minor, :tiny
15
+
16
+ # Create a new Version object with the given components.
17
+ def initialize(major, minor, tiny)
18
+ @major, @minor, @tiny = major, minor, tiny
19
+ end
20
+
21
+ # Compare this version to the given +version+ object.
22
+ def <=>(version)
23
+ to_i <=> version.to_i
24
+ end
25
+
26
+ # Converts this version object to a string, where each of the three
27
+ # version components are joined by the '.' character. E.g., 2.0.0.
28
+ def to_s
29
+ @to_s ||= [@major, @minor, @tiny].join(".")
30
+ end
31
+
32
+ # Converts this version to a canonical integer that may be compared
33
+ # against other version objects.
34
+ def to_i
35
+ @to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
36
+ end
37
+
38
+ def to_a
39
+ [@major, @minor, @tiny]
40
+ end
41
+
42
+ MAJOR = 1
43
+ MINOR = 0
44
+ TINY = 0
45
+
46
+ # The current version as a Version instance
47
+ CURRENT = new(MAJOR, MINOR, TINY)
48
+ # The current version as a String
49
+ STRING = CURRENT.to_s
50
+ end
51
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "authlogic_haapi"
@@ -0,0 +1,9 @@
1
+ ben:
2
+ login: bjohnson
3
+ persistence_token: 6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317
4
+ single_access_token: <%= Authlogic::Random.friendly_token %>
5
+ perishable_token: <%= Authlogic::Random.friendly_token %>
6
+ openid_identifier: bens_identifier
7
+ email: bjohnson@binarylogic.com
8
+ first_name: Ben
9
+ last_name: Johnson
@@ -0,0 +1,41 @@
1
+ # The only reason I am doing all of this non sense is becuase the openid_authentication requires that
2
+ # these constants be present. The only other alternative is to use an entire rails application for testing
3
+ # which is a little too overboard for this, I think.
4
+
5
+ RAILS_ROOT = ''
6
+
7
+ class ActionController < Authlogic::TestCase::MockController
8
+ class Request < Authlogic::TestCase::MockRequest
9
+ def request_method
10
+ ""
11
+ end
12
+ end
13
+
14
+ def root_url
15
+ ''
16
+ end
17
+
18
+ def request
19
+ return @request if defined?(@request)
20
+ super
21
+ # Rails does some crazy s#!t with the "method" method. If I don't do this I get a "wrong arguments (0 for 1) error"
22
+ @request.class.class_eval do
23
+ def method
24
+ nil
25
+ end
26
+ end
27
+ @request
28
+ end
29
+
30
+ def url_for(*args)
31
+ ''
32
+ end
33
+
34
+ def redirecting_to
35
+ @redirect_to
36
+ end
37
+
38
+ def redirect_to(*args)
39
+ @redirect_to = args
40
+ end
41
+ end
data/test/libs/user.rb ADDED
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_authentic
3
+ end
@@ -0,0 +1,2 @@
1
+ class UserSession < Authlogic::Session::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class SessionTest < ActiveSupport::TestCase
4
+ end
@@ -0,0 +1,71 @@
1
+ require "test/unit"
2
+ require "rubygems"
3
+ require "ruby-debug"
4
+ require "active_record"
5
+
6
+ ActiveRecord::Schema.verbose = false
7
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
8
+ ActiveRecord::Base.configurations = true
9
+ ActiveRecord::Schema.define(:version => 1) do
10
+ create_table :open_id_authentication_associations, :force => true do |t|
11
+ t.integer :issued, :lifetime
12
+ t.string :handle, :assoc_type
13
+ t.binary :server_url, :secret
14
+ end
15
+
16
+ create_table :open_id_authentication_nonces, :force => true do |t|
17
+ t.integer :timestamp, :null => false
18
+ t.string :server_url, :null => true
19
+ t.string :salt, :null => false
20
+ end
21
+
22
+ create_table :users do |t|
23
+ t.datetime :created_at
24
+ t.datetime :updated_at
25
+ t.integer :lock_version, :default => 0
26
+ t.string :login
27
+ t.string :crypted_password
28
+ t.string :password_salt
29
+ t.string :persistence_token
30
+ t.string :single_access_token
31
+ t.string :perishable_token
32
+ t.string :openid_identifier
33
+ t.string :email
34
+ t.string :first_name
35
+ t.string :last_name
36
+ t.integer :login_count, :default => 0, :null => false
37
+ t.integer :failed_login_count, :default => 0, :null => false
38
+ t.datetime :last_request_at
39
+ t.datetime :current_login_at
40
+ t.datetime :last_login_at
41
+ t.string :current_login_ip
42
+ t.string :last_login_ip
43
+ end
44
+ end
45
+
46
+ require "active_record/fixtures"
47
+ Rails = true # to trick authlogic into loading the rails adapter
48
+ require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic"
49
+ require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic/test_case"
50
+ #require File.dirname(__FILE__) + "/libs/rails_trickery"
51
+ require File.dirname(__FILE__) + '/libs/user'
52
+ require File.dirname(__FILE__) + '/libs/user_session'
53
+
54
+ class ActiveSupport::TestCase
55
+ include ActiveRecord::TestFixtures
56
+ self.fixture_path = File.dirname(__FILE__) + "/fixtures"
57
+ self.use_transactional_fixtures = false
58
+ self.use_instantiated_fixtures = false
59
+ self.pre_loaded_fixtures = false
60
+ fixtures :all
61
+ setup :activate_authlogic
62
+
63
+ private
64
+ def activate_authlogic
65
+ Authlogic::Session::Base.controller = controller
66
+ end
67
+
68
+ def controller
69
+ @controller ||= Authlogic::ControllerAdapters::RailsAdapter.new(ActionController.new)
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nielsm-authlogic_haapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Joe Scharf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-04 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: This gem Extends the Authlogic library and allows using an API key (single access token) with active resource as the login method
17
+ email: joe@quantipay.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - .gitignore
26
+ - CHANGELOG.rdoc
27
+ - MIT-LICENSE
28
+ - Manifest.txt
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION.yml
32
+ - authlogic_haapi.gemspec
33
+ - init.rb
34
+ - lib/authlogic_haapi.rb
35
+ - lib/authlogic_haapi/session.rb
36
+ - lib/authlogic_haapi/version.rb
37
+ - rails/init.rb
38
+ - test/fixtures/users.yml
39
+ - test/libs/rails_trickery.rb
40
+ - test/libs/user.rb
41
+ - test/libs/user_session.rb
42
+ - test/session_test.rb
43
+ - test/test_helper.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/quantipay/authlogic_haapi
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Extension of the Authlogic library to add support for HTTP Auth with API Key (single access token)
72
+ test_files:
73
+ - test/libs/rails_trickery.rb
74
+ - test/libs/user.rb
75
+ - test/libs/user_session.rb
76
+ - test/session_test.rb
77
+ - test/test_helper.rb