Class: StatelyDB::Common::Auth::Interceptor

Inherits:
GRPC::ClientInterceptor
  • Object
show all
Defined in:
lib/common/auth/interceptor.rb

Overview

GRPC interceptor to authenticate against Stately and append bearer tokens to outgoing requests

Instance Method Summary collapse

Constructor Details

#initialize(token_provider: Auth0TokenProvider.new) ⇒ Interceptor

Returns a new instance of Interceptor.

Parameters:

  • token_provider (TokenProvider) (defaults to: Auth0TokenProvider.new)

    The token provider to use for authentication



13
14
15
16
17
18
# File 'lib/common/auth/interceptor.rb', line 13

def initialize(
  token_provider: Auth0TokenProvider.new
)
  super()
  @token_provider = token_provider
end

Instance Method Details

#add_jwt_to_grpc_request(metadata:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Adds a JWT to the metadata hash

Parameters:

  • metadata (Hash)

    The metadata hash



76
77
78
# File 'lib/common/auth/interceptor.rb', line 76

def add_jwt_to_grpc_request(metadata:)
  ["authorization"] = "Bearer #{@token_provider.get_token}"
end

#bidi_streamer(requests:, call:, method:, metadata:) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC bidirectional streaming interceptor

Parameters:

  • requests (Enumerable)

    The list of requests

  • call (GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Enumerator)

    The response enumerator



67
68
69
70
# File 'lib/common/auth/interceptor.rb', line 67

def bidi_streamer(requests:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end

#client_streamer(requests:, call:, method:, metadata:) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC client streaming interceptor

Parameters:

  • requests (Enumerable)

    The list of requests

  • call (GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Enumerator)

    The response enumerator



41
42
43
44
# File 'lib/common/auth/interceptor.rb', line 41

def client_streamer(requests:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end

#request_response(request:, call:, method:, metadata:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC client unary interceptor

Parameters:

  • request (Object)

    The request object

  • call (GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Object)

    The response object



28
29
30
31
# File 'lib/common/auth/interceptor.rb', line 28

def request_response(request:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end

#server_streamer(request:, call:, method:, metadata:) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC server streaming interceptor

Parameters:

  • request (Object)

    The request object

  • call (GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Enumerator)

    The response enumerator



54
55
56
57
# File 'lib/common/auth/interceptor.rb', line 54

def server_streamer(request:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end