omniauth-learn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10bdc2a76691e99c5c200500d658b164796e2922
4
+ data.tar.gz: aef8f8ceaa44ec172e70b7f7bbad189e1aa3bebe
5
+ SHA512:
6
+ metadata.gz: 72a7757111452b29f25c5fb8e19b5d93671a9c6a65b02f76f474cf8b6eadd04762a671cbb4e67ce40ed0a403eb874bb466e843c9ccaba8ee38452f8e3a76b45c
7
+ data.tar.gz: f756478561316b45c52b51da8a9b646d4cb1c90aff56794b1e87b803dca432c3e83458f1c7da807da62e3cae0623879f336742a43d91a46d5e6d45a5a646e8d4
@@ -0,0 +1,54 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby
3
+
4
+ ### Ruby ###
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /spec/examples.txt
13
+ /test/tmp/
14
+ /test/version_tmp/
15
+ /tmp/
16
+
17
+ # Used by dotenv library to load environment variables.
18
+ .env
19
+
20
+ ## Specific to RubyMotion:
21
+ .dat*
22
+ .repl_history
23
+ build/
24
+ *.bridgesupport
25
+ build-iPhoneOS/
26
+ build-iPhoneSimulator/
27
+
28
+ ## Specific to RubyMotion (use of CocoaPods):
29
+ #
30
+ # We recommend against adding the Pods directory to your .gitignore. However
31
+ # you should judge for yourself, the pros and cons are mentioned at:
32
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
33
+ #
34
+ # vendor/Pods/
35
+
36
+ ## Documentation cache and generated files:
37
+ /.yardoc/
38
+ /_yardoc/
39
+ /doc/
40
+ /rdoc/
41
+
42
+ ## Environment normalization:
43
+ /.bundle/
44
+ /vendor/bundle
45
+ /lib/bundler/man/
46
+
47
+ # for a library or gem, you might want to ignore these files since the code is
48
+ # intended to run in multiple environments; otherwise, check them in:
49
+ # Gemfile.lock
50
+ # .ruby-version
51
+ # .ruby-gemset
52
+
53
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-learn (0.0.1)
5
+ omniauth (~> 1.0)
6
+ omniauth-oauth2 (>= 1.1.1, < 2.0)
7
+ rake
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ addressable (2.4.0)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.2.5)
16
+ docile (1.1.5)
17
+ dotenv (2.1.0)
18
+ faraday (0.9.2)
19
+ multipart-post (>= 1.2, < 3)
20
+ hashdiff (0.3.0)
21
+ hashie (3.4.4)
22
+ json (1.8.3)
23
+ jwt (1.5.1)
24
+ multi_json (1.12.1)
25
+ multi_xml (0.5.5)
26
+ multipart-post (2.0.0)
27
+ oauth2 (1.1.0)
28
+ faraday (>= 0.8, < 0.10)
29
+ jwt (~> 1.0, < 1.5.2)
30
+ multi_json (~> 1.3)
31
+ multi_xml (~> 0.5)
32
+ rack (>= 1.2, < 3)
33
+ omniauth (1.3.1)
34
+ hashie (>= 1.2, < 4)
35
+ rack (>= 1.0, < 3)
36
+ omniauth-oauth2 (1.4.0)
37
+ oauth2 (~> 1.0)
38
+ omniauth (~> 1.2)
39
+ rack (1.6.4)
40
+ rack-test (0.6.3)
41
+ rack (>= 1.0)
42
+ rake (11.1.2)
43
+ rspec (2.99.0)
44
+ rspec-core (~> 2.99.0)
45
+ rspec-expectations (~> 2.99.0)
46
+ rspec-mocks (~> 2.99.0)
47
+ rspec-core (2.99.2)
48
+ rspec-expectations (2.99.2)
49
+ diff-lcs (>= 1.1.3, < 2.0)
50
+ rspec-mocks (2.99.4)
51
+ safe_yaml (1.0.4)
52
+ simplecov (0.11.2)
53
+ docile (~> 1.1.0)
54
+ json (~> 1.8)
55
+ simplecov-html (~> 0.10.0)
56
+ simplecov-html (0.10.0)
57
+ webmock (2.0.3)
58
+ addressable (>= 2.3.6)
59
+ crack (>= 0.3.2)
60
+ hashdiff
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ dotenv
67
+ omniauth-learn!
68
+ rack-test
69
+ rspec (~> 2.7)
70
+ simplecov
71
+ webmock
72
+
73
+ BUNDLED WITH
74
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2016 Learn.co
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ OmniAuth Learn
2
+ ---
3
+
4
+ This is an OmniAuth strategy for authenticating with Learn.co. Right now, it's mostly good for using the (super secret) API.
5
+
6
+ To use it, you'll need to sign up for an OAuth2 application key and secret on the [Learn Applications Page](https://learn.co/oauth/applications).
7
+
8
+ ### Basic Usage
9
+
10
+ ```ruby
11
+ use OmniAuth::Builder do
12
+ provider :learn, ENV['LEARN_KEY'], ENV['LEARN_SECRET']
13
+ end
14
+ ```
15
+
16
+ ### Rails
17
+
18
+ * In your Gemfile
19
+
20
+ `gem 'omniauth-learn'`
21
+
22
+ * Create an initializer, `config/initializers/omniauth_learn.rb`
23
+
24
+ ```ruby
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :developer unless Rails.env.production?
27
+ provider :learn, ENV['LEARN_OAUTH_APP_ID'], ENV['LEARN_OAUTH_APP_SECRET'],
28
+ provider_ignores_state: true
29
+ end
30
+ ```
31
+
32
+ * Set your callback route in `config/routes.rb`
33
+
34
+ ```ruby
35
+ get '/auth/:provider/callback', to: "some_controller#some_action"
36
+ ```
37
+
38
+ * In the controller action that maps to your callback URL:
39
+
40
+ ```ruby
41
+ #some_controller.rb
42
+
43
+ def some_action
44
+ request.env["omniauth.auth"]["info"]
45
+ # => {
46
+ "github_uid" => "2938",
47
+ "github_gravatar => "http://mypic.jpg",
48
+ "username" => "sophiedebenedetto",
49
+ etc.
50
+ }
51
+ end
52
+ ```
53
+
54
+
55
+ ### Local Usage
56
+
57
+ ```ruby
58
+ provider :learn, ENV['LEARN_KEY'], ENV['LEARN_SECRET'], {
59
+ client_options: {
60
+ # use the origin for your local instance of Learn.co
61
+ site: 'http://localhost:3000',
62
+ authorize_url: 'http://localhost:3000/oauth/authorize',
63
+ token_url: 'http://localhost:3000/oauth/token'
64
+ }
65
+ }
66
+ ```
67
+
68
+ ## Contributing
69
+
70
+ * Fork and clone this repository
71
+ * Bundle install and run the test suite by running `rspec`
72
+
73
+ ### TODO
74
+
75
+ * Add scopes
76
+ * In the initializer, we should be able to set scopes to determine what information we receive in the payload from Learn.
77
+
78
+ ## License
79
+
80
+ Copyright (c) 2016 Learn.co
81
+
82
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
85
+
86
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
87
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-learn/version"
2
+ require "omniauth/strategies/learn"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Learn
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require 'omniauth-oauth2'
2
+ require 'pry'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Learn < OmniAuth::Strategies::OAuth2
7
+ include OmniAuth::Strategy
8
+
9
+ option :client_options, {
10
+ site: "https://learn.co",
11
+ authorize_url: "https://learn.co/oauth/authorize",
12
+ token_url: "https://learn.co/oauth/token"
13
+ }
14
+
15
+ def request_phase
16
+ super
17
+ end
18
+
19
+ info do
20
+ raw_info.merge("token" => access_token.token)
21
+ end
22
+
23
+ uid { raw_info["id"] }
24
+
25
+ def raw_info
26
+ @raw_info ||= access_token.get('/api/v1/users/me').parsed
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/omniauth-learn/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Sophie DeBenedetto", "Charles Pletcher"]
7
+ gem.email = ["sophie@flatironschool.com", "chuck@flatironschool.com"]
8
+ gem.description = %q{Official OmniAuth strategy for Learn.co.}
9
+ gem.summary = %q{Official OmniAuth strategy for Learn.co.}
10
+ gem.homepage = "https://github.com/pletcher/omniauth-learn"
11
+ gem.license = "MIT"
12
+
13
+
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map do |f|
15
+ File.basename(f)
16
+ end
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ gem.name = "omniauth-learn"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = OmniAuth::Learn::VERSION
22
+
23
+ gem.add_dependency 'omniauth', '~> 1.0'
24
+ # Nothing lower than omniauth-oauth2 1.1.1
25
+ # http://www.rubysec.com/advisories/CVE-2012-6134/
26
+ gem.add_dependency 'omniauth-oauth2', '>= 1.1.1', '< 2.0'
27
+ gem.add_development_dependency 'rspec', '~> 2.7'
28
+ gem.add_development_dependency 'rack-test'
29
+ gem.add_development_dependency 'simplecov'
30
+ gem.add_development_dependency 'webmock'
31
+ gem.add_development_dependency 'dotenv'
32
+ gem.add_dependency 'rake'
33
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Learn do
4
+
5
+ let(:access_token) { stub('AccessToken', :options => {}) }
6
+ let(:parsed_response) { stub('ParsedResponse') }
7
+ let(:response) { stub('Response', :parsed => parsed_response) }
8
+
9
+ let(:learn_site) { 'https://learn.co' }
10
+ let(:learn_authorize_url) { 'https://learn.co/oauth/authorize' }
11
+ let(:learn_token_url) { 'https://learn.co/oauth/token' }
12
+ let(:learn_authorizer) do
13
+ OmniAuth::Strategies::Learn.new(ENV['LEARN_KEY'], ENV['LEARN_SECRET'])
14
+ end
15
+
16
+ let(:custom_learn_authorizer) do
17
+ OmniAuth::Strategies::Learn.new(ENV['LEARN_KEY'], ENV['LEARN_SECRET'],
18
+ {
19
+ :client_options => {
20
+ :site => "http://localhost:3000",
21
+ :authorize_url => "http://localhost:3000/oauth/authorize",
22
+ :token_url => "http://localhost:3000/oauth/token"
23
+ }
24
+ }
25
+ )
26
+ end
27
+
28
+ context "client options" do
29
+ it 'has the correct authorize_url' do
30
+ expect(learn_authorizer.client.options[:authorize_url]).to eq(learn_authorize_url)
31
+ end
32
+
33
+ it 'has the correct token_url' do
34
+ expect(learn_authorizer.client.options[:token_url]).to eq(learn_token_url)
35
+ end
36
+
37
+ describe "should be overrideable" do
38
+ it "for authorize url" do
39
+ expect(custom_learn_authorizer.client.options[:authorize_url]).to eq("http://localhost:3000/oauth/authorize")
40
+ end
41
+
42
+ it "for token url" do
43
+ expect(custom_learn_authorizer.client.options[:token_url]).to eq("http://localhost:3000/oauth/token")
44
+ end
45
+ end
46
+ end
47
+
48
+ context "raw info" do
49
+
50
+ before(:each) do
51
+ learn_authorizer.stub(:access_token).and_return(access_token)
52
+ allow(learn_authorizer.access_token).to receive(:get).and_return(parsed_response)
53
+ res = learn_authorizer.access_token.get("/api/v1/users/me")
54
+ allow(res).to receive(:parsed).and_return(parsed_response)
55
+ end
56
+
57
+ it "should be set equal to the response that the access token fetches from the Learn API" do
58
+ expect(learn_authorizer.raw_info).to eq(parsed_response)
59
+ end
60
+
61
+ context "info" do
62
+ before do
63
+ allow(learn_authorizer).to receive(:raw_info).and_return({"email" => "sophie@email.com"})
64
+ allow(learn_authorizer.access_token).to receive(:token).and_return("testToken")
65
+ allow(learn_authorizer.raw_info).to receive(:merge).and_return({"email" => "sophie@email.com", "token" => "testToken"})
66
+ end
67
+
68
+ it "constructs the info hash from the raw_info hash and the access token" do
69
+ expect(learn_authorizer.info).to eq({"email" => "sophie@email.com", "token" => "testToken"})
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,19 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-learn'
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+ config.include WebMock::API
16
+ config.include Rack::Test::Methods
17
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-learn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sophie DeBenedetto
8
+ - Charles Pletcher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-05-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: omniauth-oauth2
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.1
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '2.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.1.1
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: simplecov
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: webmock
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ - !ruby/object:Gem::Dependency
105
+ name: dotenv
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ - !ruby/object:Gem::Dependency
119
+ name: rake
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ description: Official OmniAuth strategy for Learn.co.
133
+ email:
134
+ - sophie@flatironschool.com
135
+ - chuck@flatironschool.com
136
+ executables: []
137
+ extensions: []
138
+ extra_rdoc_files: []
139
+ files:
140
+ - ".gitignore"
141
+ - ".rspec"
142
+ - Gemfile
143
+ - Gemfile.lock
144
+ - LICENSE
145
+ - README.md
146
+ - Rakefile
147
+ - lib/omniauth-learn.rb
148
+ - lib/omniauth-learn/version.rb
149
+ - lib/omniauth/strategies/learn.rb
150
+ - omniauth-learn.gemspec
151
+ - spec/omniauth-learn/strategies/learn_spec.rb
152
+ - spec/spec_helper.rb
153
+ homepage: https://github.com/pletcher/omniauth-learn
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.5.1
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Official OmniAuth strategy for Learn.co.
177
+ test_files:
178
+ - spec/omniauth-learn/strategies/learn_spec.rb
179
+ - spec/spec_helper.rb