omniauth-octobat 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: ca7bf1054407693fbe9bd9b7a82f01deada5fb76
4
+ data.tar.gz: 63ac68c261785bc37bce920e3bb4ebd4d042d230
5
+ SHA512:
6
+ metadata.gz: 143a16de568af02f692935a230c10e8bd2c9ec5c4794cef4e061f7f1a291ae44597a1547c0f4e0266c1b92d6206b6a61e3b0c0c709698dff8a18d92f8c887ac9
7
+ data.tar.gz: 1506021aeec8451eb7896b6c3e8459be44e8bafab2a527292efd6a8bd35ff50ae4600a946fc6d0e31d9f489efa6f76e42ede4f01d37a5dff9e5fd21f80b7425e
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ *.rvmrc
4
+ .ruby-version
5
+ .ruby-gemset
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ example
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rake'
3
+
4
+ # Specify your gem's dependencies in omniauth-stripe-connect.gemspec
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'rspec', '>= 2.14'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2020 Octobat SAS
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,113 @@
1
+ # OmniAuth::Octobat
2
+
3
+ Octobat OAuth2 Strategy for OmniAuth 1.0.
4
+
5
+ Supports the OAuth 2.0 server-side and client-side flows.
6
+ Read the Octobat Plaza docs for more details: https://www.octobat.com/developers/plaza-quickstart
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'omniauth-octobat'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install omniauth-octobat
21
+
22
+ ## Usage
23
+
24
+ OmniAuth::Strategies::Octobat is simply a Rack middleware. Read the OmniAuth
25
+ 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
26
+
27
+ ### Non-Devise
28
+ Here's a quick example, adding the middleware to a Rails app in
29
+ `config/initializers/omniauth.rb`:
30
+
31
+ ```ruby
32
+ Rails.application.config.middleware.use OmniAuth::Builder do
33
+ provider :octobat, ENV['OCTOBAT_APP_CLIENT_ID'], ENV['OCTOBAT_APP_SECRET']
34
+ end
35
+ ```
36
+
37
+ ### Devise
38
+
39
+ You need to declare the provider in your `config/initializers/devise.rb`:
40
+
41
+ ```ruby
42
+ config.omniauth :octobat, "OCTOBAT_APP_CLIENT_ID", "OCTOBAT_APP_SECRET"
43
+ ```
44
+
45
+ You'll also need to add some configuration to your devise model (e.g. User in `app/models/user.rb`) along with any other OmniAuth providers you might have:
46
+ ```ruby
47
+ :omniauthable, :omniauth_providers => [:octobat]
48
+ ```
49
+
50
+ ### General Usage
51
+
52
+ Your `OCTOBAT_APP_CLIENT_ID` is application-specific and your `OCTOBAT_APP_SECRET` is account-specific and may also be known as your Octobat application secret.
53
+
54
+ Edit your `routes.rb` file to have:
55
+ `devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }`
56
+
57
+ And create a file called `omniauth_callbacks_controller.rb` which should have this inside:
58
+ ```ruby
59
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
60
+
61
+ def octobat
62
+ # Delete the code inside of this method and write your own.
63
+ # The code below is to show you where to access the data.
64
+ raise request.env["omniauth.auth"].to_yaml
65
+ end
66
+ end
67
+ ```
68
+
69
+ Make sure to go to Octobat's Developers Settings > Applications and set your Redirect URL to:
70
+ `http://localhost:3003/users/auth/octobat/callback`
71
+
72
+ The Callback URL will be something similar:
73
+ `http://www.yourdomain.com/users/auth/octobat/callback`
74
+
75
+ Then you can hit `/auth/octobat`
76
+
77
+ If you hit `/auth/octobat` with any query params, they will be passed along to Octobat API. You can access these params from `request.env['omniauth.params']`. Read [Octobat's OAuth Reference](https://www.octobat.com/developers/plaza-quickstart) for more information.
78
+
79
+ ## Auth Hash
80
+
81
+ Here is an example of the Auth Hash you get back from calling `request.env['omniauth.auth']`:
82
+
83
+ ```ruby
84
+ {
85
+ "provider"=>"octobat",
86
+ "uid"=>"<OCTOBAT_ACCOUNT_ID>",
87
+ "info"=> {
88
+ "livemode"=>false
89
+ },
90
+ "credentials"=> {
91
+ "token"=>"<OCTOBAT_ACCESS_TOKEN>",
92
+ },
93
+ "extra"=> {
94
+ "raw_info"=> {
95
+ "token_type"=>"bearer",
96
+ "octobat_account_id"=>"<OCTOBAT_ACCOUNT_ID>",
97
+ "livemode"=>false
98
+ },
99
+ "extra_info"=> {
100
+ "country"=>"US",
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+
107
+ ## Contributing
108
+
109
+ 1. Fork it
110
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
111
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
112
+ 4. Push to the branch (`git push origin my-new-feature`)
113
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/octobat'
@@ -0,0 +1,61 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Octobat < OmniAuth::Strategies::OAuth2
6
+ option :name, :octobat
7
+
8
+ option :client_options, {
9
+ :site => 'https://auth.octobat.com',
10
+ :authorize_path => '/oauth/authorize',
11
+ :access_token_path => '/oauth/token'
12
+ }
13
+
14
+ def raw_info
15
+ @raw_info ||= deep_symbolize(access_token.params)
16
+ end
17
+
18
+ def extra_info
19
+ @extra_info ||= deep_symbolize(access_token.get('/oauth/account').parsed)
20
+ end
21
+
22
+ uid { raw_info[:octobat_account_id] }
23
+
24
+ info do
25
+ { livemode: raw_info[:livemode] }
26
+ end
27
+
28
+ extra do
29
+ {
30
+ raw_info: raw_info,
31
+ extra_info: extra_info
32
+ }
33
+ end
34
+
35
+
36
+ #option :authorize_options, [:scope, :landing, :always_prompt]
37
+ #option :provider_ignores_state, true
38
+
39
+
40
+ # info do
41
+ # {
42
+ # :name => extra_info[:display_name] || extra_info[:business_name] || extra_info[:email],
43
+ # :email => extra_info[:email],
44
+ # :nickname => extra_info[:display_name],
45
+ # :scope => raw_info[:scope],
46
+ # :livemode => raw_info[:livemode],
47
+ # :stripe_publishable_key => raw_info[:stripe_publishable_key]
48
+ # }
49
+ # end
50
+ #
51
+ # extra do
52
+ # e = {
53
+ # :raw_info => raw_info
54
+ # }
55
+ # e[:extra_info] = extra_info unless skip_info?
56
+ #
57
+ # e
58
+ # end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Octobat
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-octobat/version"
2
+ require 'omniauth/octobat'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-octobat/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Gaultier Laperche"]
6
+ gem.email = ["gaultier@octobat.com"]
7
+ gem.description = %q{Octobat OAuth2 Strategy for OmniAuth 1.0.}
8
+ gem.summary = %q{
9
+ Supports the OAuth 2.0 server-side and client-side flows.
10
+ Read the Octobat Plaza docs for more details: https://www.octobat.com/developers/plaza-quickstart
11
+ }
12
+ gem.homepage = "https://www.octobat.com/developers/plaza-quickstart"
13
+
14
+ gem.files = `git ls-files | grep -v example`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.name = "omniauth-octobat"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = OmniAuth::Octobat::VERSION
20
+ gem.license = "MIT"
21
+
22
+ gem.add_dependency 'omniauth', '~> 1.3'
23
+ gem.add_dependency 'omniauth-oauth2', '~> 1.4'
24
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Octobat do
4
+ let(:fresh_strategy) { Class.new(OmniAuth::Strategies::Octobat) }
5
+
6
+
7
+ before(:each) do
8
+ OmniAuth.config.test_mode = true
9
+ @old_host = OmniAuth.config.full_host
10
+ end
11
+
12
+ after(:each) do
13
+ OmniAuth.config.full_host = @old_host
14
+ OmniAuth.config.test_mode = false
15
+ end
16
+
17
+ describe '#authorize_params' do
18
+ subject { fresh_strategy }
19
+
20
+ it 'should include redirect_uri if full_host is set' do
21
+ OmniAuth.config.full_host = 'https://foo.com/'
22
+ instance = subject.new('abc', 'def')
23
+
24
+ instance.authorize_params[:redirect_uri].should =~ /\Ahttps:\/\/foo\.com/
25
+ end
26
+
27
+ it 'should include redirect_uri if callback_path is set' do
28
+ # TODO: It would be nice to grab this from the request URL
29
+ # instead of setting it on the config
30
+ OmniAuth.config.full_host = 'https://foo.com/'
31
+ instance = subject.new('abc', 'def', :callback_path => 'bar/baz')
32
+
33
+ instance.authorize_params[:redirect_uri].should == 'https://foo.com/bar/baz'
34
+ end
35
+
36
+ it 'should not include redirect_uri by default' do
37
+ instance = subject.new('abc', 'def')
38
+
39
+ expect(instance.authorize_params[:redirect_uri]).to be_nil
40
+ end
41
+ end
42
+
43
+ describe '#token_params' do
44
+ subject { fresh_strategy }
45
+
46
+ # NOTE: We call authorize_params first in each of these methods
47
+ # since the OAuth2 gem uses it to setup some state for testing
48
+
49
+ it 'should include redirect_uri if full_host is set' do
50
+ OmniAuth.config.full_host = 'https://foo.com/'
51
+ instance = subject.new('abc', 'def')
52
+
53
+ instance.authorize_params
54
+ instance.token_params[:redirect_uri].should =~ /\Ahttps:\/\/foo\.com/
55
+ end
56
+
57
+ it 'should include redirect_uri if callback_path is set' do
58
+ # TODO: It would be nice to grab this from the request URL
59
+ # instead of setting it on the config
60
+ OmniAuth.config.full_host = 'https://foo.com/'
61
+ instance = subject.new('abc', 'def', :callback_path => 'bar/baz')
62
+
63
+ instance.authorize_params
64
+ instance.token_params[:redirect_uri].should == 'https://foo.com/bar/baz'
65
+ end
66
+
67
+ it 'should not include redirect_uri by default' do
68
+ instance = subject.new('abc', 'def')
69
+
70
+ instance.authorize_params
71
+ expect(instance.token_params[:redirect_uri]).to be_nil
72
+ end
73
+ end
74
+
75
+ describe '#callback_url' do
76
+ subject { fresh_strategy }
77
+ OmniAuth.config.full_host = 'https://foo.com/'
78
+
79
+ it 'returns a url with the host and path' do
80
+ instance = subject.new('abc', 'def', :callback_path => 'bar/baz')
81
+ instance.authorize_params
82
+ expect(instance.callback_url).to eq 'https://foo.com/bar/baz'
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'omniauth-octobat'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-octobat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gaultier Laperche
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-15 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.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ description: Octobat OAuth2 Strategy for OmniAuth 1.0.
42
+ email:
43
+ - gaultier@octobat.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/omniauth-octobat.rb
54
+ - lib/omniauth-octobat/version.rb
55
+ - lib/omniauth/octobat.rb
56
+ - lib/omniauth/strategies/octobat.rb
57
+ - omniauth-octobat.gemspec
58
+ - spec/omniauth/strategies/octobat_spec.rb
59
+ - spec/spec_helper.rb
60
+ homepage: https://www.octobat.com/developers/plaza-quickstart
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.5.2.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: 'Supports the OAuth 2.0 server-side and client-side flows. Read the Octobat
84
+ Plaza docs for more details: https://www.octobat.com/developers/plaza-quickstart'
85
+ test_files:
86
+ - spec/omniauth/strategies/octobat_spec.rb
87
+ - spec/spec_helper.rb