code: public UserInfo authenticate(
        HttpServletRequest httpServletRequest,
        AuthInfo authInfo,
        String serviceName) {
  
      Preconditions.checkNotNull(httpServletRequest);
      Preconditions.checkNotNull(authInfo);
  
      Optional<String> maybeAuthToken = extractAuthToken(httpServletRequest);
      if (!maybeAuthToken.isPresent()) {
        throw new UnauthenticatedException(
            "No auth token is contained in the HTTP request");
      }
  
      JwtClaims jwtClaims = this.authTokenDecoder.decode(maybeAuthToken.get());
      UserInfo userInfo = toUserInfo(jwtClaims);
      String issuer = userInfo.getIssuer();
  
      if (!this.issuersToProviderIds.containsKey(issuer)) {
        throw new UnauthenticatedException("Unknown issuer: " + issuer);
      }
      String providerId = this.issuersToProviderIds.get(issuer);
  
      // Check whether the provider id is allowed.
      if (!authInfo.isProviderIdAllowed(providerId)) {
        String message = "The requested method does not allowed this provider id: " + providerId;
        throw new UnauthenticatedException(message);
      }
  
      checkJwtClaims(jwtClaims);
  
      // Check the audiences decoded from the auth token. The auth token is allowed when
      // 1) an audience is equal to the service name,
      // or 2) at least one audience is allowed in the method configuration.
      Set<String> audiences = userInfo.getAudiences();
      boolean hasServiceName = audiences.contains(serviceName);
      Set<String> allowedAudiences = authInfo.getAudiencesForProvider(providerId);
      if (!hasServiceName && Sets.intersection(audiences, allowedAudiences).isEmpty()) {
        throw new UnauthenticatedException("Audiences not allowed");
      }
  
      return userInfo;
    }
docs: Authenticate the current HTTP request.
  
  @param httpServletRequest is the incoming HTTP request object.
  @param authInfo contains authentication configurations of the API method being called.
  @param serviceName is the name of this service.
  @return a constructed {@link UserInfo} object representing the identity of the caller.