clerk-sdk-ruby 4.0.1 → 4.1.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: d0afe6493d39ec3b1273a7c15930cd38ccd9ea35eec5d46c9f3ca50c7212fab5
4
- data.tar.gz: af49ba2bec123f277107c118fdf7576fece156a78de328c7351e3db8bc37e401
3
+ metadata.gz: 2c5d13e407e2b3827d2d451604f62d018e90ecb79fb28b12864318358bc7bcdf
4
+ data.tar.gz: c0c69cab555345231c04bec2dfb48316f4f4c66a04f8a5270588ba9a8e98230f
5
5
  SHA512:
6
- metadata.gz: 2440592868199c1c08ba259b2a32f3e551d17ceda2d8a7865b7bd8442e312b8cca7881280702e537a2b1952794c9e379fd71efd9a391f0c761f5cf57909809ba
7
- data.tar.gz: 474c06a1094afb7d39d1e9e3ee727f070873ca58f470d457fc5bc586b3f611de928935ff50237a41cc13bb437f36f4846a604752c645b0788e7de1a115e656e6
6
+ metadata.gz: 3f3b78b75a176ee0667fc492e85bb3672ce258c8fa869cc2196943ed85014e47526abc677d8771d034bcd505ee4edb4999a790f3e16206e0417b2cdaa29cbf96
7
+ data.tar.gz: 5b7f5366e6ed26d47c4e9856622c0424d46e6dbaf07f218e94f908e587755700b876069e677ecd4c75dc49ced41d18f113d4c2fdd9653dadde99922c8ea3da1f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 4.1.0 - 2025-04-10
2
+
3
+ - feat: Add support for org. claims of v2 session tokens [https://github.com/clerk/clerk-sdk-ruby/pull/89]
4
+
1
5
  ## 4.0.0.beta4 - 2025-01-06
2
6
 
3
7
  [BREAKING] This release introduces our new `clerk-http-client` gem, which is a generated directly from the Clerk API OpenAPI specs. This will help to ensure that the SDK is always in sync with the Clerk API.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clerk-sdk-ruby (4.0.1)
4
+ clerk-sdk-ruby (4.1.0)
5
5
  clerk-http-client (~> 2.0)
6
6
  concurrent-ruby (~> 1.1)
7
7
  faraday (>= 1.4.1, < 3.0)
data/lib/clerk/sdk.rb CHANGED
@@ -5,14 +5,14 @@ require "jwt"
5
5
 
6
6
  module Clerk
7
7
  class SDK < ClerkHttpClient::SDK
8
- # TODO: Move to constants?
9
8
  DEFAULT_HEADERS = {
10
9
  "User-Agent": "Clerk/#{Clerk::VERSION}; Faraday/#{Faraday::VERSION}; Ruby/#{RUBY_VERSION}",
11
- "X-Clerk-SDK": "ruby/#{Clerk::VERSION}" # TODO: Add framework identifier
10
+ "X-Clerk-SDK": "ruby/#{Clerk::VERSION}",
11
+ "Clerk-API-Version": "2025-04-10",
12
12
  }
13
13
 
14
14
  # How often (in seconds) should JWKs be refreshed
15
- JWKS_CACHE_LIFETIME = 3600 # 1 hour / TODO: Move to constants?
15
+ JWKS_CACHE_LIFETIME = 3600 # 1 hour
16
16
 
17
17
  @@jwks_cache = JWKSCache.new(JWKS_CACHE_LIFETIME)
18
18
 
@@ -41,7 +41,44 @@ module Clerk
41
41
  {keys: SDK.jwks_cache.fetch(self, kid_not_found: options[:invalidate] || options[:kid_not_found], force_refresh: force_refresh_jwks)}
42
42
  end
43
43
 
44
- JWT.decode(token, nil, true, algorithms: algorithms, exp_leeway: timeout, jwks: jwk_loader).first
44
+ claims = JWT.decode(token, nil, true, algorithms: algorithms, exp_leeway: timeout, jwks: jwk_loader).first
45
+
46
+ # orgs
47
+ if claims["v"].nil? || claims["v"] == 1
48
+ claims["v"] = 1
49
+ elsif claims["v"] == 2 && claims["o"]
50
+ claims["org_id"] = claims["o"].fetch("id", nil)
51
+ claims["org_slug"] = claims["o"].fetch("slg", nil)
52
+ claims["org_role"] = "org:#{claims["o"].fetch("rol", nil)}"
53
+
54
+ org_permissions = compute_org_permissions_from_v2_token(claims)
55
+ claims["org_permissions"] = org_permissions if org_permissions.any?
56
+ claims.delete("o")
57
+ claims.delete("fea")
58
+ end
59
+
60
+ claims
61
+ end
62
+
63
+ private
64
+
65
+ def compute_org_permissions_from_v2_token(claims)
66
+ features = claims["fea"].split(",")
67
+ permissions = claims["o"]["per"].split(",")
68
+ mappings = claims["o"]["fpm"].split(",")
69
+ org_permissions = []
70
+
71
+ mappings.each_with_index do |mapping, i|
72
+ scope, feature = features[i].split(":")
73
+
74
+ next if !scope.include?("o") # not an orgs-related permission
75
+
76
+ mapping.to_i.to_s(2).reverse.each_char.each_with_index do |bit, i|
77
+ org_permissions << "org:#{feature}:#{permissions[i]}" if bit == "1"
78
+ end
79
+ end
80
+
81
+ org_permissions
45
82
  end
46
83
  end
47
84
  end
data/lib/clerk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clerk
4
- VERSION = "4.0.1"
4
+ VERSION = "4.1.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clerk-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clerk
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 2025-02-14 00:00:00.000000000 Z
11
+ date: 2025-04-10 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: faraday
@@ -306,6 +307,7 @@ metadata:
306
307
  homepage_uri: https://github.com/clerkinc/clerk-sdk-ruby
307
308
  source_code_uri: https://github.com/clerkinc/clerk-sdk-ruby
308
309
  changelog_uri: https://github.com/clerkinc/clerk-sdk-ruby/blob/main/CHANGELOG.md
310
+ post_install_message:
309
311
  rdoc_options: []
310
312
  require_paths:
311
313
  - lib
@@ -320,7 +322,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
322
  - !ruby/object:Gem::Version
321
323
  version: '0'
322
324
  requirements: []
323
- rubygems_version: 3.6.2
325
+ rubygems_version: 3.5.3
326
+ signing_key:
324
327
  specification_version: 4
325
328
  summary: Clerk SDK for Ruby.
326
329
  test_files: []