Package s2.auth

Class BearerTokenCallCredentials

java.lang.Object
io.grpc.CallCredentials
s2.auth.BearerTokenCallCredentials

public class BearerTokenCallCredentials extends io.grpc.CallCredentials
Implementation of CallCredentials that adds a bearer token to request metadata. This class is used to authenticate gRPC requests using a bearer token in the Authorization header with the "Bearer" scheme.
  • Nested Class Summary

    Nested classes/interfaces inherited from class io.grpc.CallCredentials

    io.grpc.CallCredentials.MetadataApplier, io.grpc.CallCredentials.RequestInfo
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates new bearer token credentials.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyRequestMetadata(io.grpc.CallCredentials.RequestInfo requestInfo, Executor executor, io.grpc.CallCredentials.MetadataApplier metadataApplier)
    Applies the bearer token to the request metadata.
    boolean
    equals(Object other)
    Returns whether this credentials implementation is equal to another object.
    int
    Returns a hash code value for this credentials implementation.

    Methods inherited from class io.grpc.CallCredentials

    thisUsesUnstableApi

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BearerTokenCallCredentials

      public BearerTokenCallCredentials(String token)
      Creates new bearer token credentials.
      Parameters:
      token - The bearer token to use for authentication
      Throws:
      IllegalArgumentException - if token is null or empty
  • Method Details

    • applyRequestMetadata

      public void applyRequestMetadata(io.grpc.CallCredentials.RequestInfo requestInfo, Executor executor, io.grpc.CallCredentials.MetadataApplier metadataApplier)
      Applies the bearer token to the request metadata. This method is called by the gRPC framework before each request.
      Specified by:
      applyRequestMetadata in class io.grpc.CallCredentials
      Parameters:
      requestInfo - Information about the RPC being called
      executor - The executor to use for any asynchronous operations
      metadataApplier - Interface for applying the resulting metadata
    • hashCode

      public int hashCode()
      Returns a hash code value for this credentials implementation.
      Overrides:
      hashCode in class Object
      Returns:
      A hash code value for this object
    • equals

      public boolean equals(Object other)
      Returns whether this credentials implementation is equal to another object. Two BearerTokenCallCredentials are equal if they have the same token.
      Overrides:
      equals in class Object
      Parameters:
      other - The object to compare with
      Returns:
      true if the objects are equal, false otherwise