Skip to content

Add idp_url and api_server_id to Authlete::Client - #26

Open
srqai wants to merge 2 commits into
mainfrom
idp-url-override
Open

srqai wants to merge 2 commits into
mainfrom
idp-url-override

Conversation

@srqai

@srqai srqai commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Lets one Authlete::Client reach both the main API and the Authlete IdP, with the IdP URL overridable for DC/self-managed deployments. Ruby counterpart of authlete/authlete-typescript-sdk#36.

Usage

# SaaS: nothing new to set. services.create / remove get the cluster's apiServerId from server_url.
sdk = Authlete::Client.new(bearer: token, server_url: 'https://jp.authlete.com')

# DC / self-managed
sdk = Authlete::Client.new(bearer: token,
                           server_url: 'https://authlete.example.com',
                           idp_url: 'https://authlete-login.example.com',
                           api_server_id: 99_999)

How it works

  • lib/authlete/idp.rb (hand-written) adds idp_url: and api_server_id: to Authlete::Client.new.
  • It installs a Faraday middleware on a private copy of the client's connection, so a connection shared between clients is never modified.
  • The middleware re-points requests for the spec's IdP origin (login.authlete.com) at idp_url, keeping any path prefix, and fills in apiServerId on service create and remove unless the caller set it.
  • apiServerId is derived from server_url for the SaaS clusters only while the IdP is the default. With a custom idp_url, it comes only from api_server_id.
  • .speakeasy/patches/lib/authlete_ruby_sdk.rb.patch adds one require_relative to the gem entry point. Speakeasy reapplies it after every generation, so customers need no extra require.

Testing

  • test/idp_routing_test.rb: 30 tests, no network. SaaS derivation for all four clusters and server_idx, explicit and caller-supplied IDs, path prefix, port, invalid URL, main API requests unchanged, shared-connection isolation, retries injecting once, 600 concurrent requests, together with the service_id global.
  • Survives regeneration: three speakeasy runs apply the patch once each time and keep the hand-written files.
  • Built gem installed into a clean GEM_HOME loads it from require "authlete_ruby_sdk".
  • Live harness, all passing on JP: https://git.authlete.com/shariq.nazr/sdk-testing/-/tree/ruby

CI

This adds the Ruby repo's first PR checks, so the hand-written IdP code is checked after every regeneration.

  • Repair: Speakeasy reapplies .speakeasy/patches/lib/authlete_ruby_sdk.rb.patch on every generation, including the robot's daily runs. If the patch can no longer apply, Speakeasy fails the generation instead of producing an SDK without it. No repair script of our own is needed.
  • Tests (.github/workflows/tests.yaml, new): on every pull request and push to main, it checks that the require_relative 'authlete/idp' line is in the gem entry point, runs the 30 offline tests, and runs rubocop on the hand-written files. Robot regeneration PRs run it too, so a regeneration that lost the patch shows a failed check before merge.
  • Release gate (.github/workflows/sdk_publish.yaml): the same checks run first, and publishing waits for them (needs: test), so a broken SDK is never released to RubyGems.

Verified by deleting the require line locally: the patch check failed and 25 of the 30 tests failed. No secrets are needed; the tests do not use the network.

Release

After merging, run Generate with set_version=2.0.0 to publish #25 and this change together.

shariq added 2 commits October 19, 2026 17:04
One client now reaches both the main API and the Authlete IdP, with the IdP
URL overridable for DC/self-managed deployments:

    Authlete::Client.new(bearer: token, server_url: 'https://jp.authlete.com')
    # services.create / remove get apiServerId 53285 automatically

    Authlete::Client.new(bearer: token, server_url: 'https://authlete.example.com',
                         idp_url: 'https://authlete-login.example.com',
                         api_server_id: 99_999)

lib/authlete/idp.rb is hand-written. It installs a Faraday middleware on a
private copy of the client's connection, so a connection shared between
clients is never modified. The middleware re-points requests for the
spec-defined IdP origin at idp_url (keeping any path prefix) and fills in
apiServerId on service create and remove unless the caller set it. The ID is
derived from server_url for SaaS clusters only while the IdP is the default.

The gem entry point loads it through
.speakeasy/patches/lib/authlete_ruby_sdk.rb.patch, which Speakeasy reapplies
after every generation.

Matches the TypeScript SDK's behaviour (authlete/authlete-typescript-sdk#36).
- tests.yaml (new): on every pull request and push to main, checks that the
  require line from .speakeasy/patches is in the gem entry point, runs the
  offline tests in test/idp_routing_test.rb, and runs rubocop on the
  hand-written files. Robot regeneration PRs run it too, so a regeneration
  that lost the patch shows a failed check before merge.
- sdk_publish.yaml: the same checks run first, and publishing waits for them
  (needs: test), so a broken SDK is never released.

No secrets needed; the tests do not use the network.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant