alula-ruby 2.39.1 → 2.40.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 +4 -4
- data/README.md +18 -0
- data/VERSION.md +1 -0
- data/alula.gemspec +1 -0
- data/lib/alula/filter_builder.rb +1 -1
- data/lib/alula/keymaster.rb +94 -0
- data/lib/alula/version.rb +1 -1
- data/lib/alula.rb +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ec1d8b1f79ed0d8066e623b8ed335d9792bd240a949ff2d19caf259f2a970f3a
|
|
4
|
+
data.tar.gz: 0c9f5a7f2d3780334fcbf1d936e75c776e5ef0e928c1402d1c57d52a71fb3477
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 478d6bfc4375a7cfe604a5076c0b3d6b971c6bc8faefb261e271a8dd3bdfec5b5aff523f6ab6a8314860de4dd4c8c62d5e853de8fd2d9fe215e3210684e5a83b
|
|
7
|
+
data.tar.gz: bdff1264180f7fd748969cc540d1d329e12656209cf609bd688488e690db76ec397a17657caaf1d8c65db1b64953c9543a1f21c255d1adebd18b34d54c8ad94e
|
data/README.md
CHANGED
|
@@ -43,6 +43,24 @@ creds = Alula::Oauth.authenticate(username: "a username", password: "a password"
|
|
|
43
43
|
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
### Keymaster
|
|
47
|
+
|
|
48
|
+
`Alula::Keymaster` signs users in through Keymaster instead of the Core API's own OAuth endpoint. Keymaster checks the username and password against the Core API and returns a JWT that the Core API accepts as a Bearer token. Like `Alula::Oauth`, its settings are stored per request, so configure it on each request.
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
Alula::Keymaster.configure(issuer_url: "https://login.example.com/realms/m2m", client_id: "your Keymaster client id")
|
|
52
|
+
|
|
53
|
+
creds = Alula::Keymaster.authenticate(username: "a username", password: "a password", scope: "offline_access")
|
|
54
|
+
raise creds.error_description if creds.is_a?(Alula::Oauth::Error)
|
|
55
|
+
|
|
56
|
+
refreshed = Alula::Keymaster.refresh(refresh_token: creds.refresh_token)
|
|
57
|
+
creds = refreshed unless refreshed.is_a?(Alula::Oauth::Error)
|
|
58
|
+
|
|
59
|
+
Alula::Keymaster.revoke(refresh_token: creds.refresh_token)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`authenticate` and `refresh` return an `Alula::Oauth::Response` on success and an `Alula::Oauth::Error` otherwise. `revoke` returns `true` or an `Alula::Oauth::Error`. An error's `code` is the HTTP status, and its `error` and `error_description` are Keymaster's, which are not the same as the Core API's. Network failures and timeouts (15 seconds) raise. Ask for the `offline_access` scope to keep the user signed in until they sign out.
|
|
63
|
+
|
|
46
64
|
## Configuring
|
|
47
65
|
There are two types of settings in the `Alula::Client` configuration:
|
|
48
66
|
The first one are the ones that will have a fixed value in the application lifecicle so its better to put them in an initializer.
|
data/VERSION.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
| Version | Date | Description |
|
|
4
4
|
| ------- | ------------| --------------------------------------------------------------------------- |
|
|
5
|
+
| v2.40.0 | 2026-11-10 | Add `Alula::Keymaster` to sign users in through Keymaster: password grant, refresh and revoke. Replace `JSON.fast_generate`, removed in json 3, in `FilterBuilder` |
|
|
5
6
|
| v2.39.1 | 2026-08-14 | Bugfix: require admin_token_get_proc so it is available to consumers |
|
|
6
7
|
| v2.39.0 | 2026-08-14 | Add support for new admin.token.get RPC |
|
|
7
8
|
| v2.38.0 | 2026-08-10 | Upgrade Ruby to 4.0.6; require Ruby >= 4.0; declare logger and base64; move ostruct to a dev dependency; drop byebug |
|
data/alula.gemspec
CHANGED
data/lib/alula/filter_builder.rb
CHANGED
|
@@ -259,7 +259,7 @@ module Alula
|
|
|
259
259
|
# Ensure a value will be a JSON-encodable value. We don't really care what it is,
|
|
260
260
|
# but what comes out of JSON serialization is what we'll use.
|
|
261
261
|
def simple_value!(value)
|
|
262
|
-
JSON.parse(JSON.
|
|
262
|
+
JSON.parse(JSON.generate({ purify: value }))['purify']
|
|
263
263
|
end
|
|
264
264
|
|
|
265
265
|
def simple_values!(values)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module Alula
|
|
5
|
+
class Keymaster
|
|
6
|
+
include HTTParty
|
|
7
|
+
|
|
8
|
+
follow_redirects false
|
|
9
|
+
default_timeout 15
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def configure(**config)
|
|
13
|
+
self.issuer_url = config[:issuer_url]&.chomp('/')
|
|
14
|
+
self.client_id = config[:client_id]
|
|
15
|
+
nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def authenticate(username:, password:, scope: nil)
|
|
19
|
+
body = {
|
|
20
|
+
grant_type: 'password',
|
|
21
|
+
client_id: client_id,
|
|
22
|
+
username: username,
|
|
23
|
+
password: password
|
|
24
|
+
}
|
|
25
|
+
body[:scope] = scope if scope
|
|
26
|
+
|
|
27
|
+
token_result(post_form('token', body))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def refresh(refresh_token:)
|
|
31
|
+
body = {
|
|
32
|
+
grant_type: 'refresh_token',
|
|
33
|
+
client_id: client_id,
|
|
34
|
+
refresh_token: refresh_token
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
token_result(post_form('token', body))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def revoke(refresh_token:)
|
|
41
|
+
body = {
|
|
42
|
+
client_id: client_id,
|
|
43
|
+
token: refresh_token,
|
|
44
|
+
token_type_hint: 'refresh_token'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
response = post_form('revoke', body)
|
|
48
|
+
response.ok? ? true : error_result(response, json_body(response))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
%i(issuer_url client_id).each do |prop|
|
|
52
|
+
define_method(prop) do
|
|
53
|
+
RequestStore.store["alula_keymaster_#{prop}"]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
define_method("#{prop}=") do |value|
|
|
57
|
+
RequestStore.store["alula_keymaster_#{prop}"] = value
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def post_form(endpoint, body)
|
|
64
|
+
unless issuer_url && client_id
|
|
65
|
+
raise Alula::NotConfiguredError.new('did you forget to call Alula::Keymaster.configure ?')
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
post("#{issuer_url}/protocol/openid-connect/#{endpoint}", { body: body })
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def token_result(response)
|
|
72
|
+
body = json_body(response)
|
|
73
|
+
return error_result(response, body) unless response.ok? && token_body?(body)
|
|
74
|
+
|
|
75
|
+
Alula::Oauth::Response.new(body)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def token_body?(body)
|
|
79
|
+
body.is_a?(Hash) && body['access_token'].is_a?(String) && body['expires_in'].is_a?(Integer)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def error_result(response, body)
|
|
83
|
+
attributes = body.is_a?(Hash) ? body : {}
|
|
84
|
+
Alula::Oauth::Error.new(attributes.merge('code' => response.code))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def json_body(response)
|
|
88
|
+
JSON.parse(response.body.to_s)
|
|
89
|
+
rescue JSON::ParserError
|
|
90
|
+
nil
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
data/lib/alula/version.rb
CHANGED
data/lib/alula.rb
CHANGED
|
@@ -41,6 +41,7 @@ require_relative 'alula/client_configuration'
|
|
|
41
41
|
require_relative 'alula/errors'
|
|
42
42
|
require_relative 'alula/list_object'
|
|
43
43
|
require_relative 'alula/oauth'
|
|
44
|
+
require_relative 'alula/keymaster'
|
|
44
45
|
require_relative 'alula/helpers/device_helpers/attribute_translations_helper'
|
|
45
46
|
require_relative 'alula/helpers/device_helpers/program_id_helper'
|
|
46
47
|
require_relative 'alula/resources/billing_program'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: alula-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.40.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Titus Johnson
|
|
@@ -217,6 +217,20 @@ dependencies:
|
|
|
217
217
|
- - ">="
|
|
218
218
|
- !ruby/object:Gem::Version
|
|
219
219
|
version: '0'
|
|
220
|
+
- !ruby/object:Gem::Dependency
|
|
221
|
+
name: webmock
|
|
222
|
+
requirement: !ruby/object:Gem::Requirement
|
|
223
|
+
requirements:
|
|
224
|
+
- - "~>"
|
|
225
|
+
- !ruby/object:Gem::Version
|
|
226
|
+
version: '3.25'
|
|
227
|
+
type: :development
|
|
228
|
+
prerelease: false
|
|
229
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
230
|
+
requirements:
|
|
231
|
+
- - "~>"
|
|
232
|
+
- !ruby/object:Gem::Version
|
|
233
|
+
version: '3.25'
|
|
220
234
|
description: Alula Ruby API Client
|
|
221
235
|
email:
|
|
222
236
|
- titus.johnson@alula.net
|
|
@@ -276,6 +290,7 @@ files:
|
|
|
276
290
|
- lib/alula/helpers/device_helpers/attribute_translations_helper.rb
|
|
277
291
|
- lib/alula/helpers/device_helpers/program_id_helper.rb
|
|
278
292
|
- lib/alula/helpers/jwt_helper.rb
|
|
293
|
+
- lib/alula/keymaster.rb
|
|
279
294
|
- lib/alula/list_object.rb
|
|
280
295
|
- lib/alula/m2m_response.rb
|
|
281
296
|
- lib/alula/m2m_rest_resource.rb
|