holivia 0.12.0 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14dc959e163c982b0cb9ff68d098eb453c99c9802055de1c6086c8b61541894b
4
- data.tar.gz: cb404446122ffd0f4dab4535b358ec50c6bcdda67781c569f9c6db699ca8ed3e
3
+ metadata.gz: 5727339aa56fea9ffe71d4f5e0c49fdcd91a2d120aa3f88f7ff33f6a7b6eb49a
4
+ data.tar.gz: 6860e618178ca2b72dd346ec6f02b900cb1aaf48299db21bd6b2e98b6944ad9e
5
5
  SHA512:
6
- metadata.gz: fd225340d2dd039e3a40f1104b0a606db28e3b5d30b3f7bd5a19a3ddc6d4e222a1519db2db64a3429fa8040ddc2131b38b5dafca3ce61701241c939e562475ae
7
- data.tar.gz: c55acec78801a2a38ffa864d95997ae1e0245baa82fa57f53a508592d53a25b77e6c4809cc9d07ff44e9d2eb444a85d22a57d283ade5d32e3ae6d37ae8ec23c8
6
+ metadata.gz: 573b090f0d92ee3676f920992e1c60f71b17b423627a000a4f4d118a1f394657670ce40c19d378f29bf4f56b2f54b682716d66ee70b80db1c7ccf1b088742d37
7
+ data.tar.gz: 26a6014d2c1351a3c2887c406ea572e7c5b73874077533c96c667ef8f11329e3a749954ae2ba141356066d51eff1ec970e758faa236d96687218db48f794d7da
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.13.0] - 2026-09-30
4
+
5
+ - Replace terminal password login with browser OAuth authorization using PKCE and existing password/company SSO sign-in.
6
+ - Require CLI upgrade and a new login; remove `--email`/`--password` and legacy `/api/v1/auth/*` endpoints.
7
+ - Use two-hour access tokens, rotating refresh tokens without a fixed expiry, and server revocation for logout.
8
+ - Store per-environment credentials atomically with owner-only permissions and omit credentials from debug logs.
9
+ - Keep browser and CLI sessions independent; existing API permissions continue to apply.
10
+ - Redirect browser authorization callbacks to the localized Holivia completion page while the CLI exchanges tokens separately.
11
+ - Requires the matching Holivia OAuth server deployment and provisioning of the public CLI application.
12
+
3
13
  ## [0.12.0] - 2026-09-16
4
14
 
5
15
  - Add `holivia tag` commands for catalogue CRUD and incremental topic-link management through repeatable `--topic-tag-json` flags or stdin JSON
data/README.md CHANGED
@@ -73,21 +73,23 @@ holivia env debug --false
73
73
 
74
74
  ## Authentication
75
75
 
76
- Log in interactively:
76
+ Log in through your browser using your existing password or company SSO:
77
77
 
78
78
  ```bash
79
79
  holivia login
80
80
  ```
81
81
 
82
- Or pass credentials directly:
83
-
84
- ```bash
85
- holivia login --email user@example.com --password secret
86
- ```
82
+ The CLI opens a browser and prints a URL you can open manually on the same computer. A temporary loopback listener receives the callback. Browserless login is not supported.
87
83
 
88
84
  Credentials are stored per environment in `~/.holivia/credentials.<env>.json`. Access tokens are sent as bearer tokens, and the CLI automatically refreshes credentials after a `401` response when a refresh token is available.
89
85
 
90
- Log out and remove stored credentials for the current environment:
86
+ Access tokens expire after two hours. Refresh tokens have no fixed expiry and rotate when used. Credential files are replaced atomically with owner-only permissions. Pundit permissions still determine which API operations the user may perform.
87
+
88
+ Existing users must upgrade the CLI and run `holivia login` again. The old `/api/v1/auth/login`, `/api/v1/auth/refresh`, and `/api/v1/auth/logout` endpoints and `--email`/`--password` flags have been removed.
89
+
90
+ The database migration drops the legacy `auth_tokens` table. Rolling it back restores the table structure only; deleted or revoked credentials are not restored. Users must log in again.
91
+
92
+ Logout revokes this CLI session and removes credentials for the current environment. Other CLI sessions and browser sessions remain signed in. If the server cannot be reached, credentials are retained so logout can be retried:
91
93
 
92
94
  ```bash
93
95
  holivia logout
data/SKILL.md CHANGED
@@ -16,7 +16,7 @@ Use `holivia` in examples below. If working from a checkout before installation,
16
16
 
17
17
  - Never invent API URLs, credentials, IDs, enum values, or content model fields.
18
18
  - Never print, store, or commit passwords, access tokens, refresh tokens, or files under `~/.holivia/credentials.*.json`.
19
- - Prefer interactive `holivia login` when a human can enter credentials. Use `--password` only when the user explicitly provides it for automation.
19
+ - Use `holivia login` and let the user authenticate in their browser. Terminal email/password flags are no longer supported.
20
20
  - Before creating or updating content, run `holivia selfcare schema` and use its returned enum values and permitted item params as the source of truth.
21
21
  - Before creating or updating intervention catalog items, run `holivia intervention schema` and use its returned enum values and locales as the source of truth.
22
22
  - Before creating or updating HR home highlights, run `holivia highlight schema` and use its returned enum values and locales as the source of truth.
@@ -90,19 +90,19 @@ Debug logging may expose request details. Do not enable it in shared logs unless
90
90
 
91
91
  Credentials are stored per environment at `~/.holivia/credentials.<env>.json`. The CLI sends the access token as a bearer token and refreshes credentials automatically after a `401` response when possible.
92
92
 
93
- Interactive login:
93
+ Browser login using your existing password or company SSO:
94
94
 
95
95
  ```bash
96
96
  holivia login
97
97
  ```
98
98
 
99
- Non-interactive login:
99
+ A browser on the same computer is required. If it does not open automatically, open the printed URL manually. Do not ask for terminal credentials; browserless login is not supported.
100
100
 
101
- ```bash
102
- holivia login --email user@example.com --password secret
103
- ```
101
+ Access tokens expire after two hours. Refresh tokens have no fixed expiry and rotate when used. Credential files are replaced atomically with owner-only permissions. Pundit permissions still determine which API operations the user may perform.
102
+
103
+ Existing users must upgrade the CLI and run `holivia login` again. The old `/api/v1/auth/login`, `/api/v1/auth/refresh`, and `/api/v1/auth/logout` endpoints and `--email`/`--password` flags have been removed.
104
104
 
105
- Logout for the current environment:
105
+ Logout revokes this CLI session and removes credentials for the current environment. Other CLI sessions and browser sessions remain signed in. If the server cannot be reached, credentials are retained so logout can be retried:
106
106
 
107
107
  ```bash
108
108
  holivia logout
data/exe/holivia CHANGED
@@ -9,7 +9,10 @@ rescue Holivia::ApiError => e
9
9
  warn "Error (#{e.status}): #{e.message}"
10
10
  warn JSON.pretty_generate(e.details) if e.details.is_a?(Hash)
11
11
  exit 1
12
- rescue Holivia::ConfigError => e
12
+ rescue Holivia::ConfigError, Holivia::BrowserLogin::Error, OptionParser::ParseError, Faraday::Error => e
13
13
  warn "Error: #{e.message}"
14
14
  exit 1
15
+ rescue Interrupt
16
+ warn "Cancelled."
17
+ exit 130
15
18
  end
data/lib/holivia/auth.rb CHANGED
@@ -2,15 +2,20 @@
2
2
 
3
3
  require "json"
4
4
  require "fileutils"
5
+ require "tempfile"
5
6
 
6
7
  module Holivia
7
8
  class Auth
8
- def initialize(client: Client.new(auth: nil))
9
- @client = client
9
+ def initialize(client: nil, configuration: Holivia.configuration)
10
+ @client = client || Client.new(base_url: configuration.base_url, auth: nil)
11
+ @credentials_path = configuration.credentials_path.dup.freeze
10
12
  end
11
13
 
12
- def login(email:, password:)
13
- response = client.post("/api/v1/auth/login", body: { email: email, password: password })
14
+ def login(code:, code_verifier:, redirect_uri:)
15
+ response = client.post_form("/oauth/token", body: {
16
+ grant_type: "authorization_code", client_id: BrowserLogin::CLIENT_ID,
17
+ code: code, code_verifier: code_verifier, redirect_uri: redirect_uri
18
+ })
14
19
  store_tokens(response)
15
20
  response
16
21
  end
@@ -18,15 +23,25 @@ module Holivia
18
23
  def refresh
19
24
  raise ApiError.new("No refresh token. Run `holivia login`.", status: 401) unless refresh_token
20
25
 
21
- response = client.post("/api/v1/auth/refresh", headers: { "Authorization" => "Bearer #{refresh_token}" })
26
+ response = client.post_form("/oauth/token", body: {
27
+ grant_type: "refresh_token", client_id: BrowserLogin::CLIENT_ID,
28
+ refresh_token: refresh_token
29
+ })
22
30
  store_tokens(response)
23
31
  response
32
+ rescue ApiError => e
33
+ raise unless e.details.is_a?(Hash) && e.details["error"] == "invalid_grant"
34
+
35
+ raise ApiError.new("Session expired or revoked. Run `holivia login`.", status: 401)
24
36
  end
25
37
 
26
38
  def logout
27
- raise ApiError.new("Already logged out.", status: 401) unless access_token
39
+ raise ApiError.new("Already logged out.", status: 401) unless refresh_token
28
40
 
29
- response = client.delete("/api/v1/auth/logout", headers: { "Authorization" => "Bearer #{access_token}" })
41
+ response = client.post_form("/oauth/revoke", body: {
42
+ client_id: BrowserLogin::CLIENT_ID, token: refresh_token,
43
+ token_type_hint: "refresh_token"
44
+ })
30
45
  FileUtils.rm_f(credentials_path)
31
46
  response
32
47
  end
@@ -41,7 +56,7 @@ module Holivia
41
56
 
42
57
  private
43
58
 
44
- attr_reader :client
59
+ attr_reader :client, :credentials_path
45
60
 
46
61
  def credentials
47
62
  return nil unless File.exist?(credentials_path)
@@ -50,17 +65,14 @@ module Holivia
50
65
  end
51
66
 
52
67
  def store_tokens(data)
53
- FileUtils.mkdir_p(File.dirname(credentials_path))
54
-
55
- File.write(credentials_path, JSON.pretty_generate(
56
- "access_token" => data["access_token"],
57
- "refresh_token" => data["refresh_token"]
58
- ))
59
- File.chmod(0o600, credentials_path)
60
- end
61
-
62
- def credentials_path
63
- Holivia.configuration.credentials_path
68
+ directory = File.dirname(credentials_path)
69
+ FileUtils.mkdir_p(directory, mode: 0o700)
70
+ Tempfile.create(["credentials", ".json"], directory) do |file|
71
+ file.write(JSON.pretty_generate(data.slice("access_token", "refresh_token")))
72
+ file.flush
73
+ file.fsync
74
+ File.rename(file.path, credentials_path)
75
+ end
64
76
  end
65
77
  end
66
78
  end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "securerandom"
5
+ require "socket"
6
+ require "timeout"
7
+ require "uri"
8
+
9
+ module Holivia
10
+ class BrowserLogin
11
+ class Error < StandardError; end
12
+
13
+ CLIENT_ID = "holivia-cli"
14
+
15
+ def initialize(base_url: Holivia.configuration.base_url, output: $stderr, timeout: 180, browser_launcher: nil)
16
+ @base_url = base_url.dup.freeze
17
+ @output = output
18
+ @timeout = timeout
19
+ @browser_launcher = browser_launcher || method(:launch_browser)
20
+ end
21
+
22
+ def call
23
+ verifier = SecureRandom.urlsafe_base64(32)
24
+ state = SecureRandom.urlsafe_base64(32)
25
+ server = TCPServer.new("127.0.0.1", 0)
26
+ redirect_uri = "http://127.0.0.1:#{server.addr[1]}/callback"
27
+
28
+ Timeout.timeout(@timeout, Error, "Browser login timed out. Run holivia login to try again.") do
29
+ open_browser(authorization_url(verifier, state, redirect_uri))
30
+ code = receive_code(server, state)
31
+ { code: code, code_verifier: verifier, redirect_uri: redirect_uri }
32
+ end
33
+ ensure
34
+ server&.close
35
+ end
36
+
37
+ private
38
+
39
+ def authorization_url(verifier, state, redirect_uri)
40
+ url = URI.join(@base_url, "/oauth/authorize")
41
+ url.query = URI.encode_www_form(
42
+ client_id: CLIENT_ID, response_type: "code", redirect_uri: redirect_uri,
43
+ code_challenge: [Digest::SHA256.digest(verifier)].pack("m0").tr("+/", "-_").delete("="),
44
+ code_challenge_method: "S256", state: state
45
+ )
46
+ url.to_s
47
+ end
48
+
49
+ def open_browser(url)
50
+ @output.puts "Open this URL in a browser on this computer to log in:\n#{url}"
51
+ @browser_launcher.call(url)
52
+ end
53
+
54
+ def launch_browser(url)
55
+ command = RUBY_PLATFORM.include?("darwin") ? "open" : "xdg-open"
56
+ system(command, url, out: File::NULL, err: File::NULL)
57
+ end
58
+
59
+ def receive_code(server, state)
60
+ loop do
61
+ code = handle_callback(server.accept, state)
62
+ return code if code
63
+ end
64
+ end
65
+
66
+ def handle_callback(socket, state)
67
+ params = callback_params(socket.gets("\r\n\r\n", 8192))
68
+ unless valid_callback?(params, state)
69
+ respond(socket, "400 Bad Request", "Invalid login callback.")
70
+ return nil
71
+ end
72
+
73
+ complete_callback(socket, params)
74
+ rescue SystemCallError, IOError
75
+ nil # A disconnected browser must not prevent a later valid callback.
76
+ ensure
77
+ socket.close
78
+ end
79
+
80
+ def callback_params(request)
81
+ return {} unless request&.end_with?("\r\n\r\n")
82
+
83
+ match = request.lines.first.match(%r{\AGET /callback\?([^\s]+) HTTP/1\.[01]\r\n\z})
84
+ return {} unless match
85
+
86
+ pairs = URI.decode_www_form(match[1])
87
+ return {} unless pairs.map(&:first).uniq.length == pairs.length
88
+
89
+ pairs.to_h
90
+ rescue ArgumentError
91
+ {}
92
+ end
93
+
94
+ def valid_callback?(params, state)
95
+ return false unless params["state"] == state
96
+
97
+ code = params["code"]
98
+ error = params["error"]
99
+ (code && !code.empty? && error.nil?) || (error && !error.empty? && code.nil?)
100
+ end
101
+
102
+ def complete_callback(socket, params)
103
+ if params["error"]
104
+ respond(socket, "200 OK", "Authorization was not granted. Return to the terminal.")
105
+ raise Error, "Authorization was not granted. Run holivia login to try again."
106
+ end
107
+
108
+ redirect_to_completion(socket)
109
+ params.fetch("code")
110
+ end
111
+
112
+ def redirect_to_completion(socket)
113
+ url = URI.join(@base_url, "/oauth/complete")
114
+ socket.write "HTTP/1.1 303 See Other\r\nLocation: #{url}\r\n" \
115
+ "Referrer-Policy: no-referrer\r\nCache-Control: no-store\r\n" \
116
+ "Content-Length: 0\r\nConnection: close\r\n\r\n"
117
+ end
118
+
119
+ def respond(socket, status, message)
120
+ socket.write "HTTP/1.1 #{status}\r\nContent-Type: text/plain; charset=utf-8\r\n" \
121
+ "Content-Length: #{message.bytesize}\r\nCache-Control: no-store\r\n" \
122
+ "Connection: close\r\n\r\n#{message}"
123
+ end
124
+ end
125
+ end
@@ -17,7 +17,7 @@ module Holivia
17
17
  Config stored at ~/.holivia/config.yml. Defaults to staging if no config exists.
18
18
 
19
19
  Authentication:
20
- holivia login [--email EMAIL --password PASSWORD] Log in (flags or interactive prompt)
20
+ holivia login Log in through your browser (password or company SSO)
21
21
  holivia logout Log out and clear stored credentials
22
22
  Tokens are stored at ~/.holivia/credentials.<env>.json and refreshed automatically on 401.
23
23
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "faraday"
4
4
  require "faraday/multipart"
5
+ require "uri"
5
6
 
6
7
  module Holivia
7
8
  class Client
@@ -15,6 +16,16 @@ module Holivia
15
16
  request(:post, path, body:, headers:)
16
17
  end
17
18
 
19
+ def post_form(path, body: {})
20
+ response = connection.post(path) do |req|
21
+ req.headers["Accept"] = "application/json"
22
+ req.headers["Content-Type"] = "application/x-www-form-urlencoded"
23
+ req.body = URI.encode_www_form(body)
24
+ end
25
+
26
+ handle_response(response)
27
+ end
28
+
18
29
  def get(path, params: {}, headers: {})
19
30
  request(:get, path, params:, headers:)
20
31
  end
@@ -59,7 +70,7 @@ module Holivia
59
70
  @connection ||= http.new(url: base_url) do |f|
60
71
  f.request :multipart
61
72
  f.request :json
62
- f.response :logger if Holivia.configuration.debug?
73
+ f.response :logger, nil, headers: false, bodies: false if Holivia.configuration.debug?
63
74
  f.response :json
64
75
  f.adapter Faraday.default_adapter
65
76
  end
@@ -77,6 +88,8 @@ module Holivia
77
88
  return "Request failed" unless body.is_a?(Hash)
78
89
 
79
90
  error = body["error"]
91
+ return [error, body["error_description"]].compact.join(": ") if error.is_a?(String)
92
+
80
93
  error.is_a?(Hash) ? (error["message"] || "Request failed") : (error || "Request failed")
81
94
  end
82
95
 
@@ -1,23 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "io/console"
4
3
  require "optparse"
5
4
 
6
5
  module Holivia
7
6
  module Commands
8
7
  class Auth
9
8
  def login(args = [])
10
- options = {}
11
9
  OptionParser.new do |opts|
12
- opts.banner = "Usage: holivia login [--email EMAIL --password PASSWORD]"
13
- opts.on("--email EMAIL") { |v| options[:email] = v }
14
- opts.on("--password PASSWORD") { |v| options[:password] = v }
10
+ opts.banner = "Usage: holivia login"
15
11
  end.parse!(args)
12
+ raise OptionParser::InvalidArgument, args.join(" ") unless args.empty?
16
13
 
17
- email = options[:email] || prompt("Email: ")
18
- password = options[:password] || prompt_secret("Password: ")
19
-
20
- Holivia::Auth.new.login(email: email, password: password)
14
+ auth = Holivia::Auth.new
15
+ exchange = BrowserLogin.new.call
16
+ auth.login(**exchange)
21
17
  puts "Logged in successfully."
22
18
  end
23
19
 
@@ -25,20 +21,6 @@ module Holivia
25
21
  Holivia::Auth.new.logout
26
22
  puts "Logged out successfully."
27
23
  end
28
-
29
- private
30
-
31
- def prompt(label)
32
- print label
33
- $stdin.gets.chomp
34
- end
35
-
36
- def prompt_secret(label)
37
- print label
38
- result = $stdin.noecho(&:gets).chomp
39
- puts
40
- result
41
- end
42
24
  end
43
25
  end
44
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Holivia
4
- VERSION = "0.12.0"
4
+ VERSION = "0.13.0"
5
5
  end
data/lib/holivia.rb CHANGED
@@ -7,6 +7,7 @@ require_relative "holivia/api_error"
7
7
  require_relative "holivia/config_error"
8
8
  require_relative "holivia/client"
9
9
  require_relative "holivia/auth"
10
+ require_relative "holivia/browser_login"
10
11
 
11
12
  module Holivia
12
13
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holivia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Holivia
@@ -57,6 +57,7 @@ files:
57
57
  - lib/holivia.rb
58
58
  - lib/holivia/api_error.rb
59
59
  - lib/holivia/auth.rb
60
+ - lib/holivia/browser_login.rb
60
61
  - lib/holivia/cli.rb
61
62
  - lib/holivia/cli/help.rb
62
63
  - lib/holivia/client.rb