omniauth-sageone 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -0
- data/Gemfile +2 -1
- data/Guardfile +5 -6
- data/README.md +21 -1
- data/Rakefile +3 -6
- data/lib/omniauth-sageone/version.rb +1 -1
- data/lib/omniauth/strategies/sage_one.rb +51 -9
- data/omniauth-sageone.gemspec +10 -9
- data/spec/spec_helper.rb +3 -3
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da92bc2f9d2afee3f98d52341b7cf51d044cd1da
|
4
|
+
data.tar.gz: 6485af5bd93e8e05f7a35681a6344b5fb6d7ca8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 485bfa8fbe9a70f414edf9de5479373f0a94b2030062961e68cd44123049b2335448260439753df0a54cc55d8e94f31d075cdc6be37409b05c5076ba480c1265
|
7
|
+
data.tar.gz: 6fb854d669c7962f2a4a34b9a75aab7eca1c78761ff354befb267c14a4d68ddc1560dcc96fa990bfbc50391ae3daed6d271d36f2164f3f4ee479add423a30f1b
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
guard 'rspec', version: 2 do
|
2
|
-
watch(%r{^spec/.+_spec\.rb$})
|
3
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
4
|
-
watch('spec/spec_helper.rb') { "spec" }
|
5
|
-
end
|
6
|
-
|
7
1
|
guard 'bundler' do
|
8
2
|
watch('Gemfile')
|
9
3
|
watch('omniauth-sageone.gemspec')
|
10
4
|
end
|
5
|
+
|
6
|
+
guard :rubocop do
|
7
|
+
watch(%r{.+\.rb$})
|
8
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
9
|
+
end
|
data/README.md
CHANGED
@@ -8,4 +8,24 @@ This is an unofficial OmniAuth strategy for authenticating to SageOne. To use it
|
|
8
8
|
provider :sageone, ENV['SAGE_CLIENT_ID'], ENV['SAGE_CLIENT_SECRET'], scope: 'full_access'
|
9
9
|
end
|
10
10
|
|
11
|
-
Options for `scope` are either `readonly` or `full_access`.
|
11
|
+
# Options for `scope` are either `readonly` or `full_access`.
|
12
|
+
|
13
|
+
## Auth Hash
|
14
|
+
|
15
|
+
The hash in `env['omniauth.auth']` will have the following information:
|
16
|
+
|
17
|
+
- in `credentials`:
|
18
|
+
- `token`: The access token.
|
19
|
+
- `refresh_token`: The refresh token. Use this to get a new token when the one in `token` has been expired.
|
20
|
+
- `expires_at`: Timestamp that indicates when `token` will expire.
|
21
|
+
- `expires`: `true`
|
22
|
+
- `resource_owner_id`: An ID returned by Sage One when fetching the access token. You'll need that value for API v3
|
23
|
+
for request signing and the `X-SITE` header that is required on API requests.
|
24
|
+
- in `info`:
|
25
|
+
- `country`: The user's country. Use that information to get the correct base URL (Sage One has different ones for
|
26
|
+
different countries).
|
27
|
+
- in `uid`: The `requested_by_id` returned by Sage One when fetching the token.
|
28
|
+
|
29
|
+
## See Also
|
30
|
+
|
31
|
+
https://developer.sageone.com has the Sage One API documentation.
|
data/Rakefile
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
|
5
5
|
desc 'Default: run specs.'
|
6
|
-
task :
|
7
|
-
|
8
|
-
desc "Run specs"
|
9
|
-
RSpec::Core::RakeTask.new
|
6
|
+
task default: :spec
|
10
7
|
|
11
8
|
desc 'Run specs'
|
12
|
-
|
9
|
+
RSpec::Core::RakeTask.new
|
@@ -3,29 +3,71 @@ require 'omniauth-oauth2'
|
|
3
3
|
module OmniAuth
|
4
4
|
module Strategies
|
5
5
|
class SageOne < OmniAuth::Strategies::OAuth2
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
TOKEN_URLS = {
|
7
|
+
'ca' => 'https://mysageone.ca.sageone.com/oauth2/token',
|
8
|
+
'de' => 'https://oauth.eu.sageone.com/token',
|
9
|
+
'es' => 'https://oauth.eu.sageone.com/token',
|
10
|
+
'fr' => 'https://oauth.eu.sageone.com/token',
|
11
|
+
'gb' => 'https://app.sageone.com/oauth2/token',
|
12
|
+
'ie' => 'https://app.sageone.com/oauth2/token',
|
13
|
+
'us' => 'https://mysageone.na.sageone.com/oauth2/token'
|
14
|
+
}.freeze
|
10
15
|
|
11
|
-
option :
|
12
|
-
|
13
|
-
|
16
|
+
option :client_options,
|
17
|
+
authorize_url: 'https://www.sageone.com/oauth2/auth/central'
|
18
|
+
|
19
|
+
option :authorize_params,
|
20
|
+
response_type: 'code'
|
21
|
+
|
22
|
+
uid do
|
23
|
+
access_token['requested_by_id']
|
24
|
+
end
|
25
|
+
|
26
|
+
credentials do
|
27
|
+
{
|
28
|
+
resource_owner_id: access_token['resource_owner_id']
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
info do
|
33
|
+
{
|
34
|
+
country: country
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
# SageOne has different token endpoints for each available country. The country is returned in
|
39
|
+
# the authorization callback. Configure the OAuth client to use that information.
|
40
|
+
def client
|
41
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, client_options)
|
42
|
+
end
|
14
43
|
|
15
44
|
protected
|
16
45
|
|
17
46
|
# Override this method to remove the query string from the callback_url because SageOne
|
18
47
|
# requires an exact match
|
19
48
|
def build_access_token
|
20
|
-
verifier = request.params['code']
|
21
49
|
client.auth_code.get_token(
|
22
|
-
|
50
|
+
request.params['code'],
|
23
51
|
{
|
24
52
|
redirect_uri: callback_url.split('?').first
|
25
53
|
}.merge(token_params.to_hash(symbolize_keys: true)),
|
26
54
|
deep_symbolize(options.auth_token_params)
|
27
55
|
)
|
28
56
|
end
|
57
|
+
|
58
|
+
def country
|
59
|
+
request[:country].try(:downcase)
|
60
|
+
end
|
61
|
+
|
62
|
+
def client_options
|
63
|
+
hash = if country
|
64
|
+
{ token_url: TOKEN_URLS[country] }.merge(options.client_options)
|
65
|
+
else
|
66
|
+
options.client_options
|
67
|
+
end
|
68
|
+
|
69
|
+
deep_symbolize(hash)
|
70
|
+
end
|
29
71
|
end
|
30
72
|
end
|
31
73
|
end
|
data/omniauth-sageone.gemspec
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
require File.expand_path('../lib/omniauth-sageone/version', __FILE__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
7
|
-
gem.description =
|
8
|
-
gem.summary =
|
9
|
-
gem.homepage =
|
10
|
-
gem.licenses =
|
6
|
+
gem.authors = ['Jared Moody']
|
7
|
+
gem.email = ['jared@jetbuilt.com']
|
8
|
+
gem.description = 'OmniAuth strategy for SageOne.'
|
9
|
+
gem.summary = 'OmniAuth strategy for SageOne.'
|
10
|
+
gem.homepage = 'https://github.com/jetbuilt/omniauth-sageone'
|
11
|
+
gem.licenses = 'MIT'
|
11
12
|
|
12
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
13
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
13
14
|
gem.files = `git ls-files`.split("\n")
|
14
15
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
-
gem.name =
|
16
|
-
gem.require_paths = [
|
16
|
+
gem.name = 'omniauth-sageone'
|
17
|
+
gem.require_paths = ['lib']
|
17
18
|
gem.version = OmniAuth::SageOne::VERSION
|
18
19
|
|
19
20
|
gem.add_dependency 'omniauth', '~> 1.0'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
3
|
require 'simplecov'
|
4
4
|
SimpleCov.start
|
5
5
|
require 'rspec'
|
@@ -11,5 +11,5 @@ require 'omniauth-sageone'
|
|
11
11
|
RSpec.configure do |config|
|
12
12
|
config.include WebMock::API
|
13
13
|
config.include Rack::Test::Methods
|
14
|
-
config.extend OmniAuth::Test::StrategyMacros, :
|
14
|
+
config.extend OmniAuth::Test::StrategyMacros, type: :strategy
|
15
15
|
end
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-sageone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Moody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: omniauth-oauth2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.7'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-test
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: webmock
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: OmniAuth strategy for SageOne.
|
@@ -101,8 +101,9 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- .gitignore
|
105
|
-
- .rspec
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
106
107
|
- Gemfile
|
107
108
|
- Guardfile
|
108
109
|
- LICENSE
|
@@ -124,17 +125,17 @@ require_paths:
|
|
124
125
|
- lib
|
125
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
126
127
|
requirements:
|
127
|
-
- -
|
128
|
+
- - ">="
|
128
129
|
- !ruby/object:Gem::Version
|
129
130
|
version: '0'
|
130
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
132
|
requirements:
|
132
|
-
- -
|
133
|
+
- - ">="
|
133
134
|
- !ruby/object:Gem::Version
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.4.5.2
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: OmniAuth strategy for SageOne.
|