Class: StatelyDB::Common::Auth::Interceptor
- Inherits:
-
GRPC::ClientInterceptor
- Object
- GRPC::ClientInterceptor
- StatelyDB::Common::Auth::Interceptor
- 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
-
#add_jwt_to_grpc_request(metadata:) ⇒ void
private
Adds a JWT to the metadata hash.
-
#bidi_streamer(requests:, call:, method:, metadata:) ⇒ Enumerator
private
gRPC bidirectional streaming interceptor.
-
#client_streamer(requests:, call:, method:, metadata:) ⇒ Enumerator
private
gRPC client streaming interceptor.
-
#initialize(token_provider: Auth0TokenProvider.new) ⇒ Interceptor
constructor
A new instance of Interceptor.
-
#request_response(request:, call:, method:, metadata:) ⇒ Object
private
gRPC client unary interceptor.
-
#server_streamer(request:, call:, method:, metadata:) ⇒ Enumerator
private
gRPC server streaming interceptor.
Constructor Details
#initialize(token_provider: Auth0TokenProvider.new) ⇒ Interceptor
Returns a new instance of Interceptor.
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
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
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
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
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
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 |