Package s2.auth

Class 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
      BearerTokenCallCredentials​(java.lang.String token)
      Creates new bearer token credentials.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyRequestMetadata​(io.grpc.CallCredentials.RequestInfo requestInfo, java.util.concurrent.Executor executor, io.grpc.CallCredentials.MetadataApplier metadataApplier)
      Applies the bearer token to the request metadata.
      boolean equals​(java.lang.Object other)
      Returns whether this credentials implementation is equal to another object.
      int hashCode()
      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 Detail

      • BearerTokenCallCredentials

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

      • applyRequestMetadata

        public void applyRequestMetadata​(io.grpc.CallCredentials.RequestInfo requestInfo,
                                         java.util.concurrent.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 java.lang.Object
        Returns:
        A hash code value for this object
      • equals

        public boolean equals​(java.lang.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 java.lang.Object
        Parameters:
        other - The object to compare with
        Returns:
        true if the objects are equal, false otherwise