easy_auth-oauth_core 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbcdb51bf83787705adef21ff0ccf1779d71cff8
4
+ data.tar.gz: 0a0ea615a7aff3ff818c41db6d47daca656d94f8
5
+ SHA512:
6
+ metadata.gz: 703f1ad050285f0218356d11aa7be83fc7fa4637efc12f70790c6f434730b48167f81f73beb73b3bdb3ec3aa9687c0d9f6df23ded215169756aea08cac1eff8e
7
+ data.tar.gz: 57580881c24a3418a9378c70b6fe35208937e120b0954f8496d5d4c31a770e42331a336e9cc10bfdab1bea80bf5df10410cf3f4bd8814fee181471d4e5e5da6d
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # EasyAuth-OauthCore #
2
+
3
+ Dead simple drop in authentication for Rails
4
+
5
+ ## Installation ##
6
+
7
+ In your Gemfile add the following:
8
+
9
+ ```ruby
10
+ gem 'easy_auth-oauth_core'
11
+ ```
12
+
13
+ Then follow the general installation instructions for
14
+ [EasyAuth](https://github.com/dockyard/easy_auth#installation)
15
+
16
+ ## Authors ##
17
+
18
+ [Brian Cardarella](http://twitter.com/bcardarella)
19
+
20
+ ## Versioning ##
21
+
22
+ This gem follows [Semantic Versioning](http://semver.org)
23
+
24
+ ## Want to help? ##
25
+
26
+ Stable branches are created based upon each minor version. Please make
27
+ pull requests to specific branches rather than master.
28
+
29
+ Please make sure you include tests!
30
+
31
+ Unles Rails drops support for Ruby 1.8.7 we will continue to use the
32
+ hash-rocket syntax. Please respect this.
33
+
34
+ Don't use tabs to indent, two spaces are the standard.
35
+
36
+ ## Legal ##
37
+
38
+ [DockYard](http://dockyard.com), LLC © 2012
39
+
40
+ [@dockyard](http://twitter.com/dockyard)
41
+
42
+ [Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,118 @@
1
+ module EasyAuth::Models::Identities::OauthCore
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def authenticate(controller)
6
+ if can_authenticate?(controller)
7
+ identity, account_attributes = *yield
8
+
9
+ if controller.current_account
10
+ with_account(identity, controller, account_attributes)
11
+ else
12
+ without_account(identity, controller, account_attributes)
13
+ end
14
+ end
15
+ end
16
+
17
+ def with_account(identity, controller, account_attributes)
18
+ if identity.account
19
+ if identity.account != controller.current_account
20
+ controller.flash[:error] = I18n.t('easy_auth.oauth2.sessions.create.error')
21
+ return nil
22
+ end
23
+ else
24
+ identity.account = controller.current_account
25
+ end
26
+
27
+ identity.save!
28
+
29
+ return identity
30
+ end
31
+
32
+ def without_account(identity, controller, account_attributes)
33
+ if identity.account
34
+ return identity
35
+ else
36
+ account_model_name = EasyAuth.account_model.model_name
37
+ env = clean_env(controller.env.dup)
38
+
39
+ env['QUERY_STRING'] = {account_model_name.param_key => account_attributes(account_attributes, identity)}.to_param
40
+
41
+ account_controller_class = ActiveSupport::Dependencies.constantize("#{account_model_name.route_key.camelize}Controller")
42
+ account_controller = account_controller_class.new
43
+ account_controller.dispatch(:create, ActionDispatch::Request.new(env))
44
+
45
+ controller.status = account_controller.status
46
+ controller.location = account_controller.location
47
+ controller.content_type = account_controller.content_type
48
+ controller.response_body = account_controller.response_body
49
+ controller.request.session = account_controller.session
50
+
51
+ return nil
52
+ end
53
+ end
54
+
55
+ def can_authenticate?(controller)
56
+ raise NotImplementedError
57
+ end
58
+
59
+ def account_attributes(account_attributes, identity)
60
+ EasyAuth.account_model.define_attribute_methods unless EasyAuth.account_model.attribute_methods_generated?
61
+ setters = EasyAuth.account_model.instance_methods.grep(/=$/) - [:id=]
62
+
63
+ attributes = account_attributes_map.inject({}) do |hash, kv|
64
+ if setters.include?("#{kv[0]}=".to_sym)
65
+ hash[kv[0]] = account_attributes[kv[1]]
66
+ end
67
+
68
+ hash
69
+ end
70
+
71
+ attributes[:identities_attributes] = [
72
+ { uid: identity.uid, token: identity.token, type: identity.class.model_name.to_s }
73
+ ]
74
+
75
+ return attributes
76
+ end
77
+
78
+ def account_attributes_map
79
+ { :email => 'email' }
80
+ end
81
+
82
+ def client_id
83
+ settings.client_id
84
+ end
85
+
86
+ def secret
87
+ settings.secret
88
+ end
89
+
90
+ def settings
91
+ EasyAuth.send(version)[provider]
92
+ end
93
+
94
+ def provider
95
+ self.to_s.split('::').last.underscore.to_sym
96
+ end
97
+
98
+ def retrieve_uid(account_attributes)
99
+ raise NotImplementedError
100
+ end
101
+
102
+ private
103
+
104
+ def clean_env(env)
105
+ env.keys.grep(/action/).each do |key|
106
+ env.delete(key)
107
+ end
108
+
109
+ env.delete('rack.request.query_string')
110
+ env.delete('rack.request.query_hash')
111
+ env
112
+ end
113
+ end
114
+
115
+ def get_access_token
116
+ self.class.get_access_token self
117
+ end
118
+ end
@@ -0,0 +1,5 @@
1
+ module EasyAuth
2
+ module OauthCore
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'easy_auth'
2
+
3
+ module EasyAuth
4
+ module Models
5
+ module Identities
6
+ autoload :OauthCore
7
+ end
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'easy_auth/oauth_core'
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_auth-oauth_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Cardarella
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: EasyAuth-OauthCore
14
+ email:
15
+ - brian@dockyard.com
16
+ - bcardarella@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/easy_auth/models/identities/oauth_core.rb
22
+ - lib/easy_auth/oauth_core/version.rb
23
+ - lib/easy_auth/oauth_core.rb
24
+ - lib/easy_auth-oauth_core.rb
25
+ - Rakefile
26
+ - README.md
27
+ homepage: https://github.com/dockyard/easy_auth-oauth_core
28
+ licenses: []
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.0.3
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: EasyAuth-OauthCore
50
+ test_files: []