omniauth-gohighlevel 0.1.0
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 +7 -0
- data/.standard.yml +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +10 -0
- data/lib/omniauth/gohighlevel/version.rb +7 -0
- data/lib/omniauth/gohighlevel.rb +97 -0
- data/omniauth-gohighlevel.gemspec +37 -0
- data/sig/omniauth/gohighlevel.rbs +6 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 00cb7b9008f98ec5ebb612a83d4d9dfac417aec37c8b3832b07820cc3f7925b6
|
4
|
+
data.tar.gz: a35c144c8d913c2ebea23a0a625ca185ffa39052095c6563dbf0d7c12da03938
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4519c2ba3a39f31e7bf97acb6bb20b1ea0fdb61edc443dd20d213c1c3f557863a1c05beff389393cf69d82d60af5a194aeafd37d5229194b59841634f757c094
|
7
|
+
data.tar.gz: 26c837359b748c87cab336900906a41747e0dae9581006550881334a5b745144166a239c53c99c457a235612082293834b3a9eb4a653440ea0a65c7111d6953b
|
data/.standard.yml
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Michael Koper
|
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,45 @@
|
|
1
|
+
# Omniauth::Gohighlevel
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/gohighlevel`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-gohighlevel'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-gohighlevel
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Here's a quick example, adding the middleware to a Rails app in config/initializers/omniauth.rb:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
27
|
+
provider :gohighlevel, ENV['GOHIGHLEVEL_CLIENT_ID'], ENV['GOHIGHLEVEL_CLIENT_SECRET'], {
|
28
|
+
scope: "contacts.write contacts.readonly invoices.readonly invoices.write products.readonly locations.readonly"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/michaelkoper/omniauth-gohighlevel.
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "gohighlevel/version"
|
4
|
+
require "omniauth-oauth2"
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
class Gohighlevel < OmniAuth::Strategies::OAuth2
|
9
|
+
option :name, "gohighlevel"
|
10
|
+
|
11
|
+
option :client_options, {
|
12
|
+
site: "https://marketplace.gohighlevel.com",
|
13
|
+
authorize_url: "https://marketplace.gohighlevel.com/oauth/chooselocation",
|
14
|
+
token_url: "https://services.leadconnectorhq.com/oauth/token"
|
15
|
+
}
|
16
|
+
|
17
|
+
option :authorize_params, {
|
18
|
+
response_type: "code",
|
19
|
+
user_type: "Location"
|
20
|
+
}
|
21
|
+
|
22
|
+
def build_access_token
|
23
|
+
verifier = request.params["code"]
|
24
|
+
@token = client.auth_code.get_token(
|
25
|
+
verifier,
|
26
|
+
{
|
27
|
+
redirect_uri: callback_url,
|
28
|
+
client_id: options.client_id,
|
29
|
+
client_secret: options.client_secret,
|
30
|
+
grant_type: "authorization_code",
|
31
|
+
user_type: "Location"
|
32
|
+
},
|
33
|
+
{headers: {"Accept" => "application/json"}}
|
34
|
+
)
|
35
|
+
@token
|
36
|
+
rescue ::OAuth2::Error => e
|
37
|
+
Rails.logger.error "OAuth2 Error: #{e.code} - #{e.description}"
|
38
|
+
Rails.logger.error "Response body: #{e.response.body}" if e.response
|
39
|
+
raise e
|
40
|
+
rescue => e
|
41
|
+
Rails.logger.error "Error during token exchange: #{e.class.name} - #{e.message}"
|
42
|
+
Rails.logger.error e.backtrace.join("\n")
|
43
|
+
raise e
|
44
|
+
end
|
45
|
+
|
46
|
+
def callback_phase
|
47
|
+
if request.params["error"] || request.params["error_reason"]
|
48
|
+
raise CallbackError.new(request.params["error"],
|
49
|
+
request.params["error_description"] || request.params["error_reason"], request.params["error_uri"])
|
50
|
+
elsif !request.params["code"]
|
51
|
+
fail!(:missing_code, OmniAuth::Error.new("Missing code parameter"))
|
52
|
+
else
|
53
|
+
options.token_params["redirect_uri"] = callback_url
|
54
|
+
super
|
55
|
+
end
|
56
|
+
rescue CallbackError => e
|
57
|
+
fail!(:invalid_credentials, e)
|
58
|
+
rescue ::OAuth2::Error, CallbackError => e
|
59
|
+
fail!(:invalid_credentials, e)
|
60
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
61
|
+
fail!(:timeout, e)
|
62
|
+
rescue ::SocketError => e
|
63
|
+
fail!(:failed_to_connect, e)
|
64
|
+
end
|
65
|
+
|
66
|
+
def authorize_params
|
67
|
+
super.tap do |params|
|
68
|
+
params[:scope] = request.params["scope"] if request.params["scope"]
|
69
|
+
params[:user_type] = "Location"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
uid { @token.params[:user_id] }
|
74
|
+
|
75
|
+
info do
|
76
|
+
{
|
77
|
+
user_id: raw_info["user_id"],
|
78
|
+
location_id: raw_info["location_id"]
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
extra do
|
83
|
+
{
|
84
|
+
"raw_info" => raw_info
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def raw_info
|
89
|
+
@raw_info ||= access_token.params.slice("company_id", "location_id", "user_id", "user_type")
|
90
|
+
end
|
91
|
+
|
92
|
+
def callback_url
|
93
|
+
full_host + script_name + callback_path
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/omniauth/gohighlevel/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'omniauth-gohighlevel'
|
7
|
+
spec.version = Omniauth::Gohighlevel::VERSION
|
8
|
+
spec.authors = ['Michael Koper']
|
9
|
+
spec.email = ['hello@michaelkoper.com']
|
10
|
+
|
11
|
+
spec.summary = 'Omniauth strategy for Gohighlevels'
|
12
|
+
spec.homepage = 'https://github.com/michaelkoper/omniauth-gohighlevels'
|
13
|
+
spec.description = spec.homepage
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.6.0'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'omniauth-oauth2', '~> 1.7.0'
|
33
|
+
spec.add_development_dependency 'standardrb'
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, check out our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-gohighlevel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Koper
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth-oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: standardrb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: https://github.com/michaelkoper/omniauth-gohighlevels
|
42
|
+
email:
|
43
|
+
- hello@michaelkoper.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".standard.yml"
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/omniauth/gohighlevel.rb
|
53
|
+
- lib/omniauth/gohighlevel/version.rb
|
54
|
+
- omniauth-gohighlevel.gemspec
|
55
|
+
- sig/omniauth/gohighlevel.rbs
|
56
|
+
homepage: https://github.com/michaelkoper/omniauth-gohighlevels
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
homepage_uri: https://github.com/michaelkoper/omniauth-gohighlevels
|
61
|
+
source_code_uri: https://github.com/michaelkoper/omniauth-gohighlevels
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.6.0
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubygems_version: 3.5.3
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Omniauth strategy for Gohighlevels
|
81
|
+
test_files: []
|