omniauth-idme 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d84f1ccf7610e795077a6150dfab10c513e9c318
4
+ data.tar.gz: 8e1b81cc5a9d737d9c243fd8fbffe386d4d71a8f
5
+ SHA512:
6
+ metadata.gz: 2ea148e0f9c90fdc9451776e49adb299a7cb462fec2b12cd7dc1cda878d11eec4af8d832753a79cfdd80d437325d7300d8309afc6485c0b8fd11d8316f923ad2
7
+ data.tar.gz: 3439056624592f2730f59a22db51e95a2243b00c6c8a75966f0ed397a71d990bb6e22ee5929325fe4bc5de9e39d61fad8b4522c8d80076db15c8371b01e8d446
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/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p195
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,50 @@
1
+ # OmniAuth ID.me
2
+
3
+ This gem contains the ID.me strategy for [OmniAuth 2.0](https://github.com/intridea/omniauth).
4
+
5
+ ID.me 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.id.me/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-idme"
17
+
18
+ In a Rack application:
19
+
20
+ use OmniAuth::Builder do
21
+ provider :idme, "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 :idme, "consumer_key", "consumer_secret"
28
+ end
29
+
30
+ By default the scope passed to the ID.me API is military. If you would like to support another scope, put this in your OmniAuth configuration file (config/initializers/omniauth.rb):
31
+
32
+ Rails.application.config.middleware.use OmniAuth::Builder do
33
+ provider :idme, "consumer_key", "consumer_secret",
34
+ :scope => "scope"
35
+ end
36
+
37
+ Register your app at https://sandbox.developer.id.me/ during development and https://developer.id.me/ for production. Once your app has been approved you'll receive a consumer token and secret.
38
+
39
+ ## TODO:
40
+ - add multi-scope support
41
+
42
+ ## License
43
+
44
+ Copyright (c) 2012 by TroopSwap, Inc.
45
+
46
+ 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:
47
+
48
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
+
50
+ 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-idme", :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/idme"
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["IDME_CONSUMER_KEY"], ENV["IDME_CONSUMER_SECRET"], :scope => "basic"
25
+ end
26
+
27
+ run App.new
@@ -0,0 +1,43 @@
1
+ require "omniauth/strategies/oauth2"
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class IDme < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, "idme"
8
+ option :scope, "military"
9
+
10
+ option :client_options, {
11
+ :site => "https://api.id.me",
12
+ :authorize_url => "https://api.id.me/oauth/authorize",
13
+ :token_url => "https://api.id.me/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("/v2/#{options[:scope]}.json").parsed
33
+ end
34
+
35
+ def headers
36
+ { "X-API-ORIGIN" => "OMNIAUTH-IDME" }
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+
43
+ OmniAuth.config.add_camelization "idme", "IDme"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module IDme
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "omniauth-idme/version"
2
+ require "omniauth/strategies/idme"
3
+
4
+ module Omniauth
5
+ module IDme
6
+
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-idme/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-idme"
7
+ s.version = Omniauth::IDme::VERSION
8
+ s.authors = %w(ID.me)
9
+ s.email = %w(awesome@id.me)
10
+ s.homepage = "https://github.com/troopswap/omniauth-idme"
11
+ s.summary = "ID.me strategy for OmniAuth"
12
+ s.description = "ID.me 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,27 @@
1
+ require "spec_helper"
2
+
3
+ describe "OmniAuth::Strategies::IDme" do
4
+ subject do
5
+ OmniAuth::Strategies::IDme.new(nil, @options || {})
6
+ end
7
+
8
+ context "client options" do
9
+ it "has correct IDme site" do
10
+ subject.options.client_options.site.should eq("https://api.id.me")
11
+ end
12
+
13
+ it "has correct authorize url" do
14
+ subject.options.client_options.authorize_url.should eq("https://api.id.me/oauth/authorize")
15
+ end
16
+ end
17
+
18
+ context "#uid" do
19
+ before :each do
20
+ subject.stub(:data) { { "id" => "123456" } }
21
+ end
22
+
23
+ it "returns the id from data" do
24
+ subject.uid.should eq("123456")
25
+ end
26
+ end
27
+ 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-idme"
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,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-idme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ID.me
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ID.me strategy for OmniAuth
84
+ email:
85
+ - awesome@id.me
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .ruby-version
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - example/Gemfile
97
+ - example/config.ru
98
+ - lib/omniauth-idme.rb
99
+ - lib/omniauth-idme/version.rb
100
+ - lib/omniauth/strategies/idme.rb
101
+ - omniauth-idme.gemspec
102
+ - spec/omniauth/strategies/idme_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/troopswap/omniauth-idme
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: ID.me strategy for OmniAuth
127
+ test_files:
128
+ - spec/omniauth/strategies/idme_spec.rb
129
+ - spec/spec_helper.rb