github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/auth/HttpBearerAuth.mustache (about) 1 {{>licenseInfo}} 2 3 package {{invokerPackage}}.auth; 4 5 import {{invokerPackage}}.Pair; 6 7 import java.util.Map; 8 import java.util.List; 9 10 {{>generatedAnnotation}} 11 public class HttpBearerAuth implements Authentication { 12 private final String scheme; 13 private String bearerToken; 14 15 public HttpBearerAuth(String scheme) { 16 this.scheme = scheme; 17 } 18 19 /** 20 * Gets the token, which together with the scheme, will be sent as the value of the Authorization header. 21 * 22 * @return The bearer token 23 */ 24 public String getBearerToken() { 25 return bearerToken; 26 } 27 28 /** 29 * Sets the token, which together with the scheme, will be sent as the value of the Authorization header. 30 * 31 * @param bearerToken The bearer token to send in the Authorization header 32 */ 33 public void setBearerToken(String bearerToken) { 34 this.bearerToken = bearerToken; 35 } 36 37 @Override 38 public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) { 39 if(bearerToken == null) { 40 return; 41 } 42 43 headerParams.put("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken); 44 } 45 46 private static String upperCaseBearer(String scheme) { 47 return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme; 48 } 49 }