Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PATH
livekit-server-sdk (1.0.0)
faraday (>= 2.0, < 3.0)
google-protobuf (~> 4.30, >= 4.30.2)
jwt (>= 2.2.3, < 3.0)
jwt (>= 2.3.0, < 3.0)
twirp (~> 1.13, >= 1.13.1)

GEM
Expand Down
10 changes: 9 additions & 1 deletion lib/livekit/token_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ def initialize(api_key: nil, api_secret: nil)
end

def verify(token)
decoded_token = JWT.decode(token, @api_secret, true, algorithm: AccessToken::SIGNING_ALGORITHM)
decoded_token = JWT.decode(
token,
@api_secret,
true,
{
algorithm: AccessToken::SIGNING_ALGORITHM,
required_claims: ["exp"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required_claims landed in ruby-jwt v2.3.0 - Gemfile.lock needs to bump the minimum from v2.2.3

},
)
decoded = decoded_token.first
if decoded["iss"] != @api_key
raise "Invalid issuer"
Expand Down
2 changes: 1 addition & 1 deletion livekit_server_sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "faraday", ">= 2.0", "< 3.0"
spec.add_dependency "google-protobuf", "~> 4.30", ">= 4.30.2"
spec.add_dependency "jwt", ">= 2.2.3", "< 3.0"
spec.add_dependency "jwt", ">= 2.3.0", "< 3.0"
spec.add_dependency "twirp", "~> 1.13", ">= 1.13.1"

# For more information and examples about making a new gem, checkout our
Expand Down
12 changes: 12 additions & 0 deletions spec/livekit/token_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
expect(grant.attributes["mykey"]).to eq("myvalue")
end

it "fails when exp is missing" do
payload = {
"iss" => TEST_KEY,
"sub" => "user",
"nbf" => Time.now.to_i - 5,
"video" => { "roomJoin" => true, "room" => "testroom" },
}
jwt = JWT.encode(payload, TEST_SECRET, "HS256")
v = described_class.new(api_key: TEST_KEY, api_secret: TEST_SECRET)
expect { v.verify(jwt) }.to raise_error(JWT::MissingRequiredClaim)
end

it "fails on expired tokens" do
token = LiveKit::AccessToken.new(api_key: TEST_KEY, api_secret: TEST_SECRET,
identity: "test_identity", ttl: -10)
Expand Down
Loading