ubicloud/routes/helpers/runtime.rb
Jeremy Evans 611e64c4a3 Rename get_jwt_payload to get_runtime_jwt_payload
This is a runtime-specific method, and it's best if the method
name reflects that.

While here, remove the argument, as it isn't needed, since the
request method returns the request.
2024-11-05 10:47:00 -08:00

12 lines
335 B
Ruby

# frozen_string_literal: true
class Clover < Roda
def get_runtime_jwt_payload
return unless (v = request.env["HTTP_AUTHORIZATION"])
jwt_token = v.sub(%r{\ABearer:?\s+}, "")
begin
JWT.decode(jwt_token, Config.clover_runtime_token_secret, true, {algorithm: "HS256"})[0]
rescue JWT::DecodeError
end
end
end