omniauth-troopid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
6
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create 1.9.3@omniauth-troopid
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem "multi_json"
7
+ gem "rake"
8
+ end
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # OmniAuth Troop ID
2
+
3
+ This gem contains the Troop ID strategy for OmniAuth 2.0.
4
+
5
+ Troop ID offers online brands a secure, real-time method for verifying the military affiliation of their customers online. By verifying military affiliation companies can tailor the user experience on their platform to offer discounts or other benefits.
6
+
7
+ Read our [documentation](https://developer.troopid.com/docs) to learn more about how to integrate.
8
+
9
+ ## How To Use It
10
+
11
+ Usage is as per any other OmniAuth 2.0 strategy.
12
+
13
+ Add the strategy to your `Gemfile` alongside OmniAuth:
14
+
15
+ gem "omniauth"
16
+ gem "omniauth-troopid"
17
+
18
+ In a Rack application:
19
+
20
+ use OmniAuth::Builder do
21
+ provider :troopid, "consumer_key", "consumer_secret"
22
+ end
23
+
24
+ For Rails, put this in your OmniAuth configuration file (config/initializers/omniauth.rb):
25
+
26
+ Rails.application.config.middleware.use OmniAuth::Builder do
27
+ provider :troopid, "consumer_key", "consumer_secret"
28
+ end
29
+
30
+ Register your app at https://sandbox.developer.troopid.com/ during development and https://developer.troopid.com/ for production. Once your app has been approved you'll receive a consumer token and secret.
31
+
32
+ ## License
33
+
34
+ Copyright (c) 2012 by TroopSwap, Inc.
35
+
36
+ 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:
37
+
38
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
39
+
40
+ 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.
data/Rakefile ADDED
@@ -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
data/example/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem "sinatra"
4
+ gem "multi_json"
5
+ gem "omniauth-troopid", :path => "../"
data/example/config.ru ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/setup"
2
+ require "sinatra/base"
3
+ require "omniauth-linkedin"
4
+
5
+ class App < Sinatra::Base
6
+ get "/" do
7
+ redirect "/auth/troopid"
8
+ end
9
+
10
+ get "/auth/:provider/callback" do
11
+ content_type "application/json"
12
+ MultiJson.encode(request.env)
13
+ end
14
+
15
+ get "/auth/failure" do
16
+ content_type "application/json"
17
+ MultiJson.encode(request.env)
18
+ end
19
+ end
20
+
21
+ use Rack::Session::Cookie
22
+
23
+ use OmniAuth::Builder do
24
+ provider :linkedin, ENV["TROOPID_CONSUMER_KEY"], ENV["TROOPID_CONSUMER_SECRET"], :scope => "basic"
25
+ end
26
+
27
+ run App.new
@@ -0,0 +1,39 @@
1
+ require "omniauth/strategies/oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class TroopID < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, "troopid"
8
+ option :scope, "basic"
9
+
10
+ option :client_options, {
11
+ :site => "https://api.troopid.com",
12
+ :authorize_url => "https://api.troopid.com/oauth/authorize",
13
+ :token_url => "https://api.troopid.com/oauth/token"
14
+ }
15
+
16
+ option :authorize_options, [:scope, :display]
17
+
18
+ uid { data["id"] }
19
+
20
+ info do
21
+ {
22
+ :affiliation => data["affiliation"],
23
+ :verified => data["verified"]
24
+ }
25
+ end
26
+
27
+ extra do
28
+ { :raw => data }
29
+ end
30
+
31
+ def data
32
+ @data ||= access_token.get("/v1/me.json").parsed
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ OmniAuth.config.add_camelization "troopid", "TroopID"
39
+
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module TroopID
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "omniauth-troopid/version"
2
+ require "omniauth/strategies/troopid"
3
+
4
+ module Omniauth
5
+ module TroopID
6
+
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-troopid/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-troopid"
7
+ s.version = Omniauth::TroopID::VERSION
8
+ s.authors = %w(Troop ID)
9
+ s.email = %w(awesome@troopswap.com)
10
+ s.homepage = "https://github.com/troopswap/omniauth-troopid"
11
+ s.summary = "Troop ID strategy for OmniAuth"
12
+ s.description = "Troop ID strategy for OmniAuth"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = %w(lib)
18
+
19
+ s.add_runtime_dependency "omniauth-oauth2"
20
+
21
+ s.add_development_dependency "rspec", "~> 2.7"
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "webmock"
24
+ s.add_development_dependency "rack-test"
25
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe "OmniAuth::Strategies::TroopID" do
4
+ subject do
5
+ OmniAuth::Strategies::TroopID.new(nil, @options || {})
6
+ end
7
+
8
+ it "should add a camelization for itself" do
9
+ OmniAuth::Utils.camelize("troopid").should == "TroopID"
10
+ end
11
+
12
+ context "client options" do
13
+ it "has correct TroopID site" do
14
+ subject.options.client_options.site.should eq("https://api.troopid.com")
15
+ end
16
+
17
+ it "has correct authorize url" do
18
+ subject.options.client_options.authorize_url.should eq("https://api.troopid.com/oauth/authorize")
19
+ end
20
+ end
21
+
22
+ context "#uid" do
23
+ before :each do
24
+ subject.stub(:data) { { "id" => "123456" } }
25
+ end
26
+
27
+ it "returns the id from data" do
28
+ subject.uid.should eq("123456")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.expand_path("..", __FILE__)
2
+ $:.unshift File.expand_path("../../lib", __FILE__)
3
+
4
+ require "rspec"
5
+ require "rack/test"
6
+ require "webmock/rspec"
7
+ require "omniauth"
8
+ require "omniauth-troopid"
9
+
10
+ RSpec.configure do |config|
11
+ config.include WebMock::API
12
+ config.include Rack::Test::Methods
13
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
14
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-troopid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Troop
9
+ - ID
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-12-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth-oauth2
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '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'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '2.7'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '2.7'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
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: webmock
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: rack-test
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
+ description: Troop ID strategy for OmniAuth
96
+ email:
97
+ - awesome@troopswap.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .rspec
104
+ - .rvmrc
105
+ - Gemfile
106
+ - README.md
107
+ - Rakefile
108
+ - example/Gemfile
109
+ - example/config.ru
110
+ - lib/omniauth-troopid.rb
111
+ - lib/omniauth-troopid/version.rb
112
+ - lib/omniauth/strategies/troopid.rb
113
+ - omniauth-troopid.gemspec
114
+ - spec/omniauth/strategies/troopid_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/troopswap/omniauth-troopid
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.24
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Troop ID strategy for OmniAuth
140
+ test_files:
141
+ - spec/omniauth/strategies/troopid_spec.rb
142
+ - spec/spec_helper.rb