omniauth-whichsignupapi 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f0d5679f3ca7f95b2f17d2071e3257cf61dda41
4
+ data.tar.gz: 4e3526401c73da8fe74707ba05b7841904c27750
5
+ SHA512:
6
+ metadata.gz: 5e0b543272b68e09efe98ff5577085c87b0469e7be18a3edca3892ff700bb1b4ab034f08285a1a1e2182e669b0c42997d24a83c09ec51e1cf0988083122f6383
7
+ data.tar.gz: 560b172e593cd6aa55063c510a7ca69ceae6e1dfb7cc50e2f28aca46add41f623ce3be2211a60c925339c5e9e67bee2c0294691f044f49aeeec64845767eaaab
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-whichsignup.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Keith Lawrence
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.
@@ -0,0 +1,31 @@
1
+ # Omniauth::Whichsignup
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-whichsignup'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-whichsignup
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/omniauth-whichsignup/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,42 @@
1
+ require "omniauth"
2
+ require "omniauth/whichsignupapi/api_methods"
3
+ require "omniauth/whichsignupapi/auth_hash_delegate"
4
+ require "omniauth/whichsignupapi/auth_hash_delegator"
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Whichsignupapi
9
+ include OmniAuth::Strategy
10
+ include OmniAuth::Whichsignupapi::AuthHashDelegator
11
+
12
+ option :name, 'whichsignupapi'
13
+ option :api_url
14
+ option :api_secret
15
+ option :token_secret
16
+
17
+ def request_phase
18
+ form = OmniAuth::Form.new(:title => "Which? Login", :url => callback_path)
19
+ form.text_field "Email or Which? username", 'login'
20
+ form.text_field "Password", 'password'
21
+ form.button "Sign In"
22
+ form.to_response
23
+ end
24
+
25
+ def callback_phase
26
+ results = authenticate(request['login'], request['password'])
27
+ delegate_to(results)
28
+ super
29
+ end
30
+
31
+ def handles(login)
32
+ OmniAuth::Whichsignupapi::ApiMethods.handles(options['api_url'], options['api_secret'], options['token_secret'], login)
33
+ end
34
+
35
+ def authenticate(login, password, always_get_details = false)
36
+ result = OmniAuth::Whichsignupapi::ApiMethods.login(options['api_url'], options['api_secret'], options['token_secret'], login, password || '', always_get_details)
37
+ fail!(:invalid_credentials) unless result[:authenticated] || always_get_details
38
+ OmniAuth::Whichsignupapi::AuthHashDelegate.new(options['name'], result)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ require "omniauth/whichsignupapi/version"
2
+ require "omniauth/whichsignupapi/api_methods"
3
+ require "omniauth/whichsignupapi/auth_hash_delegate"
4
+ require "omniauth/whichsignupapi/auth_hash_delegator"
5
+ require "omniauth/whichsignupapi/delegator"
6
+ require "omniauth/whichsignupapi/token_tools"
7
+ require "omniauth/strategies/whichsignupapi"
@@ -0,0 +1,51 @@
1
+ module OmniAuth
2
+ module Whichsignupapi
3
+ module ApiMethods
4
+ def self.handles(url, secret, token_secret, login_id)
5
+ make_call(url, '/api/login/handles',
6
+ secret, token_secret,
7
+ login: login_id)
8
+ end
9
+
10
+ def self.login(url, secret, token_secret, login_id, password, always_get_details = false)
11
+ make_call(url,'/api/login',
12
+ secret, token_secret,
13
+ login: login_id,
14
+ password: password,
15
+ requested: 'screen_name,user_name,customer_id,b2b_customer,marketing_permission',
16
+ reply: always_get_details ? 'detailed' : 'standard ')
17
+ end
18
+
19
+ private
20
+
21
+ def self.make_call(url, path, secret, token_secret, params)
22
+ token = TokenTools.new(token_secret).generate_token(secret)
23
+
24
+ uri = URI.parse(url)
25
+
26
+ conn = Faraday.new(:url => url)
27
+
28
+ conn.basic_auth(uri.user, uri.password) unless uri.user.nil?
29
+
30
+ response = conn.get do |req|
31
+ req.url path
32
+ req.params.merge!(params)
33
+ req.params['token'] = token
34
+ end
35
+
36
+ fail "Connection Problem: [#{response.status}]" unless response.status == 200
37
+
38
+ results = JSON.parse response.body
39
+ expand_and_clean_results(token_secret, results)
40
+ end
41
+
42
+ def self.expand_and_clean_results(token_secret, results)
43
+ if results['token']
44
+ token = TokenTools.new(token_secret).decode_token(results['token'])
45
+ results.merge!(YAML::load(token[:token_data])) if token[:token_data]
46
+ end
47
+ results.each_with_object({}) { |i,o| o[i[0].to_sym] = i[1] }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,37 @@
1
+ module OmniAuth
2
+ module Whichsignupapi
3
+ class AuthHashDelegate
4
+ def initialize(provider_name, user_info)
5
+ @user_info = user_info
6
+ @provider_name = provider_name
7
+ end
8
+
9
+ def provider
10
+ @provider_name
11
+ end
12
+
13
+ def raw
14
+ @user_info
15
+ end
16
+
17
+ def uid
18
+ @user_info[:customer_id]
19
+ end
20
+
21
+ def info
22
+ {
23
+ name: @user_info[:screen_name] || @user_info[:user_name],
24
+ nickname: @user_info[:screen_name]
25
+ }
26
+ end
27
+
28
+ def extra
29
+ {
30
+ as: @user_info[:as],
31
+ user_name: @user_info[:user_name],
32
+ raw_info: @user_info
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module OmniAuth
2
+ module Whichsignupapi
3
+ module AuthHashDelegator
4
+ def delegate_to(delegate)
5
+ @delegate = delegate
6
+ end
7
+
8
+ def uid
9
+ @delegate ? @delegate.uid : super
10
+ end
11
+
12
+ def info
13
+ @delegate ? @delegate.info : super
14
+ end
15
+
16
+ def extra
17
+ @delegate ? @delegate.extra : super
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module OmniAuth
2
+ module Whichsignupapi
3
+ module Delegator
4
+ include OmniAuth::Whichsignupapi::AuthHashDelegator
5
+
6
+ def delegate_strategy
7
+ return @delegate_strategy unless @delegate_strategy.nil?
8
+ config = Devise.omniauth_configs[:whichsignupapi]
9
+ @delegate_strategy = config.strategy_class.new(config.strategy_name, config.args.first)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module OmniAuth
2
+ module Whichsignupapi
3
+ class TokenTools
4
+ def initialize(password)
5
+ @password = password
6
+ end
7
+
8
+ def generate_token(token_data)
9
+ raise 'token generations not possible is token is blank' if token_data.blank?
10
+ t = "#{token_data}|#{Time.now.to_i}"
11
+ get_cipher.encrypt(t)
12
+ end
13
+
14
+ def decode_token(token)
15
+ dec = get_cipher.decrypt(token)
16
+ parts = dec.split('|')
17
+ {
18
+ time: parts.pop,
19
+ token_data: parts.join('|')
20
+ }
21
+ end
22
+
23
+ private
24
+
25
+ def get_cipher
26
+ Gibberish::AES::CBC.new(@password)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Whichsignupapi
3
+ VERSION = "0.0.6"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/whichsignupapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-whichsignupapi"
8
+ spec.version = OmniAuth::Whichsignupapi::VERSION
9
+ spec.authors = ["Keith Lawrence"]
10
+ spec.email = ["keith@kludge.co.uk"]
11
+ spec.summary = %q{Omniauth gem for logging into Which? via the signup API}
12
+ spec.description = %q{Omniauth gem for logging into Which? via the signup API}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "omniauth", "~> 1.0"
22
+ spec.add_dependency "faraday", "~> 0.8"
23
+ spec.add_dependency "gibberish", "~> 2.0"
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-whichsignupapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Keith Lawrence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gibberish
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Omniauth gem for logging into Which? via the signup API
84
+ email:
85
+ - keith@kludge.co.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/omniauth/strategies/whichsignupapi.rb
96
+ - lib/omniauth/whichsignupapi.rb
97
+ - lib/omniauth/whichsignupapi/api_methods.rb
98
+ - lib/omniauth/whichsignupapi/auth_hash_delegate.rb
99
+ - lib/omniauth/whichsignupapi/auth_hash_delegator.rb
100
+ - lib/omniauth/whichsignupapi/delegator.rb
101
+ - lib/omniauth/whichsignupapi/token_tools.rb
102
+ - lib/omniauth/whichsignupapi/version.rb
103
+ - omniauth-whichsignupapi.gemspec
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Omniauth gem for logging into Which? via the signup API
128
+ test_files: []