omniauth-braintree-auth 1.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: fcb64826d70f5ae6149befcdd8039f62581e6095
4
+ data.tar.gz: c72a91dddb46120d492f6595d7662a5da1dd9df8
5
+ SHA512:
6
+ metadata.gz: f3aacede0a4f2ff7be4d51d6d8c715fc66a487bec49e99e2486b25d2832431115a023060c8dfd187eba5715e01d66f4de02122ada54a5edd082c80b5d484a92f
7
+ data.tar.gz: bffe9306e5a2686ee411aac504802997ba69be897d5c59becf4094025f34157af118ceedbd88ce819590a77007705ef8e6ce203dd11894f1aa1ec481182c5ea8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'pry'
5
+ end
6
+
7
+ # Specify your gem's dependencies in omniauth-braintree-auth.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # OmniAuth Braintree Auth
2
+
3
+ An [OmniAuth](https://github.com/intridea/omniauth) strategy for [Braintree Auth](https://www.braintreepayments.com/products-and-features/braintree-auth).
4
+
5
+ Braintree Auth is currently in closed beta, use the link above to request access.
6
+ ## Installation
7
+
8
+ Add it to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'omniauth-braintree-auth'
12
+ ```
13
+
14
+ And then run:
15
+
16
+ $ bundle
17
+
18
+ ## Usage
19
+
20
+ It's helpful to have a general understanding of how OmniAuth works and what it provides before diving into a particular strategy. I recommend checking out the [OmniAuth documentation](https://github.com/intridead/omniauth) for more information.
21
+
22
+ The Braintree Auth strategy allows you pass a `client_id`, `client_secret`, `redirect_uri`, `scope`, `environment`, and `landing_page` as configuration options. Example usage in a Rack application:
23
+
24
+ ```ruby
25
+ use OmniAuth::Builder do
26
+ provider :braintree_auth,
27
+ "your_client_id", "your_client_secret",
28
+ :scope => "read_write", # required
29
+ :redirect_uri => "http://localhost:4567/auth/braintree_auth/callback", # required
30
+ :landing_page => "login" # optional, one of 'signup' or 'login'
31
+ :environment => "production" # optional, defaults to sandbox
32
+ end
33
+ ```
34
+
35
+ or, in Rails:
36
+
37
+ ```ruby
38
+ Rails.application.config.middleware.use OmniAuth::Builder do
39
+ provider :braintree_auth,
40
+ "your_client_id", "your_client_secret",
41
+ :scope => "read_write", # required
42
+ :redirect_uri => "http://localhost:4567/auth/braintree_auth/callback", # required
43
+ :landing_page => "login" # optional, one of 'signup' or 'login'
44
+ :environment => "production" # optional, defaults to sandbox
45
+ end
46
+ ```
47
+
48
+ ### Environment
49
+
50
+ The Braintree Auth strategy makes requests against Braintree's sandbox environment by default, which is useful for testing your integration. When you are ready to go live, be sure to specify `environment => "production"` when building your strategy.
51
+
52
+ ### Redirect
53
+
54
+ To send your users to Braintree, simply point them to `/auth/braintree_auth` in your application. It's best practice to have your users click the "Connect with Braintree" button provided by Braintree to kick off this redirect.
55
+
56
+ ```
57
+ <a href="/auth/braintree_auth">
58
+ <img src="https://s3-us-west-1.amazonaws.com/bt-partner-assets/connect-braintree.png" alt="Connect with Braintree" width="328" height="44">
59
+ </a>
60
+ ```
61
+
62
+ ### Callback
63
+
64
+ After signing up with Braintree or authorizing access to an existing account, the user will be sent back to your site to the redirect URI you provided. For OmniAuth, this must be at the path `/auth/braintree_auth/callback`. Be sure that this URI is whitelisted under your OAuth Application configuration in the Braintree Control Panel (Settings > OAuth Applications).
65
+
66
+ Once redirected, the Braintree merchant ID, access token, and refresh token will be available in `request.env['omniauth.auth']`
67
+
68
+ Here is an example auth hash provided in `request.env['omniauth.auth']`:
69
+
70
+ ```ruby
71
+ {
72
+ uid: "braintree_merchant_id",
73
+ info: { merchant_id: "braintree_merchant_id" },
74
+ credentials: {
75
+ access_token: "access_token$sandbox$example_access_token"
76
+ refresh_token: "access_token$sandbox$refresh_token"
77
+ expires_at: "2026-06-14 19:49:02 UTC"
78
+ }
79
+ }
80
+ ```
81
+
82
+ you can then use this information in your application:
83
+
84
+ ```ruby
85
+
86
+ get '/auth/braintree_auth/callback do
87
+ auth_hash = request.env['omniauth.auth']
88
+
89
+ access_token = auth_hash['credentials']['access_token']
90
+ end
91
+ ```
92
+
93
+ ## Example
94
+
95
+ Here is a full example Sinatra application using `omniauth-braintree-auth`. It simply displays the user's access token after they are redirected.
96
+
97
+ ```ruby
98
+ require 'sinatra/base'
99
+ require 'omniauth-braintree-auth'
100
+
101
+ class TestApp < Sinatra::Base
102
+ enable :method_override
103
+ enable :sessions
104
+
105
+ use Rack::Session::Cookie
106
+
107
+ use OmniAuth::Builder do
108
+ provider :braintree_auth,
109
+ ENV['BRAINTREE_AUTH_CLIENT_ID'], ENV['BRAINTREE_AUTH_CLIENT_SECRET']
110
+ :scope => "read_write",
111
+ :redirect_uri => "http://127.0.0.1:4567/auth/braintree_auth/callback",
112
+ :landing_page => "login",
113
+ :environment => "sandbox",
114
+ end
115
+
116
+ get '/' do
117
+ '<a href="/auth/braintree_auth">
118
+ <img src="https://s3-us-west-1.amazonaws.com/bt-partner-assets/connect-braintree.png" alt="Connect with Braintree" width="328" height="44">
119
+ </a>'
120
+ end
121
+
122
+ get '/auth/braintree_auth/callback' do
123
+ auth_hash = request.env['omniauth.auth']
124
+ merchant_id = auth_hash['uid']
125
+ access_token = auth_hash['credentials']['access_token']
126
+
127
+ "#{access_token} can be used to access merchant #{merchant_id}"
128
+ end
129
+ end
130
+
131
+ TestApp.run!
132
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/braintree/auth"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/braintree_auth'
@@ -0,0 +1,64 @@
1
+ require 'omniauth-oauth2'
2
+ require 'base64'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class BraintreeAuth < OmniAuth::Strategies::OAuth2
7
+ option :name, :braintree_auth
8
+ option :environment, "sandbox"
9
+
10
+ option :client_options, {
11
+ :authorize_url => "/oauth/connect",
12
+ :site => "https://api.sandbox.braintreegateway.com",
13
+ :token_url => "/oauth/access_tokens",
14
+ :raise_errors => false,
15
+ }
16
+
17
+ option :authorize_options, [:scope, :redirect_uri, :landing_page]
18
+
19
+ credentials do
20
+ access_token.params["credentials"]
21
+ end
22
+
23
+ uid do
24
+ request.params["merchantId"]
25
+ end
26
+
27
+ info do
28
+ {"merchant_id" => request.params["merchantId"]}
29
+ end
30
+
31
+ def setup_phase
32
+ options.client_options.site = "https://api.braintreegateway.com" if options.environment == "production"
33
+
34
+ # application/xml content type is not recognized as XML by OAuth2 gem, so we must register it manually
35
+ # https://github.com/intridea/oauth2/pull/255 would add it as a registered content type
36
+ ::OAuth2::Response.register_parser(:xml, "application/xml") { |body| MultiXml.parse(body) }
37
+ end
38
+
39
+ def request_phase
40
+ # Braintree requires a custom signature for authorization requests
41
+ base_url = client.auth_code.authorize_url(authorize_params)
42
+ signature = compute_signature(base_url)
43
+ authorize_url = "#{base_url}&signature=#{signature}&algorithm=SHA256"
44
+ redirect authorize_url
45
+ end
46
+
47
+ def build_access_token
48
+ options.token_params.merge!(:headers => authorization_header)
49
+ super
50
+ end
51
+
52
+ private
53
+
54
+ def authorization_header
55
+ {"Authorization" => "Basic #{::Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")}"}
56
+ end
57
+
58
+ def compute_signature(url)
59
+ key_digest = OpenSSL::Digest::SHA256.digest(options["client_secret"])
60
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, key_digest, url)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module BraintreeAuth
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth-braintree-auth/version'
2
+ require 'omniauth/braintree_auth'
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-braintree-auth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-braintree-auth"
8
+ spec.version = OmniAuth::BraintreeAuth::VERSION
9
+ spec.authors = ["Alex Kowalczuk"]
10
+ spec.email = ["askowalczuk93@gmail.com"]
11
+
12
+ spec.summary = "OmniAuth Strategy for Braintree Auth"
13
+ spec.description = "OmniAuth Strategy for Braintree Auth, allows easy integration with the Braintree Auth API through Omniauth"
14
+ spec.homepage = "https://github.com/akowalz/omniauth-braintree-auth"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+
26
+ spec.add_dependency 'omniauth', '~> 1.0'
27
+ spec.add_dependency 'faraday_middleware', '~> 0.10.0'
28
+ spec.add_dependency 'omniauth-oauth2', '~> 1.3'
29
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-braintree-auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Kowalczuk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: omniauth
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: omniauth-oauth2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ description: OmniAuth Strategy for Braintree Auth, allows easy integration with the
98
+ Braintree Auth API through Omniauth
99
+ email:
100
+ - askowalczuk93@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/omniauth-braintree-auth.rb
115
+ - lib/omniauth-braintree-auth/version.rb
116
+ - lib/omniauth/braintree_auth.rb
117
+ - lib/omniauth/strategies/braintree_auth.rb
118
+ - omniauth-braintree-auth.gemspec
119
+ homepage: https://github.com/akowalz/omniauth-braintree-auth
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.8
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: OmniAuth Strategy for Braintree Auth
143
+ test_files: []
144
+ has_rdoc: