oa-codeschool 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use oa-codeschool
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Eric Allam
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/README.rdoc ADDED
@@ -0,0 +1,33 @@
1
+ = oa-codepath
2
+
3
+ Include in your Gemfile:
4
+
5
+ gem 'oa-codepath'
6
+
7
+ Then in your config/initializers/omniauth.rb :
8
+
9
+ Rails.application.config.middleware.use OmniAuth::Builder do
10
+ provider OmniAuth::Strategies::CodePath, 'client_id', 'client_secret'
11
+ end
12
+
13
+ By default the base_uri for code_path is set to http://localhost::3000, in different environments you may want to change it:
14
+
15
+ OmniAuth::Strategies::CodePath.base_uri = "http://codepath.com"
16
+
17
+ Then all you have to do is redirect / link to /auth/code_path and omniauth will take care of the rest
18
+
19
+ == Contributing to oa-codepath
20
+
21
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
22
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
23
+ * Fork the project
24
+ * Start a feature/bugfix branch
25
+ * Commit and push until you are happy with your contribution
26
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
27
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
28
+
29
+ == Copyright
30
+
31
+ Copyright (c) 2011 Eric Allam. See LICENSE.txt for
32
+ further details.
33
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ spec.rcov = true
13
+ end
14
+
15
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ CODE_SCHOOL_VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,69 @@
1
+ begin
2
+ require 'active_support/core_ext/class/attribute_accessors'
3
+ rescue
4
+ require 'active_support'
5
+ end
6
+
7
+ require 'omniauth/oauth'
8
+
9
+ module OmniAuth
10
+ module Strategies
11
+ # Authenticate to Code School utilizing OAuth 2.0 and retrieve
12
+ # basic user information.
13
+ #
14
+ # @example Basic Usage
15
+ # use OmniAuth::Strategies::CodeSchool, 'client_id', 'client_secret'
16
+ class CodeSchool < OAuth2
17
+ cattr_accessor :base_uri
18
+ # @param [Rack Application] app standard middleware application parameter
19
+ # @param [String] client_id the application id as [registered on Facebook](http://www.facebook.com/developers/)
20
+ # @param [String] client_secret the application secret as registered on Facebook
21
+ # @option options [String] :scope ('email,offline_access') comma-separated extended permissions such as `email` and `manage_pages`
22
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
23
+ super(app, :code_path, client_id, client_secret, {
24
+ :site => self.class.base_uri.presence || "http://localhost:3000",
25
+ :authorize_path => "/oauth/authorize",
26
+ :access_token_path => "/oauth/token"
27
+ }, options, &block)
28
+ end
29
+
30
+ def request_phase
31
+ options[:response_type] ||= "code"
32
+ super
33
+ end
34
+
35
+ def callback_phase
36
+ options[:grant_type] ||= 'authorization_code'
37
+ super
38
+ end
39
+
40
+ def user_data
41
+ @data ||= MultiJson.decode(@access_token.get('/api/v1/user.json', {}, {}))['user']
42
+ end
43
+
44
+ # memoize the client or else setting up Faraday stubs does not work
45
+ def client
46
+ @_client ||= super
47
+ end
48
+
49
+ def user_info
50
+ {
51
+ 'nickname' => user_data["twitter_name"],
52
+ 'email' => (user_data["email"] if user_data["email"]),
53
+ 'first_name' => user_data["name"].split(" ").first,
54
+ 'last_name' => user_data["name"].split(" ").last,
55
+ 'name' => user_data['name']
56
+ }
57
+ end
58
+
59
+ def auth_hash
60
+ OmniAuth::Utils.deep_merge(super, {
61
+ 'uid' => user_data['id'],
62
+ 'user_info' => user_info,
63
+ 'extra' => {'user_hash' => user_data}
64
+ })
65
+ end
66
+ end
67
+ end
68
+ end
69
+
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'oa-codeschool/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'oa-codeschool'
7
+ s.version = OmniAuth::Strategies::CODE_SCHOOL_VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Eric Allam']
10
+ s.email = ['eric@envylabs.com']
11
+ s.homepage = 'https://github.com/envylabs/oa-codeschool'
12
+ s.summary = 'Provides an OmniAuth strategy for OAuth2 on CodeSchool.com'
13
+ s.description = 'Provides an OmniAuth strategy for OAuth2 on CodeSchool.com'
14
+ s.licenses = ['MIT']
15
+
16
+ s.add_runtime_dependency('oa-oauth', ['= 0.2.0.beta3'])
17
+ s.add_runtime_dependency('multi_json', ['>= 0'])
18
+ s.add_runtime_dependency('activesupport', ['>= 0'])
19
+
20
+ s.add_development_dependency('rspec', ['~> 2.3.0'])
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ['lib']
26
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "OaCodepath" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rspec'
5
+ require 'oa-codeschool'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-codeschool
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Eric Allam
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oa-oauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 62196357
29
+ segments:
30
+ - 0
31
+ - 2
32
+ - 0
33
+ - beta
34
+ - 3
35
+ version: 0.2.0.beta3
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: multi_json
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: activesupport
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: rspec
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 2
77
+ - 3
78
+ - 0
79
+ version: 2.3.0
80
+ type: :development
81
+ version_requirements: *id004
82
+ description: Provides an OmniAuth strategy for OAuth2 on CodeSchool.com
83
+ email:
84
+ - eric@envylabs.com
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files: []
90
+
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - .rvmrc
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ - Rakefile
99
+ - VERSION
100
+ - lib/oa-codeschool.rb
101
+ - lib/oa-codeschool/version.rb
102
+ - oa-codeschool.gemspec
103
+ - spec/oa-codepath_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/envylabs/oa-codeschool
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.7.2
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Provides an OmniAuth strategy for OAuth2 on CodeSchool.com
138
+ test_files:
139
+ - spec/oa-codepath_spec.rb
140
+ - spec/spec_helper.rb