Skip to content

Commit

Permalink
updating usage to be explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzhao committed Oct 29, 2024
1 parent c75c6d0 commit 4080370
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/livekit/access_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/livekit/auth_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions spec/livekit/access_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions spec/livekit/token_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 4080370

Please sign in to comment.