omniauth-ldsconnect 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94b515b100271b97d8a801770ca2feec45d028ff
4
+ data.tar.gz: ad66c17958d21a2e4848027e437a666ed391612a
5
+ SHA512:
6
+ metadata.gz: 6d479d6202394e3de3c7937ab8aae4f5e1e5113bd9469d8c5d79176a993ee4c7673be5082835af41047fb2d229eaa7fc7214b68776f325412f1c233bfbae2c14
7
+ data.tar.gz: 815b6dfcc96527f68f2537f975ed1d5a1cd1ca8d2a7f05ee5116758e3389cf41c519502a5243e5dcd6da43a32ebe790c2b98862e66a56340f6494db9f714f732
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-ldsconnect.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'rack'
8
+ gem 'rack-test'
9
+ gem 'rspec', '~> 2.12.0'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Randy Secrist
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,31 @@
1
+ # Omniauth::LDSConnect
2
+
3
+ This is a OmniAuth strategy for authenticating to LDS Connect. To
4
+ use it, you'll need to sign up for an OAuth2 Application ID and Secret on the
5
+ [LDS Connect Applications Page](https://ldsconnect.org).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'omniauth-ldsconnect'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-ldsconnect
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler/gem_tasks"
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc "Run Unit Specs Only"
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.rspec_opts = %w[--profile --tag ~integration --tag ~slow]
10
+ end
11
+
12
+ desc "Run All Specs (including slow specs)"
13
+ RSpec::Core::RakeTask.new(:ci) do |spec|
14
+ spec.rspec_opts = %w[--profile]
15
+ end
16
+ task :default => :ci
data/THANKS ADDED
@@ -0,0 +1,5 @@
1
+ The following people have contributed to the omniauth-ldsconnect gem to make it better. (If you're not listed here and you should be, please email randy.secrist@gmail.com.)
2
+
3
+ THANKS
4
+ ------
5
+ Randy Secrist
@@ -0,0 +1,7 @@
1
+ require "omniauth-ldsconnect/version"
2
+ require 'omniauth-ldsconnect/strategies/ldsconnect'
3
+ module Omniauth
4
+ module Ldsconnect
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,80 @@
1
+ require 'omniauth/strategies/oauth2'
2
+ require 'base64'
3
+ require 'openssl'
4
+ require 'rack/utils'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Ldsconnect < OmniAuth::Strategies::OAuth2
9
+ class NoAuthorizationCodeError < StandardError; end
10
+
11
+ DEFAULT_SCOPE = ''
12
+
13
+ option :client_options, {
14
+ site: 'https://ldsconnect.org',
15
+ authorize_url: '/dialog/authorize',
16
+ token_url: '/oauth/token',
17
+ profile_url: '/api/ldsorg/me'
18
+ }
19
+
20
+ option :token_params, {
21
+ parse: :query
22
+ }
23
+
24
+ option :access_token_options, {
25
+ header_format: 'OAuth %s',
26
+ param_name: 'access_token'
27
+ }
28
+
29
+ option :authorize_options, [:scope]
30
+
31
+ uid { profile_info['currentUserId'] }
32
+
33
+ extra do
34
+ profile_info
35
+ end
36
+
37
+ def profile_info
38
+ url = "#{options.client_options[:profile_url]}?access_token=#{access_token.token}"
39
+ @profile_info ||= access_token.get(url).parsed || { }
40
+ end
41
+
42
+ def authorize_params
43
+ super.tap do |params|
44
+ params[:scope] ||= DEFAULT_SCOPE
45
+ end
46
+ end
47
+
48
+ def build_access_token
49
+ ssl_options = options.client_options[:ssl].to_hash.symbolize_keys rescue {}
50
+ token_client = Faraday.new url: options.client_options[:site], ssl: ssl_options
51
+ post_params = {
52
+ grant_type: 'authorization_code',
53
+ code: request.params['code'],
54
+ redirect_uri: self.callback_url,
55
+ }
56
+ auth = "Basic #{Base64.encode64([options.client_id, options.client_secret].join(':')).gsub("\n", '')}"
57
+ resp = token_client.post(options.client_options[:token_url], post_params, 'Authorization'=>auth)
58
+ decoded = MultiJson.decode resp.body
59
+ token = decoded["access_token"]
60
+ self.access_token = ::OAuth2::AccessToken.from_hash client, decoded.merge(access_token_options)
61
+ end
62
+
63
+ private
64
+ def access_token_options
65
+ options.access_token_options.inject({ }) do |hash, (key, value)|
66
+ hash[key.to_sym] = value
67
+ hash
68
+ end
69
+ end
70
+
71
+ def prune!(hash)
72
+ hash.delete_if do |_, value|
73
+ prune!(value) if value.is_a?(Hash)
74
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Ldsconnect
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-ldsconnect/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Randy Secrist"]
6
+ gem.email = ["randy.secrist@gmail.com"]
7
+ gem.description = %q{OmniAuth plugin for LDS Connect}
8
+ gem.summary = %q{OmniAuth plugin for LDS Connect}
9
+ gem.homepage = "https://ldsconnect.org"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "omniauth-ldsconnect"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Omniauth::Ldsconnect::VERSION
17
+
18
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.0.2'
19
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Ldsconnect do
4
+ let(:access_token) { stub('AccessToken', :options => {}) }
5
+ let(:parsed_response) { stub('ParsedResponse') }
6
+ let(:response) { stub('Response', :parsed => parsed_response) }
7
+
8
+ subject do
9
+ OmniAuth::Strategies::Ldsconnect.new({})
10
+ end
11
+
12
+ before(:each) do
13
+ subject.stub!(:access_token).and_return(access_token)
14
+ end
15
+
16
+ context "client options" do
17
+ it 'should have correct site' do
18
+ subject.options.client_options.site.should eq("https://ldsconnect.org")
19
+ end
20
+
21
+ it 'should have correct authorize_url ' do
22
+ subject.options.client_options.authorize_url.should eq("/dialog/authorize")
23
+ end
24
+
25
+ it 'should have correct token_url ' do
26
+ subject.options.client_options.token_url.should eq("/oauth/token")
27
+ end
28
+ end
29
+
30
+ context "access token options" do
31
+ it 'should have correct header_format' do
32
+ subject.options.access_token_options.header_format eq("OAuth %s")
33
+ end
34
+
35
+ it 'should have correct param_name ' do
36
+ subject.options.access_token_options.param_name.should eq("access_token")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'rspec'
4
+ require 'rack/test'
5
+ require 'omniauth'
6
+ require 'omniauth-ldsconnect'
7
+
8
+ RSpec.configure do |config|
9
+ config.include Rack::Test::Methods
10
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = [:should, :expect]
13
+ end
14
+ end
15
+
16
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-ldsconnect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Randy Secrist
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-17 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: 1.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.2
27
+ description: OmniAuth plugin for LDS Connect
28
+ email:
29
+ - randy.secrist@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - THANKS
40
+ - lib/omniauth-ldsconnect.rb
41
+ - lib/omniauth-ldsconnect/strategies/ldsconnect.rb
42
+ - lib/omniauth-ldsconnect/version.rb
43
+ - omniauth-ldsconnect.gemspec
44
+ - spec/omniauth/strategies/ldsconnect_spec.rb
45
+ - spec/spec_helper.rb
46
+ homepage: https://ldsconnect.org
47
+ licenses: []
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.2.2
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: OmniAuth plugin for LDS Connect
69
+ test_files:
70
+ - spec/omniauth/strategies/ldsconnect_spec.rb
71
+ - spec/spec_helper.rb