omniauth-launch-pass 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32550a222e0e11ce13e10c4f202bc51b55516d8a
4
+ data.tar.gz: d54001afb5d38c27b6034d999579ac1569e05807
5
+ SHA512:
6
+ metadata.gz: e6ea614627a18f8fafa1f15a70f26a9786c460031583c407817f07761d332f7e8b14283a4eda7aacce5d831da5b4366aeefd84a7d394afab79a21d302056073b
7
+ data.tar.gz: 02dc2115429c184c333bba1288e9d8825c758b9df91b3ff2aebebaa1dcabf066adfcab35e798f3502621edfb99f7269f2c24d6f062159533d9b568fe017b3894
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sam McTaggart
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,31 @@
1
+ # Omniauth::LaunchPass
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-launch-pass'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-launch-pass
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/omniauth-launch-pass/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
@@ -0,0 +1,53 @@
1
+ module LaunchPass
2
+ class User
3
+ attr_reader :email
4
+ attr_reader :first_name
5
+ attr_reader :last_name
6
+ attr_reader :avatar_url
7
+ attr_reader :username
8
+
9
+ def initialize(info_hash)
10
+ @info_hash = info_hash
11
+ @email = @info_hash["email"]
12
+ @first_name = @info_hash["first_name"]
13
+ @last_name = @info_hash["last_name"]
14
+ @avatar_url = @info_hash["avatar_url"]
15
+ @username = @info_hash["username"]
16
+ end
17
+
18
+ def member_of?(team_name)
19
+ teams.include?(team_name)
20
+ end
21
+
22
+ def has_product?(product_name, wildcard = true)
23
+ if !wildcard
24
+ products.include?(product_name)
25
+ else
26
+ products.each do |product|
27
+ return true if product =~ /#{Regexp.escape(product_name)}/
28
+ end
29
+ false
30
+ end
31
+ end
32
+
33
+ def admin?
34
+ member_of?('Admins')
35
+ end
36
+
37
+ def teams
38
+ if @info_hash["teams"]
39
+ @teams ||= @info_hash["teams"].map do |team_hash|
40
+ team_hash["name"]
41
+ end
42
+ end
43
+ end
44
+
45
+ def products
46
+ if @info_hash["products"]
47
+ @products ||= @info_hash["products"].map do |product|
48
+ product["name"]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ require 'omniauth/launch_pass/version'
2
+ require 'omniauth/strategies/launch_pass'
3
+
4
+ require 'launch_pass/user'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module LaunchPass
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class LaunchPass < OmniAuth::Strategies::OAuth2
6
+ option :name, 'launch_pass'
7
+
8
+ option :client_options, {
9
+ site: "https://launchpass.launchacademy.com",
10
+ authorize_url: "/oauth/authorize"
11
+ }
12
+
13
+ uid { raw_info["user"]["id"].to_s }
14
+
15
+ info do
16
+ raw_info["user"]
17
+ end
18
+
19
+ def raw_info
20
+ @raw_info ||= access_token.get('/api/v1/me.json').parsed
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ OmniAuth.config.add_camelization 'launch_pass', 'LaunchPass'
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/launch_pass/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "omniauth-launch-pass"
7
+ spec.version = Omniauth::LaunchPass::VERSION
8
+ spec.authors = ["Sam McTaggart", "Dan Pickett"]
9
+ spec.email = [
10
+ "sam.mctaggart@launchacademy.com",
11
+ "dan.pickett@launchacademy.com"
12
+ ]
13
+
14
+ spec.summary = %q{Omniauth strategy for Launch Pass}
15
+ spec.description = %q{Launch Academy's single sign on client}
16
+ spec.homepage = "https://launchacademy.com"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split("\n")
20
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "mocha"
29
+ spec.add_development_dependency "vcr"
30
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe LaunchPass::User do
4
+ let(:info_hash) do
5
+ {
6
+ "id"=>1,
7
+ "first_name"=>"Dan",
8
+ "last_name"=>"Pickett",
9
+ "avatar_url"=>"https://secure.gravatar.com/avatar/c6aa1dc04e88732bcbea6c274f917c04.png?r=PG",
10
+ "username"=>"dpickett",
11
+ "email"=>"dan.pickett@launchacademy.com",
12
+ "product_offerings"=>[
13
+ {
14
+ "name"=>"Introduction to Programming Alpha",
15
+ "product"=> {"name"=>"Introduction to Programming"}
16
+ }
17
+ ],
18
+ "products"=>[{"name"=>"Introduction to Programming"}],
19
+ "teams"=>[
20
+ {"id"=>1, "name"=>"Admins"},
21
+ {"id"=>2, "name"=>"Online Alpha Participants"}
22
+ ]
23
+ }
24
+ end
25
+
26
+ let(:user) do
27
+ LaunchPass::User.new(info_hash)
28
+ end
29
+
30
+ it 'indicates true if I am a member of a given team' do
31
+ expect(user).to be_member_of('Admins')
32
+ end
33
+
34
+ it 'indicates false if I am not a member of a given team' do
35
+ expect(user).to_not be_member_of('The Fun People')
36
+ end
37
+
38
+ it 'informs whether a user has access to a given product' do
39
+ expect(user).to have_product('Introduction to Programming')
40
+ end
41
+
42
+ it 'informs whether a user does not have access to a given product' do
43
+ expect(user).to_not have_product('On Premises')
44
+ end
45
+
46
+ it 'allows for a wildcard search against product names' do
47
+ expect(user).to have_product('Introduction')
48
+ end
49
+
50
+ it 'can require an explicit match' do
51
+ expect(user).to_not have_product('Introduction', false)
52
+ end
53
+
54
+ it 'has a list of team naems' do
55
+ expect(user.teams).to eq(['Admins', 'Online Alpha Participants'])
56
+ end
57
+
58
+ it 'has a list of products' do
59
+ expect(user.products).to eq(['Introduction to Programming'])
60
+ end
61
+
62
+ it 'has an email' do
63
+ expect(user.email).to_not be_nil
64
+ end
65
+
66
+ it 'has a first name' do
67
+ expect(user.first_name).to_not be_nil
68
+ end
69
+
70
+ it 'has a last name' do
71
+ expect(user.last_name).to_not be_nil
72
+ end
73
+
74
+ it 'has an avatar url' do
75
+ expect(user.avatar_url).to_not be_nil
76
+ end
77
+
78
+ it 'has a username' do
79
+ expect(user.username).to_not be_nil
80
+ end
81
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::LaunchPass do
4
+ let(:app) do
5
+ lambda { [ 200, {}, ["Hello"] ] }
6
+ end
7
+ let(:request) do
8
+ mock.tap do |m|
9
+ m.stubs(:env).returns({})
10
+ m.stubs(:params).returns({})
11
+ m.stubs(:cookies).returns({})
12
+ end
13
+ end
14
+
15
+ let(:strategy) do
16
+ OmniAuth::Strategies::LaunchPass.new(app, 'app_id', 'secret_key').tap do |s|
17
+ s.stubs(:request).returns(request)
18
+ end
19
+ end
20
+
21
+ let(:access_token) do
22
+ mock.tap do |m|
23
+ m.stubs(:options).returns({})
24
+ m.stubs(:token).returns(ENV['LAUNCH_PASS_TOKEN'])
25
+ m.stubs(:expires?).returns(false)
26
+ m.stubs(:get).returns(response)
27
+ end
28
+ end
29
+
30
+ before do
31
+ OmniAuth.config.test_mode = true
32
+ end
33
+
34
+ after do
35
+ OmniAuth.config.test_mode = false
36
+ end
37
+
38
+ it 'points to the correct url' do
39
+ expect(strategy.client.site).
40
+ to eq('https://launchpass.launchacademy.com')
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+
3
+ require 'omniauth-launch-pass'
4
+
5
+ require 'mocha/api'
6
+
7
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ config.mock_with :mocha
11
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-launch-pass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sam McTaggart
8
+ - Dan Pickett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.7'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.7'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: mocha
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: vcr
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Launch Academy's single sign on client
99
+ email:
100
+ - sam.mctaggart@launchacademy.com
101
+ - dan.pickett@launchacademy.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/launch_pass/user.rb
113
+ - lib/omniauth-launch-pass.rb
114
+ - lib/omniauth/launch_pass/version.rb
115
+ - lib/omniauth/strategies/launch_pass.rb
116
+ - omniauth-launch-pass.gemspec
117
+ - spec/launch_pass/user_spec.rb
118
+ - spec/omniauth/strategies/launch_pass_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://launchacademy.com
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Omniauth strategy for Launch Pass
144
+ test_files:
145
+ - spec/launch_pass/user_spec.rb
146
+ - spec/omniauth/strategies/launch_pass_spec.rb
147
+ - spec/spec_helper.rb