Module: LiveKit::AuthMixin
- Included in:
- AgentDispatchServiceClient, ConnectorServiceClient, EgressServiceClient, IngressServiceClient, RoomServiceClient, SIPServiceClient
- Defined in:
- lib/livekit/auth_mixin.rb
Overview
Shared behavior for the Twirp-based service clients: builds authenticated request headers and issues RPCs that raise on error.
Instance Method Summary collapse
-
#auth_header(video_grant: nil, sip_grant: nil) ⇒ Object
Builds request headers.
-
#rpc!(rpc_method, input, headers:) ⇒ Object
Issues a Twirp RPC and returns the response message, raising a ServerError (or SipCallError) on failure.
Instance Method Details
#auth_header(video_grant: nil, sip_grant: nil) ⇒ Object
Builds request headers. When a pre-signed token is set it is sent verbatim (the caller is responsible for its grants); otherwise a token is signed per call from the API key and secret.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/livekit/auth_mixin.rb', line 12 def auth_header( video_grant: nil, sip_grant: nil ) headers = {} if @token headers["Authorization"] = "Bearer #{@token}" return headers end t = ::LiveKit::AccessToken.new(api_key: @api_key, api_secret: @api_secret) t.video_grant = video_grant if video_grant != nil t.sip_grant = sip_grant if sip_grant != nil headers["Authorization"] = "Bearer #{t.to_jwt}" headers end |
#rpc!(rpc_method, input, headers:) ⇒ Object
Issues a Twirp RPC and returns the response message, raising a ServerError (or SipCallError) on failure.
31 32 33 34 35 36 |
# File 'lib/livekit/auth_mixin.rb', line 31 def rpc!(rpc_method, input, headers:) resp = rpc(rpc_method, input, headers: headers) raise ::LiveKit::ServerError.from(resp.error) if resp.error resp.data end |