Skip to content

Commit 0cdca84

Browse files
committed
feat(examples): add jwks_only.rb (LICENSECHAIN_* env)
- README license JWT section + examples list
1 parent d43670b commit 0cdca84

2 files changed

Lines changed: 46 additions & 16 deletions

File tree

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,18 @@ rspec spec/client_spec.rb
430430
rspec spec/integration/
431431
```
432432

433+
## License assertion JWT (RS256 + JWKS)
434+
435+
When Core API returns **`license_token`** and **`license_jwks_uri`**, verify offline with **`LicenseChain::LicenseAssertion.verify_license_assertion_jwt`** (`jwt` gem + JWKS fetch; claim **`token_use`** = **`licensechain_license_v1`**). A minimal **JWKS-only** CLI (no prior `verify` call in-process) is **[`examples/jwks_only.rb`](examples/jwks_only.rb)** — set **`LICENSECHAIN_LICENSE_TOKEN`** and **`LICENSECHAIN_LICENSE_JWKS_URI`** (optional **`LICENSECHAIN_EXPECTED_APP_ID`**), then `ruby examples/jwks_only.rb` (same env names as Go/Rust/PHP; [JWKS_EXAMPLE_PRIORITY](https://github.com/LicenseChain/sdks/blob/main/docs/JWKS_EXAMPLE_PRIORITY.md)).
436+
433437
## 📝 Examples
434438

435439
See the `examples/` directory for complete examples:
436440

437441
- `basic_usage.rb` - Basic SDK usage
438442
- `advanced_features.rb` - Advanced features and configuration
439443
- `webhook_integration.rb` - Webhook handling
444+
- `jwks_only.rb` — RS256 `license_token` via JWKS only ([JWKS_EXAMPLE_PRIORITY](https://github.com/LicenseChain/sdks/blob/main/docs/JWKS_EXAMPLE_PRIORITY.md))
440445

441446
## 🤝 Contributing
442447

@@ -471,19 +476,19 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
471476
---
472477

473478
**Made with ❤️ for the Ruby community**
474-
475-
## LicenseChain API (v1)
476-
477-
This SDK targets the **LicenseChain HTTP API v1** implemented by the open-source API service.
478-
479-
- **Production base URL:** https://api.licensechain.app/v1
480-
- **API repository (source of routes & behavior):** https://github.com/LicenseChain/api
481-
- **Baseline REST mapping (documented for integrators):**
482-
- GET /health
483-
- POST /auth/register
484-
- POST /licenses/verify
485-
- PATCH /licenses/:id/revoke
486-
- PATCH /licenses/:id/activate
487-
- PATCH /licenses/:id/extend
488-
- GET /analytics/stats
489-
479+
480+
## LicenseChain API (v1)
481+
482+
This SDK targets the **LicenseChain HTTP API v1** implemented by the open-source API service.
483+
484+
- **Production base URL:** https://api.licensechain.app/v1
485+
- **API repository (source of routes & behavior):** https://github.com/LicenseChain/api
486+
- **Baseline REST mapping (documented for integrators):**
487+
- GET /health
488+
- POST /auth/register
489+
- POST /licenses/verify
490+
- PATCH /licenses/:id/revoke
491+
- PATCH /licenses/:id/activate
492+
- PATCH /licenses/:id/extend
493+
- GET /analytics/stats
494+

examples/jwks_only.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# JWKS-only: verify license_token with token + JWKS URI (parity with Go/Rust/PHP jwks_only).
5+
# export LICENSECHAIN_LICENSE_TOKEN="eyJ..."
6+
# export LICENSECHAIN_LICENSE_JWKS_URI="https://api.licensechain.app/v1/licenses/jwks"
7+
# # optional: LICENSECHAIN_EXPECTED_APP_ID=<uuid>
8+
# ruby examples/jwks_only.rb
9+
10+
require 'json'
11+
require_relative '../lib/licensechain_ruby_sdk'
12+
13+
token = ENV.fetch('LICENSECHAIN_LICENSE_TOKEN', '').strip
14+
jwks = ENV.fetch('LICENSECHAIN_LICENSE_JWKS_URI', '').strip
15+
if token.empty? || jwks.empty?
16+
warn 'Set LICENSECHAIN_LICENSE_TOKEN and LICENSECHAIN_LICENSE_JWKS_URI'
17+
exit 1
18+
end
19+
20+
opts = {}
21+
app = ENV['LICENSECHAIN_EXPECTED_APP_ID']&.strip
22+
opts[:expected_app_id] = app unless app.nil? || app.empty?
23+
24+
payload = LicenseChain::LicenseAssertion.verify_license_assertion_jwt(token, jwks, **opts)
25+
puts JSON.pretty_generate(payload)

0 commit comments

Comments
 (0)