omniauth-lightspeed-oauth2 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e0388af4fb289084daa95123f01a0c532dae82fbec4179c57fb04094844eb56
4
+ data.tar.gz: bcdf3b11953c6ed45b896930156f30985efe4a1f21cb80da044ea70ee7d032e9
5
+ SHA512:
6
+ metadata.gz: d8385048e53c543e1655765ee70b1915777f001871427450e5a3b97ceb0a6f508053738f12fe69033b29531acd477e9af9c76ec02557770c5429a8f5011613bf
7
+ data.tar.gz: 333e5a0a219d3c96b1cd53aa7c4f83210411fed0723204ca580449e54309c6cec88760ffa731561f3ec232d2788646d9def40b433cd0527571b1d606971c1db1
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0] - 2026-03-16
6
+
7
+ ### Added
8
+
9
+ - Initial release
10
+ - OmniAuth OAuth2 strategy for Lightspeed Restaurant (K-Series)
11
+ - Support for trial and production environments
12
+ - Business info fetching (business name, currency, location, timezone)
13
+ - Token exchange with redirect_uri query param stripping
14
+ - 100% line and branch test coverage
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dan1d
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # OmniAuth Lightspeed OAuth2
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/omniauth-lightspeed-oauth2.svg)](https://badge.fury.io/rb/omniauth-lightspeed-oauth2)
4
+ [![CI](https://github.com/dan1d/omniauth-lightspeed-oauth2/actions/workflows/ci.yml/badge.svg)](https://github.com/dan1d/omniauth-lightspeed-oauth2/actions/workflows/ci.yml)
5
+ [![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://github.com/dan1d/omniauth-lightspeed-oauth2)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ OmniAuth strategy for [Lightspeed Restaurant (K-Series)](https://www.lightspeedhq.com/pos/restaurant/) OAuth2 authentication.
9
+
10
+ Lightspeed K-Series uses OpenID Connect (Keycloak) with standard OAuth2 Authorization Code Grant. This gem handles the full OAuth2 flow, token exchange, and fetches business information from the Lightspeed K-Series API.
11
+
12
+ ## Installation
13
+
14
+ Add to your Gemfile:
15
+
16
+ ```ruby
17
+ gem 'omniauth-lightspeed-oauth2'
18
+ ```
19
+
20
+ Then run:
21
+
22
+ ```bash
23
+ bundle install
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### Rails with Devise
29
+
30
+ ```ruby
31
+ # config/initializers/devise.rb
32
+ config.omniauth :lightspeed_oauth2,
33
+ ENV['LIGHTSPEED_CLIENT_ID'],
34
+ ENV['LIGHTSPEED_CLIENT_SECRET'],
35
+ environment: Rails.env.production? ? :production : :trial
36
+ ```
37
+
38
+ ### Standalone OmniAuth
39
+
40
+ ```ruby
41
+ # config.ru or initializer
42
+ use OmniAuth::Builder do
43
+ provider :lightspeed_oauth2,
44
+ ENV['LIGHTSPEED_CLIENT_ID'],
45
+ ENV['LIGHTSPEED_CLIENT_SECRET'],
46
+ environment: :trial
47
+ end
48
+ ```
49
+
50
+ ### Environments
51
+
52
+ | Environment | Auth Server | API Server |
53
+ |-------------|-------------|------------|
54
+ | `:trial` (default) | `auth.lsk-demo.app` | `api.trial.lsk.lightspeed.app` |
55
+ | `:production` | `auth.lsk-prod.app` | `api.lsk.lightspeed.app` |
56
+
57
+ ## Auth Hash
58
+
59
+ After successful authentication, the auth hash contains:
60
+
61
+ ```ruby
62
+ {
63
+ provider: 'lightspeed_oauth2',
64
+ uid: '12345', # Lightspeed business ID
65
+ info: {
66
+ business_name: 'My Restaurant',
67
+ currency_code: 'USD',
68
+ location_id: 67890,
69
+ location_name: 'Main Location',
70
+ country: 'US',
71
+ timezone: 'America/New_York'
72
+ },
73
+ credentials: {
74
+ token: 'access_token_value',
75
+ refresh_token: 'refresh_token_value',
76
+ expires_at: 1234567890,
77
+ expires: true
78
+ },
79
+ extra: {
80
+ raw_info: {
81
+ 'business_id' => 12345,
82
+ 'business_name' => 'My Restaurant',
83
+ 'currency_code' => 'USD',
84
+ 'location_id' => 67890,
85
+ 'location_name' => 'Main Location',
86
+ 'country' => 'US',
87
+ 'timezone' => 'America/New_York'
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ ## Configuration Options
94
+
95
+ | Option | Default | Description |
96
+ |--------|---------|-------------|
97
+ | `environment` | `:trial` | API environment (`:trial` or `:production`) |
98
+ | `scope` | `openid` | OAuth2 scopes to request |
99
+
100
+ ## Callback URL
101
+
102
+ Register your callback URL in the [Lightspeed Developer Portal](https://developers.lightspeedhq.com/):
103
+
104
+ ```
105
+ https://yourdomain.com/auth/lightspeed_oauth2/callback
106
+ ```
107
+
108
+ For development with ngrok:
109
+
110
+ ```
111
+ https://yourapp.ngrok.dev/auth/lightspeed_oauth2/callback
112
+ ```
113
+
114
+ **Note:** Lightspeed requires the `redirect_uri` to match exactly. This gem automatically strips query parameters from the callback URL during token exchange to ensure matching.
115
+
116
+ ## Token Refresh
117
+
118
+ Access tokens expire. Use the refresh token to obtain new pairs:
119
+
120
+ ```ruby
121
+ client = OAuth2::Client.new(
122
+ ENV['LIGHTSPEED_CLIENT_ID'],
123
+ ENV['LIGHTSPEED_CLIENT_SECRET'],
124
+ site: 'https://api.trial.lsk.lightspeed.app',
125
+ token_url: 'https://auth.lsk-demo.app/realms/k-series/protocol/openid-connect/token'
126
+ )
127
+
128
+ token = OAuth2::AccessToken.from_hash(client, {
129
+ access_token: stored_access_token,
130
+ refresh_token: stored_refresh_token
131
+ })
132
+
133
+ new_token = token.refresh!
134
+ # Store new_token.token and new_token.refresh_token
135
+ ```
136
+
137
+ ## Development
138
+
139
+ ```bash
140
+ git clone https://github.com/dan1d/omniauth-lightspeed-oauth2.git
141
+ cd omniauth-lightspeed-oauth2
142
+ bundle install
143
+
144
+ # Run tests (100% line + branch coverage enforced)
145
+ bundle exec rspec
146
+
147
+ # Run linter
148
+ bundle exec rubocop
149
+
150
+ # Run both
151
+ bundle exec rake
152
+ ```
153
+
154
+ ## Testing
155
+
156
+ 20 examples with 100% line and branch coverage enforced via SimpleCov. The test suite uses WebMock to stub all HTTP requests.
157
+
158
+ ## Contributing
159
+
160
+ 1. Fork it
161
+ 2. Create your feature branch (`git checkout -b feature/my-feature`)
162
+ 3. Write tests first (TDD)
163
+ 4. Ensure 100% coverage: `bundle exec rspec`
164
+ 5. Ensure no RuboCop offenses: `bundle exec rubocop`
165
+ 6. Commit your changes
166
+ 7. Push to the branch
167
+ 8. Create a Pull Request
168
+
169
+ ## License
170
+
171
+ MIT License. See [LICENSE.txt](LICENSE.txt) for details.
172
+
173
+ ## Links
174
+
175
+ - [Lightspeed K-Series API Docs](https://api-docs.lsk.lightspeed.app/)
176
+ - [Lightspeed Developer Portal](https://developers.lightspeedhq.com/)
177
+ - [OmniAuth](https://github.com/omniauth/omniauth)
178
+ - [OmniAuth OAuth2](https://github.com/omniauth/omniauth-oauth2)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module LightspeedOauth2
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+ require 'faraday'
5
+ require 'json'
6
+
7
+ module OmniAuth
8
+ module Strategies
9
+ # OmniAuth strategy for Lightspeed Restaurant (K-Series) OAuth2.
10
+ #
11
+ # Lightspeed uses OpenID Connect (Keycloak) with standard OAuth2 Authorization Code Grant.
12
+ # Access tokens expire; use refresh tokens to obtain new pairs.
13
+ #
14
+ # Demo/Trial: auth.lsk-demo.app, api.trial.lsk.lightspeed.app
15
+ # Production: auth.lsk-prod.app, api.lsk.lightspeed.app
16
+ #
17
+ # @example Basic usage
18
+ # provider :lightspeed_oauth2, ENV['LIGHTSPEED_CLIENT_ID'], ENV['LIGHTSPEED_CLIENT_SECRET']
19
+ #
20
+ # @example With custom environment
21
+ # provider :lightspeed_oauth2, ENV['LIGHTSPEED_CLIENT_ID'], ENV['LIGHTSPEED_CLIENT_SECRET'],
22
+ # environment: :production
23
+ #
24
+ class LightspeedOauth2 < OmniAuth::Strategies::OAuth2
25
+ option :name, 'lightspeed_oauth2'
26
+
27
+ option :environment, :trial
28
+
29
+ option :client_options, {
30
+ site: 'https://api.trial.lsk.lightspeed.app',
31
+ authorize_url: 'https://auth.lsk-demo.app/realms/k-series/protocol/openid-connect/auth',
32
+ token_url: 'https://auth.lsk-demo.app/realms/k-series/protocol/openid-connect/token',
33
+ auth_scheme: :basic_auth
34
+ }
35
+
36
+ option :authorize_params, {
37
+ scope: 'openid'
38
+ }
39
+
40
+ ENVIRONMENTS = {
41
+ trial: {
42
+ site: 'https://api.trial.lsk.lightspeed.app',
43
+ authorize_url: 'https://auth.lsk-demo.app/realms/k-series/protocol/openid-connect/auth',
44
+ token_url: 'https://auth.lsk-demo.app/realms/k-series/protocol/openid-connect/token'
45
+ },
46
+ production: {
47
+ site: 'https://api.lsk.lightspeed.app',
48
+ authorize_url: 'https://auth.lsk-prod.app/realms/k-series/protocol/openid-connect/auth',
49
+ token_url: 'https://auth.lsk-prod.app/realms/k-series/protocol/openid-connect/token'
50
+ }
51
+ }.freeze
52
+
53
+ def setup_phase
54
+ env = options[:environment]&.to_sym || :trial
55
+ urls = ENVIRONMENTS.fetch(env, ENVIRONMENTS[:trial])
56
+ options.client_options.merge!(urls)
57
+ super
58
+ end
59
+
60
+ # UID is the Lightspeed business ID
61
+ uid { raw_info['business_id']&.to_s }
62
+
63
+ info do
64
+ {
65
+ business_name: raw_info['business_name'],
66
+ currency_code: raw_info['currency_code'],
67
+ location_id: raw_info['location_id'],
68
+ location_name: raw_info['location_name'],
69
+ country: raw_info['country'],
70
+ timezone: raw_info['timezone']
71
+ }
72
+ end
73
+
74
+ extra do
75
+ { raw_info: raw_info }
76
+ end
77
+
78
+ def raw_info
79
+ @raw_info ||= fetch_business_info
80
+ end
81
+
82
+ # Override to strip query params from callback_url for redirect_uri matching.
83
+ def build_access_token
84
+ redirect_uri = callback_url.sub(/\?.*/, '')
85
+ log(:info, "Token exchange — site: #{client.site}, redirect_uri: #{redirect_uri}")
86
+ verifier = request.params['code']
87
+ client.auth_code.get_token(
88
+ verifier,
89
+ { redirect_uri: redirect_uri }.merge(token_params.to_hash(symbolize_keys: true)),
90
+ deep_symbolize(options.auth_token_params)
91
+ )
92
+ rescue ::OAuth2::Error => e
93
+ log(:error, "Token exchange FAILED: status=#{e.response&.status} body=#{e.response&.body}")
94
+ raise
95
+ end
96
+
97
+ private
98
+
99
+ def fetch_business_info
100
+ response = access_token.get('/f/data/businesses?page=0&size=10')
101
+ data = JSON.parse(response.body)
102
+
103
+ businesses = data.dig('_embedded', 'businessList') || []
104
+ business = businesses.first || {}
105
+ location = (business['businessLocations'] || []).first || {}
106
+
107
+ {
108
+ 'business_id' => business['businessId'],
109
+ 'business_name' => business['businessName'],
110
+ 'currency_code' => business['currencyCode'],
111
+ 'location_id' => location['blID'],
112
+ 'location_name' => location['blName'],
113
+ 'country' => location['country'],
114
+ 'timezone' => location['timezone']
115
+ }
116
+ rescue StandardError => e
117
+ log(:warn, "Failed to fetch business info: #{e.message}")
118
+ { 'business_id' => nil }
119
+ end
120
+
121
+ def log(level, message)
122
+ return unless defined?(OmniAuth.logger) && OmniAuth.logger
123
+
124
+ OmniAuth.logger.send(level, "[LightspeedOauth2] #{message}")
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+ require 'omniauth/lightspeed_oauth2/version'
5
+ require 'omniauth/strategies/lightspeed_oauth2'
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-lightspeed-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dan1d
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '1.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: omniauth-oauth2
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.8'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.8'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ - !ruby/object:Gem::Dependency
61
+ name: rack-test
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.1'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '2.1'
74
+ - !ruby/object:Gem::Dependency
75
+ name: rake
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '13.0'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '13.0'
88
+ - !ruby/object:Gem::Dependency
89
+ name: rspec
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.12'
95
+ type: :development
96
+ prerelease: false
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.12'
102
+ - !ruby/object:Gem::Dependency
103
+ name: rubocop
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.75'
109
+ type: :development
110
+ prerelease: false
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.75'
116
+ - !ruby/object:Gem::Dependency
117
+ name: rubocop-rspec
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.5'
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '3.5'
130
+ - !ruby/object:Gem::Dependency
131
+ name: simplecov
132
+ requirement: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0.22'
137
+ type: :development
138
+ prerelease: false
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '0.22'
144
+ - !ruby/object:Gem::Dependency
145
+ name: webmock
146
+ requirement: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '3.18'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '3.18'
158
+ description: An OmniAuth strategy for authenticating with Lightspeed Restaurant (K-Series)
159
+ using OAuth 2.0. Supports trial and production environments.
160
+ email:
161
+ - dan1d@users.noreply.github.com
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - CHANGELOG.md
167
+ - LICENSE.txt
168
+ - README.md
169
+ - lib/omniauth-lightspeed-oauth2.rb
170
+ - lib/omniauth/lightspeed_oauth2/version.rb
171
+ - lib/omniauth/strategies/lightspeed_oauth2.rb
172
+ homepage: https://github.com/dan1d/omniauth-lightspeed-oauth2
173
+ licenses:
174
+ - MIT
175
+ metadata:
176
+ homepage_uri: https://github.com/dan1d/omniauth-lightspeed-oauth2
177
+ source_code_uri: https://github.com/dan1d/omniauth-lightspeed-oauth2
178
+ changelog_uri: https://github.com/dan1d/omniauth-lightspeed-oauth2/blob/main/CHANGELOG.md
179
+ rubygems_mfa_required: 'true'
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 3.0.0
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubygems_version: 3.6.9
195
+ specification_version: 4
196
+ summary: OmniAuth OAuth2 strategy for Lightspeed Restaurant (K-Series)
197
+ test_files: []