easy_auth-oauth 0.0.2
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.
- data/README.md +51 -0
- data/Rakefile +7 -0
- data/app/models/identities/oauth/base.rb +3 -0
- data/lib/easy_auth-oauth.rb +1 -0
- data/lib/easy_auth/models/identities/oauth.rb +4 -0
- data/lib/easy_auth/models/identities/oauth/base.rb +100 -0
- data/lib/easy_auth/oauth.rb +51 -0
- data/lib/easy_auth/oauth/controllers.rb +4 -0
- data/lib/easy_auth/oauth/controllers/sessions.rb +16 -0
- data/lib/easy_auth/oauth/engine.rb +9 -0
- data/lib/easy_auth/oauth/models.rb +5 -0
- data/lib/easy_auth/oauth/models/account.rb +7 -0
- data/lib/easy_auth/oauth/routes.rb +6 -0
- data/lib/easy_auth/oauth/version.rb +5 -0
- metadata +196 -0
data/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# EasyAuth-Oauth #
|
|
2
|
+
|
|
3
|
+
[](http://travis-ci.org/dockyard/easy_auth-oauth)
|
|
4
|
+
[](https://gemnasium.com/dockyard/easy_auth-oauth)
|
|
5
|
+
[](https://codeclimate.com/github/dockyard/easy_auth-oauth)
|
|
6
|
+
|
|
7
|
+
Dead simple drop in authentication for Rails
|
|
8
|
+
|
|
9
|
+
## Installation ##
|
|
10
|
+
|
|
11
|
+
In your Gemfile add the following:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'easy_auth-oauth'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
After running Bundler you'll need to install the migrations
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
rake easy_auth-oauth:install:migrations
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then run your migrations.
|
|
24
|
+
|
|
25
|
+
## Authors ##
|
|
26
|
+
|
|
27
|
+
[Brian Cardarella](http://twitter.com/bcardarella)
|
|
28
|
+
|
|
29
|
+
## Versioning ##
|
|
30
|
+
|
|
31
|
+
This gem follows [Semantic Versioning](http://semver.org)
|
|
32
|
+
|
|
33
|
+
## Want to help? ##
|
|
34
|
+
|
|
35
|
+
Stable branches are created based upon each minor version. Please make
|
|
36
|
+
pull requests to specific branches rather than master.
|
|
37
|
+
|
|
38
|
+
Please make sure you include tests!
|
|
39
|
+
|
|
40
|
+
Unles Rails drops support for Ruby 1.8.7 we will continue to use the
|
|
41
|
+
hash-rocket syntax. Please respect this.
|
|
42
|
+
|
|
43
|
+
Don't use tabs to indent, two spaces are the standard.
|
|
44
|
+
|
|
45
|
+
## Legal ##
|
|
46
|
+
|
|
47
|
+
[DockYard](http://dockyard.com), LLC © 2012
|
|
48
|
+
|
|
49
|
+
[@dockyard](http://twitter.com/dockyard)
|
|
50
|
+
|
|
51
|
+
[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'easy_auth/oauth'
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'oauth'
|
|
2
|
+
|
|
3
|
+
module EasyAuth::Models::Identities::Oauth::Base
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.class_eval do
|
|
6
|
+
serialize :token, Hash
|
|
7
|
+
extend ClassMethods
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module ClassMethods
|
|
12
|
+
def authenticate(controller)
|
|
13
|
+
oauth_token = controller.params[:oauth_token]
|
|
14
|
+
oauth_verifier = controller.params[:oauth_verifier]
|
|
15
|
+
access_token_secret = controller.session.delete('access_token_secret')
|
|
16
|
+
request_token = OAuth::RequestToken.new(client, oauth_token, access_token_secret)
|
|
17
|
+
token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
|
|
18
|
+
username = retrieve_username(token)
|
|
19
|
+
identity = self.find_or_initialize_by_username username.to_s
|
|
20
|
+
identity.token = {:token => token.token, :secret => token.secret}
|
|
21
|
+
account = controller.current_account
|
|
22
|
+
|
|
23
|
+
if identity.new_record?
|
|
24
|
+
account = EasyAuth.account_model.create(EasyAuth.account_model.identity_username_attribute => identity.username) if account.nil?
|
|
25
|
+
identity.account = account
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
identity.save!
|
|
29
|
+
identity
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def new_session(controller)
|
|
33
|
+
controller.redirect_to authenticate_url(controller.oauth_callback_url(:provider => provider), controller.session)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get_access_token(identity)
|
|
37
|
+
::OAuth::AccessToken.new client, identity.token[:token], identity.token[:secret]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def token_options(callback_url)
|
|
43
|
+
{ :redirect_uri => callback_url }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def client_options
|
|
47
|
+
{ :site => site_url, :authorize_path => authorize_path }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def provider
|
|
51
|
+
raise NotImplementedError
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def retrieve_username(token)
|
|
55
|
+
raise NotImplementedError
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def client
|
|
59
|
+
@client ||= ::OAuth::Consumer.new(client_id, secret, client_options)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def authenticate_url(callback_url, session)
|
|
63
|
+
request_token = client.get_request_token(:oauth_callback => callback_url)
|
|
64
|
+
session['access_token_secret'] = request_token.secret
|
|
65
|
+
request_token.authorize_url(:oauth_callback => callback_url)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def authorize_path
|
|
69
|
+
raise NotImplementedError
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def site_url
|
|
73
|
+
raise NotImplementedError
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def scope
|
|
77
|
+
settings.scope
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def client_id
|
|
81
|
+
settings.client_id
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def secret
|
|
85
|
+
settings.secret
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def settings
|
|
89
|
+
EasyAuth.oauth[provider]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def provider
|
|
93
|
+
self.to_s.split('::').last.underscore.to_sym
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def get_access_token
|
|
98
|
+
self.class.get_access_token self
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'easy_auth'
|
|
2
|
+
require 'easy_auth/oauth/engine'
|
|
3
|
+
require 'easy_auth/oauth/version'
|
|
4
|
+
|
|
5
|
+
module EasyAuth
|
|
6
|
+
|
|
7
|
+
module Oauth
|
|
8
|
+
extend ActiveSupport::Autoload
|
|
9
|
+
autoload :Controllers
|
|
10
|
+
autoload :Models
|
|
11
|
+
autoload :Routes
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module Models
|
|
15
|
+
module Account
|
|
16
|
+
include EasyAuth::Oauth::Models::Account
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Identities
|
|
20
|
+
autoload :Oauth
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module Controllers::Sessions
|
|
25
|
+
include EasyAuth::Oauth::Controllers::Sessions
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.oauth_identity_model(params)
|
|
29
|
+
method_name = "oauth_#{params[:provider]}_identity_model"
|
|
30
|
+
camelcased_provider_name = params[:provider].to_s.camelcase
|
|
31
|
+
if respond_to?(method_name)
|
|
32
|
+
send(method_name, params)
|
|
33
|
+
elsif eval("defined?(Identities::Oauth::#{camelcased_provider_name})")
|
|
34
|
+
eval("Identities::Oauth::#{camelcased_provider_name}")
|
|
35
|
+
else
|
|
36
|
+
camelcased_provider_name.constantize
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class << self
|
|
41
|
+
attr_accessor :oauth
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
self.oauth = {}
|
|
45
|
+
|
|
46
|
+
def self.oauth_client(provider, client_id, secret, scope = '')
|
|
47
|
+
oauth[provider] = OpenStruct.new :client_id => client_id, :secret => secret, :scope => scope || ''
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
ActionDispatch::Routing::Mapper.send(:include, EasyAuth::Oauth::Routes)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module EasyAuth::Oauth::Controllers::Sessions
|
|
2
|
+
|
|
3
|
+
private
|
|
4
|
+
|
|
5
|
+
def after_successful_sign_in_with_oauth(identity)
|
|
6
|
+
send("after_successful_sign_in_with_oauth_for_#{params[:provider]}", identity)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def after_successful_sign_in_url_with_oauth(identity)
|
|
10
|
+
send("after_successful_sign_in_url_with_oauth_for_#{params[:provider]}", identity)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def after_failed_sign_in_with_oauth(identity)
|
|
14
|
+
send("after_failed_sign_in_with_oauth_for_#{params[:provider]}", identity)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
module EasyAuth::Oauth::Routes
|
|
2
|
+
def easy_auth_oauth_routes
|
|
3
|
+
get '/sign_in/oauth/:provider' => 'sessions#new', :as => :oauth_sign_in, :defaults => { :identity => :oauth }
|
|
4
|
+
get '/sign_in/oauth/:provider/callback' => 'sessions#create', :as => :oauth_callback, :defaults => { :identity => :oauth }
|
|
5
|
+
end
|
|
6
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: easy_auth-oauth
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Brian Cardarella
|
|
9
|
+
- Dan McClain
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2012-11-05 00:00:00.000000000 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: easy_auth
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - ~>
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.2.0
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
none: false
|
|
27
|
+
requirements:
|
|
28
|
+
- - ~>
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
version: 0.2.0
|
|
31
|
+
- !ruby/object:Gem::Dependency
|
|
32
|
+
name: oauth
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
34
|
+
none: false
|
|
35
|
+
requirements:
|
|
36
|
+
- - ~>
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 0.4.7
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ~>
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.4.7
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: rspec
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ! '>='
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
- !ruby/object:Gem::Dependency
|
|
64
|
+
name: sqlite3
|
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
|
66
|
+
none: false
|
|
67
|
+
requirements:
|
|
68
|
+
- - ! '>='
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
type: :development
|
|
72
|
+
prerelease: false
|
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ! '>='
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
- !ruby/object:Gem::Dependency
|
|
80
|
+
name: database_cleaner
|
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
|
82
|
+
none: false
|
|
83
|
+
requirements:
|
|
84
|
+
- - ! '>='
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '0'
|
|
87
|
+
type: :development
|
|
88
|
+
prerelease: false
|
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
90
|
+
none: false
|
|
91
|
+
requirements:
|
|
92
|
+
- - ! '>='
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
- !ruby/object:Gem::Dependency
|
|
96
|
+
name: valid_attribute
|
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
|
98
|
+
none: false
|
|
99
|
+
requirements:
|
|
100
|
+
- - ! '>='
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
none: false
|
|
107
|
+
requirements:
|
|
108
|
+
- - ! '>='
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: factory_girl
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
none: false
|
|
115
|
+
requirements:
|
|
116
|
+
- - ~>
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: 2.6.0
|
|
119
|
+
type: :development
|
|
120
|
+
prerelease: false
|
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
+
none: false
|
|
123
|
+
requirements:
|
|
124
|
+
- - ~>
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: 2.6.0
|
|
127
|
+
- !ruby/object:Gem::Dependency
|
|
128
|
+
name: bourne
|
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
|
130
|
+
none: false
|
|
131
|
+
requirements:
|
|
132
|
+
- - ! '>='
|
|
133
|
+
- !ruby/object:Gem::Version
|
|
134
|
+
version: '0'
|
|
135
|
+
type: :development
|
|
136
|
+
prerelease: false
|
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
138
|
+
none: false
|
|
139
|
+
requirements:
|
|
140
|
+
- - ! '>='
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
description: EasyAuth-Oauth
|
|
144
|
+
email:
|
|
145
|
+
- brian@dockyard.com
|
|
146
|
+
- bcardarella@gmail.com
|
|
147
|
+
- rubygems@danmcclain.net
|
|
148
|
+
executables: []
|
|
149
|
+
extensions: []
|
|
150
|
+
extra_rdoc_files: []
|
|
151
|
+
files:
|
|
152
|
+
- app/models/identities/oauth/base.rb
|
|
153
|
+
- lib/easy_auth/models/identities/oauth/base.rb
|
|
154
|
+
- lib/easy_auth/models/identities/oauth.rb
|
|
155
|
+
- lib/easy_auth/oauth/controllers/sessions.rb
|
|
156
|
+
- lib/easy_auth/oauth/controllers.rb
|
|
157
|
+
- lib/easy_auth/oauth/engine.rb
|
|
158
|
+
- lib/easy_auth/oauth/models/account.rb
|
|
159
|
+
- lib/easy_auth/oauth/models.rb
|
|
160
|
+
- lib/easy_auth/oauth/routes.rb
|
|
161
|
+
- lib/easy_auth/oauth/version.rb
|
|
162
|
+
- lib/easy_auth/oauth.rb
|
|
163
|
+
- lib/easy_auth-oauth.rb
|
|
164
|
+
- Rakefile
|
|
165
|
+
- README.md
|
|
166
|
+
homepage: https://github.com/dockyard/easy_auth-oauth
|
|
167
|
+
licenses: []
|
|
168
|
+
post_install_message:
|
|
169
|
+
rdoc_options: []
|
|
170
|
+
require_paths:
|
|
171
|
+
- lib
|
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
|
+
none: false
|
|
174
|
+
requirements:
|
|
175
|
+
- - ! '>='
|
|
176
|
+
- !ruby/object:Gem::Version
|
|
177
|
+
version: '0'
|
|
178
|
+
segments:
|
|
179
|
+
- 0
|
|
180
|
+
hash: 1374071870890480504
|
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
|
+
none: false
|
|
183
|
+
requirements:
|
|
184
|
+
- - ! '>='
|
|
185
|
+
- !ruby/object:Gem::Version
|
|
186
|
+
version: '0'
|
|
187
|
+
segments:
|
|
188
|
+
- 0
|
|
189
|
+
hash: 1374071870890480504
|
|
190
|
+
requirements: []
|
|
191
|
+
rubyforge_project:
|
|
192
|
+
rubygems_version: 1.8.23
|
|
193
|
+
signing_key:
|
|
194
|
+
specification_version: 3
|
|
195
|
+
summary: EasyAuth-Oauth
|
|
196
|
+
test_files: []
|