omniauth-bolt 0.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
+ SHA256:
3
+ metadata.gz: ef01fcc3c94ba30af520dd517366bfe075b6877cc27c58724e2325e7e6ac7915
4
+ data.tar.gz: '080285b45ae56a4111d0ad2b7ff6f8915e6dbac3b4e9ee1dbb3d210202afb1d5'
5
+ SHA512:
6
+ metadata.gz: 3a1ce018932d2431c9f023b5d6c7c2f5db00f7257f97d583392288fc88ff858f931e7383dd23b2ce5087e6db4a2dcdd17efed2de1d21fdfb747dd5ad9c9b0e8b
7
+ data.tar.gz: 646f8f4666b614019f9d963ba86cd79cd062b1608fb2a8db365479471e6653880e765dc570415b16917972b1f02b6fa9657b1431c1f6b7938d7bc96faee5d376
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ dist: trusty
2
+
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.9
6
+ - 2.3.6
7
+ - 2.4.3
8
+ - 2.5.0
9
+ - jruby-1.7.26
10
+ - rbx-3
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: rbx-3
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,40 @@
1
+ # Contributing
2
+
3
+ For the best chance of having your changes merged, please:
4
+
5
+ * Fork the project.
6
+
7
+ * Make your feature addition or bug fix.
8
+
9
+ * Add tests for it. This is important so it is not accidentally broken in a future version.
10
+
11
+ * Commit, do not mess with rakefile, version, or history. (If you want to have your own version, that is fine but bump version in a commit by itself so it can be ignored when pulled).
12
+
13
+ * Send a pull request. Bonus points for topic branches.
14
+
15
+ If your proposed changes only affect documentation, include the following on a
16
+ new line in each of your commit messages:
17
+
18
+ ```
19
+ [ci skip]
20
+ ```
21
+
22
+ This will signal [Travis](https://travis-ci.org) that running the test suite is
23
+ not necessary for these changes.
24
+
25
+ # Reporting Bugs
26
+
27
+ If you are experiencing unexpected behavior and, after having read [omniauth](https://github.com/intridea/omniauth) and [omniauth-bolt](https://github.com/nebulab/omniauth-bolt)'s documentation, are convinced this behavior is a bug, please:
28
+
29
+ 1. [Search](https://github.com/nebulab/omniauth-bolt/issues) existing issues.
30
+ 2. Collect enough information to reproduce the issue:
31
+
32
+ * omniauth-bolt version
33
+
34
+ * Ruby version
35
+
36
+ * Specific setup conditions
37
+
38
+ * Description of expected behavior
39
+
40
+ * Description of actual behavior
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ if Gem::Version.create(RUBY_VERSION) < Gem::Version.create('2.0.0')
9
+ # for jruby 1.7.x
10
+ gem 'addressable', '2.4.0'
11
+ end
12
+
13
+ gem 'rack', '~> 1.6' if Gem::Version.create(RUBY_VERSION) < Gem::Version.create('2.2.2')
14
+
15
+ gem 'rack-test'
16
+ gem 'rspec', '~> 3.2'
17
+ gem 'simplecov'
18
+ gem 'webmock'
19
+ end
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # OmniAuth Bolt
2
+
3
+ This gem contains the Bolt strategy for OmniAuth.
4
+
5
+
6
+ ## Before You Begin
7
+
8
+ You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/omniauth/omniauth) to get started.
9
+
10
+ # Link the Bolt documentation page
11
+ ## Using This Strategy
12
+
13
+ First start by adding this gem to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'omniauth-bolt'
17
+ ```
18
+
19
+ If you need to use the latest HEAD version, you can do so with:
20
+
21
+ ```ruby
22
+ gem 'omniauth-bolt', :github => 'nebulab/ominauth-bolt'
23
+ ```
24
+
25
+ Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
26
+
27
+ ```ruby
28
+ Rails.application.config.middleware.use OmniAuth::Builder do
29
+ provider :bolt, "API_KEY", "PUBLISHABLE_API"
30
+ end
31
+ ```
32
+
33
+ Replace `"API_KEY"` and `"PUBLISHABLE_KEY"` with the appropriate values you obtained [earlier](https://merchant.bolt.com/developers).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Run specs'
7
+ RSpec::Core::RakeTask.new
8
+
9
+ desc 'Default: run specs.'
10
+ task default: :spec
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth'
4
+ require 'json'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Bolt
9
+ include OmniAuth::Strategy
10
+
11
+ attr_reader :access_token, :user_uid
12
+
13
+ option :name, 'bolt'
14
+
15
+ ENVIRONMENT_URLS = {
16
+ production: 'https://api.bolt.com',
17
+ sandbox: 'https://api-sandbox.bolt.com',
18
+ staging: 'https://api-staging.bolt.com'
19
+ }.freeze
20
+
21
+ args %i[publishable_key api_key]
22
+
23
+ uid { user_uid }
24
+
25
+ info do
26
+ {
27
+ 'email' => raw_info['email'],
28
+ 'first_name' => raw_info['first_name'],
29
+ 'last_name' => raw_info['last_name'],
30
+ }
31
+ end
32
+
33
+ def request_phase
34
+ OmniAuth::Form.build(:title => options.title, :url => callback_path) do
35
+ text_field 'Email', 'email'
36
+ end.to_response
37
+
38
+ session[:authorization_code] = request.params['authorization_code']
39
+ session[:scope] = request.params['scope']
40
+
41
+ redirect callback_url
42
+ end
43
+
44
+ def callback_phase
45
+ payload = {
46
+ grant_type: 'authorization_code',
47
+ code: session['authorization_code'],
48
+ client_id: options['publishable_key'],
49
+ # scope: 'openid+bolt.account.manage',
50
+ scope: session['scope'],
51
+ client_secret: options['api_key']
52
+ }
53
+
54
+ api_uri = "#{ENVIRONMENT_URLS[ENV['BOLT_ENVIRONMENT'].to_sym]}/v1/oauth/token"
55
+ uri = URI(api_uri)
56
+ http = Net::HTTP.new(uri.host, uri.port)
57
+ http.set_debug_output $stdout
58
+ if uri.scheme == 'https'
59
+ http.use_ssl = true
60
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
61
+ end
62
+
63
+ req = Net::HTTP::Post.new(uri.request_uri)
64
+ post_data = URI.encode_www_form(payload)
65
+ res = http.request(req, post_data)
66
+ response = JSON.parse(res.body)
67
+ @access_token = response['access_token']
68
+ @user_uid = response['id_token']
69
+
70
+ super
71
+ end
72
+
73
+ def raw_info
74
+ @raw_info ||= begin
75
+ get_account_details = "#{ENVIRONMENT_URLS[ENV['BOLT_ENVIRONMENT'].to_sym]}/v1/account"
76
+ uri = URI(get_account_details)
77
+ http = Net::HTTP.new(uri.host, uri.port)
78
+ http.set_debug_output $stdout
79
+ if uri.scheme == 'https'
80
+ http.use_ssl = true
81
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
82
+ end
83
+ req = Net::HTTP::Get.new(uri.request_uri)
84
+
85
+ req['Authorization'] = "Bearer #{access_token}"
86
+ req['Content-Type'] = 'application/json'
87
+ req['Accept'] = 'application/json'
88
+ req['X-API-KEY'] = options['api_key']
89
+
90
+ res = http.request(req)
91
+ JSON.parse(res.body)['profile']
92
+ end
93
+ rescue ::Errno::ETIMEDOUT
94
+ raise ::Timeout::Error
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Bolt
5
+ VERSION = '0.0.0'
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-bolt/version'
4
+ require 'omniauth/strategies/bolt'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+ require 'omniauth-bolt/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'omniauth-bolt'
8
+ s.version = OmniAuth::Bolt::VERSION
9
+ s.authors = ['Daniele Palombo']
10
+ s.email = ['danielepalombo@nebulab.com']
11
+ s.homepage = 'https://github.com/nebulab/omniauth-bolt'
12
+ s.description = 'OmniAuth strategy for Bolt'
13
+ s.summary = s.description
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+ s.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
21
+ s.add_dependency 'omniauth-oauth', '~> 1.1'
22
+ s.add_dependency 'rack'
23
+ s.add_development_dependency 'bundler', '~> 1.0'
24
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe OmniAuth::Strategies::Bolt do
6
+ let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
7
+
8
+ describe 'client options' do
9
+ it 'should have correct name' do
10
+ expect(subject.options.name).to eq('bolt')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path(__dir__)
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
+ require 'simplecov'
6
+ SimpleCov.start do
7
+ minimum_coverage(94.59)
8
+ end
9
+ require 'rspec'
10
+ require 'rack/test'
11
+ require 'webmock/rspec'
12
+ require 'omniauth'
13
+ require 'omniauth-bolt'
14
+
15
+ RSpec.configure do |config|
16
+ config.include WebMock::API
17
+ config.include Rack::Test::Methods
18
+ config.extend OmniAuth::Test::StrategyMacros, type: :strategy
19
+ config.expect_with :rspec do |c|
20
+ c.syntax = :expect
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-bolt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniele Palombo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-10 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: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: OmniAuth strategy for Bolt
56
+ email:
57
+ - danielepalombo@nebulab.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CONTRIBUTING.md
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - lib/omniauth-bolt.rb
70
+ - lib/omniauth-bolt/version.rb
71
+ - lib/omniauth/strategies/bolt.rb
72
+ - omniauth-bolt.gemspec
73
+ - spec/omniauth/strategies/bolt_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/nebulab/omniauth-bolt
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.9.3
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.7.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: OmniAuth strategy for Bolt
99
+ test_files:
100
+ - spec/omniauth/strategies/bolt_spec.rb
101
+ - spec/spec_helper.rb