omniauth-bsmart 1.0.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/LICENSE.txt +21 -0
- data/README.md +135 -0
- data/lib/omniauth/bsmart/version.rb +7 -0
- data/lib/omniauth/bsmart.rb +4 -0
- data/lib/omniauth/strategies/bsmart.rb +105 -0
- data/lib/omniauth-bsmart.rb +3 -0
- data/omniauth-bsmart.gemspec +34 -0
- metadata +86 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2e6f043f979942458da100c9045bc5926d433e6a922a47970ff495422eefb16a
|
|
4
|
+
data.tar.gz: d5e9489558f6ae69f4c7c0044a9293dfac744fae0e27e07e622c2c2b3bde6c5e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c6a315131625ecf0099331b5611f0671dd6de8c11dd00d8941628b6f384f8e29bafbdeecc243a095fa92d051ffc821e947b8151bddd8f7c023cf24d81b5304b6
|
|
7
|
+
data.tar.gz: 76f8041dbb8d0c28f07931218268ff30dcced94e3b0ca5676023dfd05ab0efba39fcbbfe09fd072c5728bca4b9c03b30b9a029e5cfbdab39d8a8091024e8a81b
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bsmartlabs
|
|
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,135 @@
|
|
|
1
|
+
# omniauth-bsmart
|
|
2
|
+
|
|
3
|
+
[](https://github.com/bsmartlabs/omniauth-bsmart/actions/workflows/test.yml)
|
|
4
|
+
[](https://github.com/bsmartlabs/omniauth-bsmart/actions/workflows/release.yml)
|
|
5
|
+
[](https://badge.fury.io/rb/omniauth-bsmart)
|
|
6
|
+
|
|
7
|
+
🔌 OmniAuth OAuth2 strategy for bSmart accounts.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- OAuth2 Authorization Code flow using bSmart Doorkeeper endpoints
|
|
12
|
+
- User profile fetch from `GET /api/v6/user`
|
|
13
|
+
- Automatic fallback to `GET /api/v6/me` when `/user` is unavailable
|
|
14
|
+
- Auth hash with normalized `uid`, `info`, `credentials`, and `extra.raw_info`
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- Ruby `>= 3.2`
|
|
19
|
+
- OmniAuth `~> 2.0`
|
|
20
|
+
- `omniauth-oauth2` `>= 1.8`, `< 1.9`
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
gem 'omniauth-bsmart'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Basic Usage
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
use OmniAuth::Builder do
|
|
32
|
+
provider :bsmart,
|
|
33
|
+
ENV.fetch('BSMART_CLIENT_ID'),
|
|
34
|
+
ENV.fetch('BSMART_CLIENT_SECRET'),
|
|
35
|
+
scope: 'public'
|
|
36
|
+
end
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Endpoint Defaults
|
|
40
|
+
|
|
41
|
+
- Site: `https://www.bsmart.it`
|
|
42
|
+
- Authorize URL: `/oauth/authorize`
|
|
43
|
+
- Token URL: `/oauth/token`
|
|
44
|
+
- User Info URL: `/api/v6/user`
|
|
45
|
+
- Fallback User Info URL: `/api/v6/me`
|
|
46
|
+
|
|
47
|
+
### Optional Overrides
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
provider :bsmart,
|
|
51
|
+
ENV.fetch('BSMART_CLIENT_ID'),
|
|
52
|
+
ENV.fetch('BSMART_CLIENT_SECRET'),
|
|
53
|
+
client_options: {
|
|
54
|
+
site: 'https://www.bsmart.it',
|
|
55
|
+
authorize_url: '/oauth/authorize',
|
|
56
|
+
token_url: '/oauth/token'
|
|
57
|
+
},
|
|
58
|
+
user_info_url: '/api/v6/user',
|
|
59
|
+
me_url: '/api/v6/me'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## bSmart OAuth App Setup
|
|
63
|
+
|
|
64
|
+
Create an OAuth application in bSmart (Doorkeeper) and configure your callback URL:
|
|
65
|
+
|
|
66
|
+
- Production OAuth base: `https://www.bsmart.it/oauth`
|
|
67
|
+
- Production API base: `https://www.bsmart.it/api/v6`
|
|
68
|
+
|
|
69
|
+
Typical callback path:
|
|
70
|
+
|
|
71
|
+
- `/auth/bsmart/callback`
|
|
72
|
+
|
|
73
|
+
## Auth Hash
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"uid": "42",
|
|
78
|
+
"info": {
|
|
79
|
+
"name": "Ada Lovelace",
|
|
80
|
+
"email": "teacher@example.test",
|
|
81
|
+
"first_name": "Ada",
|
|
82
|
+
"last_name": "Lovelace",
|
|
83
|
+
"nickname": "teacher@example.test",
|
|
84
|
+
"image": "https://www.bsmart.it/avatar/42.png",
|
|
85
|
+
"roles": ["teacher"]
|
|
86
|
+
},
|
|
87
|
+
"credentials": {
|
|
88
|
+
"token": "access-token",
|
|
89
|
+
"refresh_token": "refresh-token",
|
|
90
|
+
"expires_at": 1773000000,
|
|
91
|
+
"expires": true,
|
|
92
|
+
"scope": "public"
|
|
93
|
+
},
|
|
94
|
+
"extra": {
|
|
95
|
+
"raw_info": {
|
|
96
|
+
"id": 42,
|
|
97
|
+
"email": "teacher@example.test",
|
|
98
|
+
"name": "Ada",
|
|
99
|
+
"surname": "Lovelace",
|
|
100
|
+
"avatar_url": "https://www.bsmart.it/avatar/42.png",
|
|
101
|
+
"roles": ["teacher"]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Development
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
bundle install
|
|
111
|
+
bundle exec rake lint
|
|
112
|
+
bundle exec rake test_unit
|
|
113
|
+
bundle exec rake test_rails_integration
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## CI Matrix
|
|
117
|
+
|
|
118
|
+
- Ruby: `3.2`, `3.3`, `3.4`, `4.0`
|
|
119
|
+
- Rails integration lanes: `~> 7.1.0`, `~> 7.2.0`, `~> 8.0.0`, `~> 8.1.0`
|
|
120
|
+
- `omniauth-oauth2`: `1.8.x`
|
|
121
|
+
|
|
122
|
+
## Release
|
|
123
|
+
|
|
124
|
+
Tag a release:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
git tag vX.Y.Z
|
|
128
|
+
git push origin vX.Y.Z
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The GitHub `Release` workflow publishes the gem through RubyGems Trusted Publishing.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'omniauth-oauth2'
|
|
4
|
+
|
|
5
|
+
module OmniAuth
|
|
6
|
+
module Strategies
|
|
7
|
+
# OmniAuth strategy for bSmart OAuth2.
|
|
8
|
+
class Bsmart < OmniAuth::Strategies::OAuth2
|
|
9
|
+
option :name, 'bsmart'
|
|
10
|
+
option :authorize_options, %i[scope]
|
|
11
|
+
option :scope, 'public'
|
|
12
|
+
|
|
13
|
+
option :client_options,
|
|
14
|
+
site: 'https://www.bsmart.it',
|
|
15
|
+
authorize_url: '/oauth/authorize',
|
|
16
|
+
token_url: '/oauth/token',
|
|
17
|
+
connection_opts: {
|
|
18
|
+
headers: {
|
|
19
|
+
user_agent: 'bsmartlabs-omniauth-bsmart gem',
|
|
20
|
+
accept: 'application/json'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
option :user_info_url, '/api/v6/user'
|
|
25
|
+
option :me_url, '/api/v6/me'
|
|
26
|
+
|
|
27
|
+
uid { raw_info['id']&.to_s }
|
|
28
|
+
|
|
29
|
+
info do
|
|
30
|
+
{
|
|
31
|
+
name: full_name,
|
|
32
|
+
email: raw_info['email'],
|
|
33
|
+
first_name: raw_info['name'],
|
|
34
|
+
last_name: raw_info['surname'],
|
|
35
|
+
nickname: raw_info['email'],
|
|
36
|
+
image: raw_info['avatar_url'],
|
|
37
|
+
roles: raw_info['roles']
|
|
38
|
+
}.compact
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
credentials do
|
|
42
|
+
{
|
|
43
|
+
'token' => access_token.token,
|
|
44
|
+
'refresh_token' => access_token.refresh_token,
|
|
45
|
+
'expires_at' => access_token.expires_at,
|
|
46
|
+
'expires' => access_token.expires?,
|
|
47
|
+
'scope' => token_scope
|
|
48
|
+
}.compact
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
extra do
|
|
52
|
+
{
|
|
53
|
+
'raw_info' => raw_info
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def raw_info
|
|
58
|
+
@raw_info ||= fetch_raw_info
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def full_name
|
|
64
|
+
candidate = [raw_info['name'], raw_info['surname']].compact.join(' ').strip
|
|
65
|
+
return candidate unless candidate.empty?
|
|
66
|
+
|
|
67
|
+
raw_info['email']
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def fetch_raw_info
|
|
71
|
+
[options[:user_info_url], options[:me_url]].compact.uniq.each do |path|
|
|
72
|
+
payload = access_token.get(path).parsed
|
|
73
|
+
normalized = normalize_raw_info(payload)
|
|
74
|
+
return normalized if normalized
|
|
75
|
+
rescue ::OAuth2::Error => e
|
|
76
|
+
raise unless fallback_user_info_error?(e)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
{}
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def normalize_raw_info(payload)
|
|
83
|
+
return unless payload.is_a?(Hash)
|
|
84
|
+
return payload if payload['id']
|
|
85
|
+
|
|
86
|
+
%w[user data].each do |key|
|
|
87
|
+
nested_payload = payload[key]
|
|
88
|
+
return nested_payload if nested_payload.is_a?(Hash) && nested_payload['id']
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def fallback_user_info_error?(error)
|
|
95
|
+
status = error.response&.status.to_i
|
|
96
|
+
[404, 405].include?(status)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def token_scope
|
|
100
|
+
token_params = access_token.respond_to?(:params) ? access_token.params : {}
|
|
101
|
+
token_params['scope'] || (access_token['scope'] if access_token.respond_to?(:[]))
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'omniauth/bsmart/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'omniauth-bsmart'
|
|
9
|
+
spec.version = OmniAuth::Bsmart::VERSION
|
|
10
|
+
spec.authors = ['Claudio Poli']
|
|
11
|
+
spec.email = ['masterkain@gmail.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'OmniAuth strategy for bSmart OAuth2 authentication.'
|
|
14
|
+
spec.description = 'OAuth2 OmniAuth strategy that authenticates users against bSmart and maps v6 user profile data.'
|
|
15
|
+
spec.homepage = 'https://github.com/bsmartlabs/omniauth-bsmart'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
spec.required_ruby_version = '>= 3.2'
|
|
18
|
+
|
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/bsmartlabs/omniauth-bsmart'
|
|
20
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/bsmartlabs/omniauth-bsmart/issues'
|
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/bsmartlabs/omniauth-bsmart/releases'
|
|
22
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
23
|
+
|
|
24
|
+
spec.files = Dir[
|
|
25
|
+
'lib/**/*.rb',
|
|
26
|
+
'README*',
|
|
27
|
+
'LICENSE*',
|
|
28
|
+
'*.gemspec'
|
|
29
|
+
]
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
|
|
32
|
+
spec.add_dependency 'cgi', '>= 0.3.6'
|
|
33
|
+
spec.add_dependency 'omniauth-oauth2', '>= 1.8', '< 1.9'
|
|
34
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: omniauth-bsmart
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Claudio Poli
|
|
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: cgi
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.3.6
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.3.6
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: omniauth-oauth2
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.8'
|
|
33
|
+
- - "<"
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '1.9'
|
|
36
|
+
type: :runtime
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '1.8'
|
|
43
|
+
- - "<"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '1.9'
|
|
46
|
+
description: OAuth2 OmniAuth strategy that authenticates users against bSmart and
|
|
47
|
+
maps v6 user profile data.
|
|
48
|
+
email:
|
|
49
|
+
- masterkain@gmail.com
|
|
50
|
+
executables: []
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- LICENSE.txt
|
|
55
|
+
- README.md
|
|
56
|
+
- lib/omniauth-bsmart.rb
|
|
57
|
+
- lib/omniauth/bsmart.rb
|
|
58
|
+
- lib/omniauth/bsmart/version.rb
|
|
59
|
+
- lib/omniauth/strategies/bsmart.rb
|
|
60
|
+
- omniauth-bsmart.gemspec
|
|
61
|
+
homepage: https://github.com/bsmartlabs/omniauth-bsmart
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata:
|
|
65
|
+
source_code_uri: https://github.com/bsmartlabs/omniauth-bsmart
|
|
66
|
+
bug_tracker_uri: https://github.com/bsmartlabs/omniauth-bsmart/issues
|
|
67
|
+
changelog_uri: https://github.com/bsmartlabs/omniauth-bsmart/releases
|
|
68
|
+
rubygems_mfa_required: 'true'
|
|
69
|
+
rdoc_options: []
|
|
70
|
+
require_paths:
|
|
71
|
+
- lib
|
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '3.2'
|
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
requirements: []
|
|
83
|
+
rubygems_version: 3.6.9
|
|
84
|
+
specification_version: 4
|
|
85
|
+
summary: OmniAuth strategy for bSmart OAuth2 authentication.
|
|
86
|
+
test_files: []
|