From 408037081ef9d222679e566efd7252ebce429b45 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 29 Oct 2024 15:12:02 -0700 Subject: [PATCH] updating usage to be explicit --- lib/livekit/access_token.rb | 2 ++ lib/livekit/auth_mixin.rb | 4 ++-- spec/livekit/access_token_spec.rb | 4 ++-- spec/livekit/token_verifier_spec.rb | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/livekit/access_token.rb b/lib/livekit/access_token.rb index 3398e36..f3eb7b5 100644 --- a/lib/livekit/access_token.rb +++ b/lib/livekit/access_token.rb @@ -31,6 +31,7 @@ def initialize( @ttl = ttl end + # Deprecated, use set_video_grant instead def add_grant(video_grant) if video_grant.is_a?(Hash) video_grant = VideoGrant.from_hash(video_grant) @@ -42,6 +43,7 @@ def set_video_grant(video_grant) @grants.video = video_grant end + # Deprecated, use set_sip_grant instead def add_sip_grant(sip_grant) if sip_grant.is_a?(Hash) sip_grant = SIPGrant.from_hash(sip_grant) diff --git a/lib/livekit/auth_mixin.rb b/lib/livekit/auth_mixin.rb index 42e2349..c7a5163 100644 --- a/lib/livekit/auth_mixin.rb +++ b/lib/livekit/auth_mixin.rb @@ -10,10 +10,10 @@ def auth_header( headers = {} t = ::LiveKit::AccessToken.new(api_key: @api_key, api_secret: @api_secret) if video_grant != nil - t.add_grant(video_grant) + t.set_sip_grant(video_grant) end if sip_grant != nil - t.add_sip_grant(sip_grant) + t.set_sip_grant(sip_grant) end headers["Authorization"] = "Bearer #{t.to_jwt}" headers["User-Agent"] = "LiveKit Ruby SDK" diff --git a/spec/livekit/access_token_spec.rb b/spec/livekit/access_token_spec.rb index 5e53260..19dced8 100644 --- a/spec/livekit/access_token_spec.rb +++ b/spec/livekit/access_token_spec.rb @@ -6,7 +6,7 @@ RSpec.describe LiveKit::AccessToken do it "generates a valid JWT with defaults" do token = described_class.new(api_key: TEST_KEY, api_secret: TEST_SECRET) - token.add_grant LiveKit::VideoGrant.new + token.set_video_grant LiveKit::VideoGrant.new jwt = token.to_jwt decoded = JWT.decode(jwt, TEST_SECRET, true, algorithm: "HS256") expect(decoded.first["iss"]).to eq(TEST_KEY) @@ -24,7 +24,7 @@ token = described_class.new(api_key: TEST_KEY, api_secret: TEST_SECRET, identity: "test_identity", ttl: 60) token.name = "myname" - token.add_grant(LiveKit::VideoGrant.new(roomJoin: true, room: "myroom", canPublish: false)) + token.set_video_grant(LiveKit::VideoGrant.new(roomJoin: true, room: "myroom", canPublish: false)) jwt = token.to_jwt decoded = JWT.decode(jwt, TEST_SECRET, true, algorithm: "HS256") diff --git a/spec/livekit/token_verifier_spec.rb b/spec/livekit/token_verifier_spec.rb index 148dc76..4ba1ec8 100644 --- a/spec/livekit/token_verifier_spec.rb +++ b/spec/livekit/token_verifier_spec.rb @@ -5,7 +5,7 @@ token = LiveKit::AccessToken.new(api_key: TEST_KEY, api_secret: TEST_SECRET, identity: "user") token.name = "name" - token.add_grant LiveKit::VideoGrant.new(roomJoin: true, room: "testroom") + token.set_video_grant LiveKit::VideoGrant.new(roomJoin: true, room: "testroom") jwt = token.to_jwt v = described_class.new(api_key: TEST_KEY, api_secret: TEST_SECRET) grant = v.verify(jwt) @@ -18,7 +18,7 @@ it "fails on expired tokens" do token = LiveKit::AccessToken.new(api_key: TEST_KEY, api_secret: TEST_SECRET, identity: "test_identity", ttl: -10) - token.add_grant(LiveKit::VideoGrant.new(roomJoin: true)) + token.set_video_grant(LiveKit::VideoGrant.new(roomJoin: true)) jwt = token.to_jwt v = described_class.new(api_key: TEST_KEY, api_secret: TEST_SECRET) @@ -28,7 +28,7 @@ it "fails on invalid secret" do token = LiveKit::AccessToken.new(api_key: TEST_KEY, api_secret: TEST_SECRET, identity: "test_identity") - token.add_grant(LiveKit::VideoGrant.new(roomJoin: true)) + token.set_video_grant(LiveKit::VideoGrant.new(roomJoin: true)) jwt = token.to_jwt v = described_class.new(api_key: TEST_KEY, api_secret: "wrong-secret") @@ -38,7 +38,7 @@ it "fails on invalid api-key" do token = LiveKit::AccessToken.new(api_key: TEST_KEY, api_secret: TEST_SECRET, identity: "test_identity") - token.add_grant(LiveKit::VideoGrant.new(roomJoin: true)) + token.set_video_grant(LiveKit::VideoGrant.new(roomJoin: true)) jwt = token.to_jwt v = described_class.new(api_key: "wrong key", api_secret: TEST_SECRET)