omniauth-zenpayroll 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +5 -0
- data/Gemfile +5 -0
- data/README.md +106 -0
- data/Rakefile +1 -0
- data/lib/omniauth-zenpayroll.rb +2 -0
- data/lib/omniauth-zenpayroll/version.rb +5 -0
- data/lib/omniauth/strategies/zenpayroll.rb +74 -0
- data/omniauth-zenpayroll.gemspec +26 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjBiMzBkYjAzMDgyZDAwN2EwNjBlNjlhZjNjZTNlMWRhMGE5NzA3NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODJkNTkyYjM2NTIzYWMzOTIwOGQ3YzJiNmQ3MTU5ZTNmZjdmOTAxMw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTAyYjFlZDEwZjZjMjJiY2ZlZTczMmQ0N2VhZGM2YTNhZjZhODhhNTRmMzI3
|
10
|
+
OWIzMzE0MjUzZWYyMGQ0M2FlY2RhNTgwYjRjOTlkM2EyMWRiNzZiZWQyMzdl
|
11
|
+
OTQxNjk4MDcwMTllOTg1NTk2Y2JhYWY3YTdiNzVhYzY4ZjFiYmY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2FlNGY1ZDZjNWI0M2EwZmI4ZDUzN2Q3ZjFhN2IxZTQ4ZjhmNDY5MzMyOGM5
|
14
|
+
MzI1MmRkOTE1ZjYwNTMxNjg2YjQxMGY0N2QwNjE0OTFkNDA3NWRhYzZmZGQ1
|
15
|
+
ZjhjMmE4MWFhYWJmYjc3ZjFiN2ZjOTU2NThmNjhiY2NkYTVjZDA=
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# OmniAuth ZenPayroll
|
2
|
+
|
3
|
+
This gem contains the ZenPayroll strategy for OmniAuth.
|
4
|
+
|
5
|
+
ZenPayroll implements a standard [OAuth 2.0](http://en.wikipedia.org/wiki/OAuth#OAuth_2.0) authentication process, issuing
|
6
|
+
a short term (~10 minute ttl) authentication token that is then used to retrieve a longer-term (~2 hour ttl) access token
|
7
|
+
and single-use refresh token.
|
8
|
+
|
9
|
+
For more detailed information see the [ZenPayroll Authentication Example](http://docs.zenpayroll.com/v1/examples/authentication/)
|
10
|
+
in the API docs.
|
11
|
+
|
12
|
+
## Before You Begin
|
13
|
+
|
14
|
+
You should have already installed OmniAuth in your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth)
|
15
|
+
to get started. Also, Ryan Bates has made a number of excellent [Railscasts](http://railscasts.com/episodes/235-devise-and-omniauth-revised)
|
16
|
+
on getting started with OmniAuth and Devise.
|
17
|
+
|
18
|
+
You'll need to create an application with ZenPayroll first. Take note of your Client ID, Client Secret and Redirect URI,
|
19
|
+
your application will use these to authenticate against the ZenPayroll API.
|
20
|
+
|
21
|
+
## Using This Strategy
|
22
|
+
|
23
|
+
Add the gem to your Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'omniauth-zenpayroll'
|
27
|
+
```
|
28
|
+
|
29
|
+
If you need to use the latest HEAD version, you can do so with:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'omniauth-zenpayroll', :github => 'shiftdock/omniauth-zenpayroll'
|
33
|
+
```
|
34
|
+
|
35
|
+
Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
39
|
+
provider :zenpayroll, "CLIENT_ID", "CLIENT_SECRET"
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Replace `CLIENT_ID` and `CLIENT_SECRET` with the appropriate values you obtained from ZenPayroll earlier.
|
44
|
+
|
45
|
+
If you need to override the Redirect URI (i.e. if yours deviates from the default) you can do so by setting it as the
|
46
|
+
`callback_url` in an `authorize_params` options hash.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Rails.application.config.middleware.user OmniAuth:Builder do
|
50
|
+
provider :zenpayroll, "CLIENT_ID", "CLIENT_SECRET", :authorize_params => {:callback_url => '/my/app/callback/url'}
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
#### UID Gotcha
|
55
|
+
|
56
|
+
As the ZenPayroll API doesn't expose a unique ID for the user being authenticated we have to use their email address
|
57
|
+
instead. ZenPayroll ensure that it will be unique. To remain consistent with other OmniAuth strategies the email address
|
58
|
+
is returned as both the `uid` and as `email` in the `info` hash.
|
59
|
+
|
60
|
+
## Authentication Hash
|
61
|
+
|
62
|
+
An example auth hash available in `request.env['omniauth.auth']`:
|
63
|
+
```ruby
|
64
|
+
{
|
65
|
+
:provider => "zenpayroll",
|
66
|
+
:uid => "auth_user@zenpayroll.x",
|
67
|
+
:info => {
|
68
|
+
:email => "auth_user@zenpayroll.x"
|
69
|
+
},
|
70
|
+
:credentials => {
|
71
|
+
:token => "a1b2c3d4...", # The OAuth 2.0 access token
|
72
|
+
:refresh_token => "abcdef1234",
|
73
|
+
:expires => true,
|
74
|
+
:expires_at => 456102000
|
75
|
+
},
|
76
|
+
:extra => {
|
77
|
+
:email => "auth_user@zenpayroll.x",
|
78
|
+
:permissions => {
|
79
|
+
:payroll_admin => {
|
80
|
+
:company_ids => [123456789]
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
```
|
86
|
+
|
87
|
+
## Tests
|
88
|
+
|
89
|
+
Although the strategy is currently in production use at [ShiftDock](https://shiftdock.com), the version is <1.0.0 until the project
|
90
|
+
includes robust tests.
|
91
|
+
|
92
|
+
## Credits
|
93
|
+
|
94
|
+
Built with example from the awesome [omniauth-twitter](https://github.com/arunagw/omniauth-twitter) gem by Arun Agrawal and
|
95
|
+
[omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook) gem by Mark Dodwell.
|
96
|
+
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
Copyright (c) 2013 by John M. Hope
|
101
|
+
|
102
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
103
|
+
|
104
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
105
|
+
|
106
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class ZenPayroll < OmniAuth::Strategies::OAuth2
|
7
|
+
|
8
|
+
option :name, 'zenpayroll'
|
9
|
+
<<<<<<< HEAD
|
10
|
+
option :client_options, { authorize_url: '/oauth/authorize',
|
11
|
+
token_url: '/oauth/token',
|
12
|
+
site: 'https://zenpayroll.com/' }
|
13
|
+
|
14
|
+
option :token_params, {
|
15
|
+
parse: :json,
|
16
|
+
grant_type: 'authorization_code'
|
17
|
+
}
|
18
|
+
=======
|
19
|
+
option :client_options, {:authorize_path => '/oauth/authorize',
|
20
|
+
:site => 'https://zenpayroll-demo.com'}
|
21
|
+
>>>>>>> df6131f... First stage authentication routing works
|
22
|
+
|
23
|
+
option :auth_token_params, {
|
24
|
+
param_name: 'access_token',
|
25
|
+
mode: :query
|
26
|
+
}
|
27
|
+
|
28
|
+
uid { raw_info['email'] }
|
29
|
+
|
30
|
+
info do
|
31
|
+
{
|
32
|
+
'email' => raw_info['email']
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
extra do
|
37
|
+
{ :raw_info => raw_info }
|
38
|
+
end
|
39
|
+
|
40
|
+
# ZenPayroll are strict on redirect_uri.
|
41
|
+
# Pass 'origin=...' as parameter to provider url to pass through.
|
42
|
+
def callback_url
|
43
|
+
options.authorize_params.callback_url or super
|
44
|
+
end
|
45
|
+
|
46
|
+
def request_phase
|
47
|
+
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(options.authorize_params))
|
48
|
+
end
|
49
|
+
|
50
|
+
def callback_url
|
51
|
+
options.authorize_params.callback_url or super
|
52
|
+
end
|
53
|
+
|
54
|
+
def raw_info
|
55
|
+
@raw_info ||= access_token.get('/api/v1/me.json').parsed
|
56
|
+
rescue ::Errno::ETIMEDOUT
|
57
|
+
raise ::Timeout::Error
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_access_token
|
61
|
+
token_params = options.token_params.merge({
|
62
|
+
code: request.params['code'],
|
63
|
+
redirect_uri: callback_url,
|
64
|
+
client_id: client.id,
|
65
|
+
client_secret: client.secret
|
66
|
+
})
|
67
|
+
|
68
|
+
client.get_token(token_params, deep_symbolize(options.auth_token_params))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
OmniAuth.config.add_camelization 'zenpayroll', 'ZenPayroll'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-zenpayroll/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-zenpayroll"
|
7
|
+
s.version = OmniAuth::ZenPayroll::VERSION
|
8
|
+
s.authors = ["John M. Hope"]
|
9
|
+
s.email = ["john@shiftdock.com"]
|
10
|
+
s.homepage = "https://github.com/shiftdock/omniauth-zenpayroll"
|
11
|
+
s.summary = %q{OmniAuth strategy for ZenPayroll}
|
12
|
+
s.description = %q{OmniAuth strategy for ZenPayroll}
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.rubyforge_project = "omniauth-zenpayroll"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'multi_json', '~> 1.3'
|
22
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1.1'
|
23
|
+
s.add_development_dependency 'rack-test'
|
24
|
+
s.add_development_dependency 'simplecov'
|
25
|
+
s.add_development_dependency 'webmock'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-zenpayroll
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John M. Hope
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
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.1.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: OmniAuth strategy for ZenPayroll
|
84
|
+
email:
|
85
|
+
- john@shiftdock.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/omniauth-zenpayroll.rb
|
95
|
+
- lib/omniauth-zenpayroll/version.rb
|
96
|
+
- lib/omniauth/strategies/zenpayroll.rb
|
97
|
+
- omniauth-zenpayroll.gemspec
|
98
|
+
homepage: https://github.com/shiftdock/omniauth-zenpayroll
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project: omniauth-zenpayroll
|
118
|
+
rubygems_version: 2.1.5
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: OmniAuth strategy for ZenPayroll
|
122
|
+
test_files: []
|