omniauth-7digital 1.0.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: 310d23e9dc15ce1c2e3f55bcc3495022f8a610a9
4
+ data.tar.gz: 434647ea57f630136bef82be05a6b64d22885ffd
5
+ SHA512:
6
+ metadata.gz: 73b17d052a0b2ae547d756abafa897c0d9a5b604f1d8d974fb0c20685e1f605e4ac1dc099cb0fe6877c9475e7b2cc82729d9d69ac0d398073fa3b20978805b9b
7
+ data.tar.gz: 0342ea7dca542e9cd18e579cd2b3cc997f526167a91408eb6014ad7ef80ef68b95c491e78a667c67924d275ccb5d60deda0b5eba56e6772d0508097e7cc0ac22
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'rspec', '~> 3.2'
9
+ gem 'rack-test'
10
+ gem 'simplecov'
11
+ gem 'webmock'
12
+ end
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ OmniAuth 7digital
2
+ ==============
3
+
4
+ This gem contains the 7digital strategy for OmniAuth.
5
+
6
+ For more information about the 7digital api: http://developer.7digital.com/
7
+
8
+ How To Use It
9
+ -------------
10
+
11
+ If you are using Rails, you need to add the gem to your `Gemfile`:
12
+
13
+ gem 'omniauth-7digital'
14
+
15
+ You can pull them in directly from GitHub e.g.:
16
+
17
+ gem 'omniauth-7digital', :git => 'git://github.com/Musikee/omniauth-7digital.git'
18
+
19
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
20
+
21
+ Rails.application.config.middleware.use OmniAuth::Builder do
22
+ provider :seven_digital, 'consumer_key', 'consumer_secret'
23
+ end
24
+
25
+ You will obviously have to put in your key and secret, which you can get from https://api-signup.7digital.com/
26
+
27
+
28
+ After you have the gem running and the configuration is done, you can get to the follow url to log the user in:
29
+
30
+ http://localhost:3000/auth/seven_digital
31
+
32
+ Now just follow the README at: https://github.com/intridea/omniauth
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Run specs'
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require 'omniauth-7digital/version'
2
+ require 'omniauth/strategies/7digital'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module SevenDigital
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'omniauth-oauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class SevenDigital < OmniAuth::Strategies::OAuth
6
+
7
+ option :name, 'seven_digital'
8
+
9
+ option :client_options, { :access_token_path => '/1.2/oauth/accesstoken',
10
+ :request_token_path => '/1.2/oauth/requesttoken',
11
+ :site => 'https://api.7digital.com' }
12
+
13
+ def request_phase
14
+ request_token = consumer.get_request_token({ :exclude_callback => true }, options.request_params)
15
+ session['oauth'] ||= {}
16
+ session['oauth'][name.to_s] = { 'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret }
17
+
18
+ params = { :oauth_token => request_token.token, :oauth_callback => callback_url }.map { |key, value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
19
+ redirect "https://account.7digital.com/#{options.consumer_key}/oauth/authorise?#{params}"
20
+ rescue ::Timeout::Error => e
21
+ fail!(:timeout, e)
22
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
23
+ fail!(:service_unavailable, e)
24
+ end
25
+
26
+ def callback_phase
27
+ fail(OmniAuth::NoSessionError, 'Session Expired') if session['oauth'].nil?
28
+
29
+ request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
30
+
31
+ @access_token = request_token.get_access_token({}, {})
32
+
33
+ env['omniauth.auth'] = auth_hash
34
+ call_app!
35
+ rescue ::Timeout::Error => e
36
+ fail!(:timeout, e)
37
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
38
+ fail!(:service_unavailable, e)
39
+ rescue ::OAuth::Unauthorized => e
40
+ fail!(:invalid_credentials, e)
41
+ rescue ::OmniAuth::NoSessionError => e
42
+ fail!(:session_expired, e)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth-7digital/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-7digital'
7
+ s.version = OmniAuth::SevenDigital::VERSION
8
+ s.authors = ['Fabio Cantoni']
9
+ s.email = ['cover@revoc.net']
10
+ s.homepage = 'https://github.com/Musikee/omniauth-7digital'
11
+ s.description = 'OmniAuth strategy for 7digital'
12
+ s.summary = s.description
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_dependency 'omniauth-oauth', '~> 1.1'
21
+ s.add_development_dependency 'bundler', '~> 1.0'
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::SevenDigital do
4
+ subject do
5
+ OmniAuth::Strategies::SevenDigital.new({})
6
+ end
7
+
8
+ context 'client options' do
9
+ it 'should have correct name' do
10
+ expect(subject.options.name).to eq('seven_digital')
11
+ end
12
+
13
+ it 'should have correct site' do
14
+ expect(subject.options.client_options.site).to eq('https://api.7digital.com')
15
+ end
16
+
17
+ it 'should have correct request token url' do
18
+ expect(subject.options.client_options.request_token_path).to eq('/1.2/oauth/requesttoken')
19
+ end
20
+
21
+ it 'should have correct access token url' do
22
+ expect(subject.options.client_options.access_token_path).to eq('/1.2/oauth/accesstoken')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ minimum_coverage(94.59)
6
+ end
7
+ require 'rspec'
8
+ require 'rack/test'
9
+ require 'webmock/rspec'
10
+ require 'omniauth'
11
+ require 'omniauth-7digital'
12
+
13
+ RSpec.configure do |config|
14
+ config.include WebMock::API
15
+ config.include Rack::Test::Methods
16
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-7digital
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Cantoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: OmniAuth strategy for 7digital
42
+ email:
43
+ - cover@revoc.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - lib/omniauth-7digital.rb
53
+ - lib/omniauth-7digital/version.rb
54
+ - lib/omniauth/strategies/7digital.rb
55
+ - omniauth-7digital.gemspec
56
+ - spec/omniauth/strategies/7digital_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: https://github.com/Musikee/omniauth-7digital
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: OmniAuth strategy for 7digital
82
+ test_files:
83
+ - spec/omniauth/strategies/7digital_spec.rb
84
+ - spec/spec_helper.rb