#gRPC Client - Adding Dynamic Authorization Header

5 messages · Page 1 of 1 (latest)

terse night
#

Hi All,

I have a simple NestJS Client implementation of to an gRPC service, however this service requires a JWT to authorize the requests being made. The JWT will change based on who is making the request due to changing authorities with in the JWT. This is a Service (NestJS Microservice) to Service (SpringBoot Microservice) request.

As it stands I have connection to the Service when calling the NestJS Endpont, but the client is being rejected as there is no Bearer Token in the gRPC request. Can anyone clarify how I am supposed to pass this to the server via the client gRPC call?

POC Service Example:

export class GrpcPocService implements OnModuleInit {
  private merchantRegistrarService: MerchantRegistrarService

  constructor(
    @Inject('MERCHANT_REGISTRAR_PACKAGE')
    private readonly grpcClient: ClientGrpc
  ) {}

  onModuleInit() {
    this.merchantRegistrarService =
      this.grpcClient.getService<MerchantRegistrarService>(
        'MerchantRegistrarService'
      )
  }

  getPaymentRules(token: string): Observable<PaymentRulesResponse> {
    const metaData = new grpc.Metadata()
    metaData.add('Content-Type', 'application/grpc')
    metaData.add('Authorization', `Bearer ${token}`)

    console.debug(metaData)
    console.debug(this.merchantRegistrarService)

    return this.merchantRegistrarService.getPaymentRules({}, metaData)
  }
}```

As you can see I am trying to add metaData, but how do I add this to the client before making the gRPC service request?
terse night
#

Points to note: I have no control over the Spring Service and must remain secure

dense basin
#

How you solved this issue, if yes how?

#

I also need to add JWT tokens to the request.

dense basin