uses_openid 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .idea
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uses_openid.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Daniel Vandersluis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # UsesOpenid
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'uses_openid'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install uses_openid
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ require "uses_openid/version"
2
+ require "uses_openid/active_record"
3
+
4
+ module UsesOpenID
5
+ class Railtie < Rails::Railtie
6
+ initializer 'uses_openid.initialize' do
7
+ ActiveSupport.on_load(:active_record) do
8
+ ActiveRecord::Base.send :extend, UsesOpenID::MacroMethods
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ module UsesOpenID
2
+ module MacroMethods
3
+ def uses_openid(options = {})
4
+ extend(ClassMethods)
5
+ include InstanceMethods
6
+ end
7
+ end
8
+
9
+ module ClassMethods
10
+ class OpenIDAuthenticationError < StandardError; end
11
+
12
+ def self.extended(klass)
13
+ # Set up the has_many association
14
+ klass.class_eval %Q{
15
+ @identity_url_class_name = '#{klass.name}IdentityURL'
16
+ has_many :identity_urls, :class_name => @identity_url_class_name, :dependent => :delete_all
17
+ }
18
+ end
19
+
20
+ def authenticate_with_openid(identity_url, user_args = {})
21
+ # Try to find a user from the identity_url
22
+ # If one cannot be found, use the email to find a user.
23
+ # A user can have multiple identity urls. If an unrecognized one is given, it'll be associated with the user
24
+ user_args.symbolize_keys!
25
+ email = user_args[:email]
26
+
27
+ if user = @identity_url_class_name.constantize.find_by_identity_url(identity_url).try(:user)
28
+ # We've already got the identity URL saved
29
+ elsif !email.nil? and user = self.where(user_args).first
30
+ # Save the identity URL for next time
31
+ user.identity_urls.build(:identity_url => identity_url) unless user.identity_urls.where(:identity_url => identity_url).exists?
32
+ user.save(:validate => false) # Don't need to do user validation here
33
+ else
34
+ # We don't have an account for this OpenID
35
+ user = nil
36
+ end
37
+
38
+ user
39
+ end
40
+ end
41
+
42
+ module InstanceMethods
43
+ def openid_user?
44
+ password.nil? and !identity_urls.empty?
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module UsesOpenID
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uses_openid/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "uses_openid"
8
+ gem.version = UsesOpenID::VERSION
9
+ gem.authors = ["Daniel Vandersluis"]
10
+ gem.email = ["dvandersluis@selfmgmt.com"]
11
+ gem.description = %q{Adds some OpenID authentication methods to an ActiveRecord model}
12
+ gem.summary = %q{Adds some OpenID authentication methods to an ActiveRecord model}
13
+ gem.homepage = "https://github.com/talentnest/uses_openid"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "activerecord", "> 3.0.0"
21
+ gem.add_dependency "activesupport", "> 3.0.0"
22
+ gem.add_dependency "railties", "> 3.0.0"
23
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uses_openid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Vandersluis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ none: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>'
27
+ - !ruby/object:Gem::Version
28
+ version: 3.0.0
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>'
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ none: false
39
+ type: :runtime
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>'
43
+ - !ruby/object:Gem::Version
44
+ version: 3.0.0
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: railties
48
+ prerelease: false
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>'
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.0
54
+ none: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>'
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.0
61
+ none: false
62
+ description: Adds some OpenID authentication methods to an ActiveRecord model
63
+ email:
64
+ - dvandersluis@selfmgmt.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/uses_openid.rb
75
+ - lib/uses_openid/active_record.rb
76
+ - lib/uses_openid/version.rb
77
+ - uses_openid.gemspec
78
+ homepage: https://github.com/talentnest/uses_openid
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ none: false
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ none: false
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Adds some OpenID authentication methods to an ActiveRecord model
102
+ test_files: []
103
+ has_rdoc: