omniauth-myusa 0.0.4

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: e32846eca541483f4e65f6738e520179cf2ae292
4
+ data.tar.gz: f63e4b9cd7f5fd647f41d78ae6ea021812b2d5d3
5
+ SHA512:
6
+ metadata.gz: b22cdf799e98643a36dd8425425dd4b1bf8fb1af3c84cbc5c664906af160a2b22cd486f04d61f7e8ddba322dfed34b3bd8292c7aa14a2e691842701752caa6bc
7
+ data.tar.gz: 0db2140a6436d5f4c327b571160f0a1c10221f4ca32e8208be04c964c7b255c4e57051974b1eeaf23ce67bcfeded01e762317097cf6e7e6a8137904d7e5d9535
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ example/app.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-myusa.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec'
8
+ gem 'simplecov'
9
+ gem 'rack-test'
10
+ gem 'webmock'
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Greg Gershman
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.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # OmniAuth::Strategies::Myusa
2
+
3
+ This gem contains the MyUSA strategy for OmniAuth.
4
+
5
+ MyUSA uses OAuth 2.0. To find out more information about MyUSA and how to create
6
+ your own application visit the [developers](https://my.usa.gov/developer)
7
+ section of MyUSA.
8
+
9
+ View the OmniAuth 1.0 docs for more information about strategy implementation:
10
+ https://github.com/intridea/omniauth.
11
+
12
+ ## Before You Begin
13
+
14
+ Sign in to [MyUSA](https://my.usa.gov/developer) and register an application.
15
+ You will need to provide a redirect URI which is "YOUR_SITE/auth/myusa/callback"
16
+ by default. Take note of your Consumer Key and Consumer Secret.
17
+
18
+ ## Using This Strategy
19
+
20
+ First start by adding this gem to your Gemfile:
21
+
22
+ ```ruby
23
+ gem 'omniauth-myusa', git: 'https://github.com/18F/omniauth-myusa.git'
24
+ ```
25
+
26
+ Next, tell OmniAuth about this provider. For a Rails app, your
27
+ `config/initializers/omniauth.rb` file should look like this:
28
+
29
+ ```ruby
30
+ provider(
31
+ :myusa,
32
+ "CONSUMER_KEY",
33
+ "CONSUMER_SECRET",
34
+ scope: "profile.email tasks submit_forms notifications"
35
+ )
36
+ ```
37
+
38
+ Replace CONSUMER_KEY and CONSUMER_SECRET with the appropriate values you obtained from [MyUSA](https://my.usa.gov/apps) earlier. Valid scopes are:
39
+ - profile.email
40
+ - profile.title
41
+ - profile.first_name
42
+ - profile.middle_name
43
+ - profile.last_name
44
+ - profile.suffix
45
+ - profile.address
46
+ - profile.address2
47
+ - profile.city
48
+ - profile.state
49
+ - profile.zip
50
+ - profile.phone_number
51
+ - profile.mobile_number
52
+ - profile.gender
53
+ - profile.marital_status
54
+ - profile.is_parent
55
+ - profile.is_student
56
+ - profile.is_veteran
57
+ - profile.is_retired
58
+ - tasks
59
+ - notifications
60
+ - submit_forms
61
+
62
+ ## Authentication Hash
63
+ An example auth hash available in `request.env['omniauth.auth']`:
64
+
65
+ ```ruby
66
+ {
67
+ "provider"=>"myusa",
68
+ "uid"=>"r03Ke0000000000FrqOOFlq0DeNc9q1QQQQQQQQC",
69
+ "info"=>{"email"=>"johnq@bloggs.com"},
70
+ "credentials"=>{"token"=>"3gnsgg14ymf54mquevfry38ao", "expires"=>false},
71
+ "extra"=>
72
+ {"raw_info"=>
73
+ {"title"=>nil,
74
+ "first_name"=>nil,
75
+ "middle_name"=>nil,
76
+ "last_name"=>nil,
77
+ "suffix"=>nil,
78
+ "address"=>nil,
79
+ "address2"=>nil,
80
+ "city"=>nil,
81
+ "state"=>nil,
82
+ "zip"=>nil,
83
+ "phone_number"=>nil,
84
+ "mobile_number"=>nil,
85
+ "gender"=>nil,
86
+ "marital_status"=>nil,
87
+ "is_parent"=>nil,
88
+ "is_retired"=>nil,
89
+ "is_veteran"=>nil,
90
+ "is_student"=>nil,
91
+ "email"=>"johnq@bloggs.com
92
+ "uid"=>"r03Ke0000000000FrqOOFlq0DeNc9q1QQQk390QC"
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ ## Watch the RailsCast
99
+
100
+ Ryan Bates has put together an excellent RailsCast on OmniAuth:
101
+
102
+ [![RailsCast #241](http://railscasts.com/static/episodes/stills/241-simple-omniauth-revised.png "RailsCast #241 - Simple OmniAuth (revised)")](http://railscasts.com/episodes/241-simple-omniauth-revised)
103
+
104
+ ## Contributing
105
+
106
+ 1. Fork it
107
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
108
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
109
+ 4. Push to the branch (`git push origin my-new-feature`)
110
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
10
+
11
+ desc 'Run specs'
12
+ task :default => :spec
data/example/.cfignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ .DS_Store
18
+ app.log
data/example/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'sinatra-reloader'
5
+ gem 'omniauth-myusa', git: 'git://github.com/18f/omniauth-myusa.git'
data/example/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # OmniAuth MyUSA Example Application
2
+
3
+ To set up a client application that points to a dev/staging version of MyUSA:
4
+
5
+ 1. Ensure you have Ruby installed - version 2.0 or greater.
6
+
7
+ 1. Install the Bundler gem:
8
+ ```bash
9
+ $ gem install bundler
10
+ ```
11
+
12
+ 1. Clone this repository locally and change to the `example` folder:
13
+ ```bash
14
+ $ git clone https://github.com/18F/omniauth-myusa/
15
+ $ cd omniauth-myusa/example
16
+ ```
17
+
18
+ 1. Use `bundle` to install the necessary dependencies:
19
+ ```bash
20
+ $ bundle install
21
+ ```
22
+
23
+ 1. Register a new client application with MyUSA at `https://my.usa.gov/oauth/applications`
24
+ 1. Set **Url** to `http://localhost:9292`
25
+ 2. Set **Redirect Uri** to `http://localhost:9292/auth/myusa/callback`
26
+
27
+ 1. Copy the application id and secret and set them as environment variables:
28
+ ```bash
29
+ $ export APP_ID=...
30
+ $ export APP_SECRET=...
31
+ ```
32
+
33
+ 1. Add the following to the `provider` call in `config.ru`:
34
+ ```ruby
35
+ provider :myusa, ENV['APP_ID'], ENV['APP_SECRET'], {
36
+ scope: %q(...),
37
+ client_options: {
38
+ site: 'http://<myusa host:port>',
39
+ token_url: '/oauth/token'
40
+ }
41
+ }
42
+ ```
43
+ where `:scope => %q(...)` is a space separated list of scopes that the client
44
+ application will request.
45
+
46
+ 1. Uncomment the following line in `config.ru` and set the correct url for this
47
+ dummy app (it will default to `http://localhost:9292`):
48
+ ```ruby
49
+ OmniAuth.config.full_host = "http://<dummy host:port>"
50
+ ```
51
+
52
+ 1. Run the dummy app:
53
+ ```bash
54
+ $ rackup
55
+ ```
56
+ or to run it as a daemon (you may want to set up logging):
57
+ ```bash
58
+ $ rackup -D
59
+ ```
data/example/app.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'sinatra'
2
+ require 'sinatra/reloader'
3
+ require 'yaml'
4
+
5
+ set :run, false
6
+ set :raise_errors, true
7
+
8
+ get '/' do
9
+ content_type 'text/html'
10
+ <<-END
11
+ <html>
12
+ <body>
13
+ <link href='//fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
14
+ <link href='//s3.amazonaws.com/myusa-static/button.min.css' rel='stylesheet' type='text/css'>
15
+ <p>
16
+ <a href="/auth/myusa" class="btn btn-social btn-myusa">Connect with MyUSA</a>
17
+ </p>
18
+ </body>
19
+ </html>
20
+ END
21
+ end
22
+
23
+ get '/auth/myusa/callback' do
24
+ content_type 'application/json'
25
+ MultiJson.encode(request.env)
26
+ end
27
+
28
+ get '/auth/failure' do
29
+ content_type 'application/json'
30
+ MultiJson.encode(request.env)
31
+ end
data/example/config.ru ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+ require 'omniauth-myusa'
3
+ require './app.rb'
4
+
5
+ use Rack::Session::Cookie, secret: 'secret'
6
+
7
+ # APP_ID an APP_SECRET are provided by MyUSA at the end of app registration,
8
+ # referred to as "Consumer Public Key" and "Consumer Secret Key" respectively.
9
+ # APP_URL is the URL for the front page of this app.
10
+ APP_ID = ENV['APP_ID'] || nil
11
+ APP_SECRET = ENV['APP_SECRET'] || nil
12
+ APP_URL = ENV['APP_URL'] || 'http://localhost:9292'
13
+ MYUSA_URL = ENV['MYUSA_URL'] || 'http://alpha.my.usa.gov'
14
+
15
+ OmniAuth.config.full_host = APP_URL
16
+
17
+ # To run the app, simply call `rackup` from the command line. If you would
18
+ # like to run as a daemon, call `rackup -D` ... if you do this, you should
19
+ # set up logging.
20
+
21
+ use OmniAuth::Builder do
22
+ provider :myusa, APP_ID, APP_SECRET,
23
+ scope: 'profile.email profile.last_name',
24
+ client_options: { site: MYUSA_URL, token_url: '/oauth/token' }
25
+ end
26
+
27
+ run Sinatra::Application
@@ -0,0 +1,2 @@
1
+ require "omniauth-myusa/version"
2
+ require 'omniauth/strategies/myusa'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Myusa
3
+ VERSION = "0.0.4"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Myusa < OmniAuth::Strategies::OAuth2
6
+ # Give your strategy a name.
7
+ option :name, "myusa"
8
+
9
+ # This is where you pass the options you would pass when
10
+ # initializing your consumer from the OAuth gem.
11
+ option :client_options, site: 'https://alpha.my.usa.gov', token_url: '/oauth/authorize'
12
+
13
+ # These are called after authentication has succeeded. If
14
+ # possible, you should try to set the UID without making
15
+ # additional calls (if the user id is returned with the token
16
+ # or as a URI parameter). This may not be possible with all
17
+ # providers.
18
+ uid{ raw_info['uid'] }
19
+
20
+ info do
21
+ {
22
+ :email => raw_info['email']
23
+ }
24
+ end
25
+
26
+ extra do
27
+ {
28
+ 'raw_info' => raw_info
29
+ }
30
+ end
31
+
32
+ def raw_info
33
+ @raw_info ||= access_token.get('/api/profile').parsed
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-myusa/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-myusa"
8
+ gem.version = Omniauth::Myusa::VERSION
9
+ gem.authors = ["Greg Gershman", "Christopher Papazian"]
10
+ gem.email = ["gregory.gershman@gsa.gov"]
11
+ gem.description = %q{OmniAuth strategy for MyUSA.}
12
+ gem.summary = %q{OmniAuth strategy for MyUSA.}
13
+ gem.homepage = "https://github.com/GSA-OCSIT/omniauth-myusa"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'omniauth', '~> 1.0'
21
+ # oauth2 gem locked hard at pre-1.4.0 because 1.4.0 breaks.
22
+ # See comments on https://github.com/intridea/omniauth-oauth2/commit/26152673224aca5c3e918bcc83075dbb0659717f
23
+ gem.add_dependency 'omniauth-oauth2', '1.3.1'
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Myusa do
4
+ subject do
5
+ OmniAuth::Strategies::Myusa.new({})
6
+ end
7
+
8
+ context "client options" do
9
+ it 'should have correct name' do
10
+ subject.options.name.should eq("myusa")
11
+ end
12
+
13
+ it 'should have correct site' do
14
+ subject.options.client_options.site.should eq('https://alpha.my.usa.gov')
15
+ end
16
+
17
+ it 'should have correct token url' do
18
+ subject.options.client_options.token_url.should eq('/oauth/authorize')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
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-myusa'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+ # Run specs in random order to surface order dependencies. If you find an
21
+ # order dependency and want to debug it, you can fix the order by providing
22
+ # the seed, which is printed after each run.
23
+ # --seed 1234
24
+ config.order = 'random'
25
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-myusa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Greg Gershman
8
+ - Christopher Papazian
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-03-04 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.3.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.3.1
42
+ description: OmniAuth strategy for MyUSA.
43
+ email:
44
+ - gregory.gershman@gsa.gov
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".ruby-version"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - example/.cfignore
57
+ - example/Gemfile
58
+ - example/README.md
59
+ - example/app.rb
60
+ - example/config.ru
61
+ - lib/omniauth-myusa.rb
62
+ - lib/omniauth-myusa/version.rb
63
+ - lib/omniauth/strategies/myusa.rb
64
+ - omniauth-myusa.gemspec
65
+ - spec/omniauth/strategies/myusa_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/GSA-OCSIT/omniauth-myusa
68
+ licenses: []
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.5.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: OmniAuth strategy for MyUSA.
90
+ test_files:
91
+ - spec/omniauth/strategies/myusa_spec.rb
92
+ - spec/spec_helper.rb