Skip to content

Commit

Permalink
add vertx-specific HttpBearerAuth template and samples
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwcarlson committed Jan 31, 2019
1 parent fb46ef2 commit 485a738
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{>licenseInfo}}

package {{invokerPackage}}.auth;

import {{invokerPackage}}.Pair;
import io.vertx.core.MultiMap;
import java.util.Base64;
import java.nio.charset.StandardCharsets;
import java.util.List;

{{>generatedAnnotation}}
public class HttpBearerAuth implements Authentication {
private final String scheme;
private String bearerToken;
public HttpBearerAuth(String scheme) {
this.scheme = scheme;
}

public String getBearerToken() {
return bearerToken;
}

public void setBearerToken(String bearerToken) {
this.bearerToken = bearerToken;
}

@Override
public void applyToParams(List<Pair> queryParams, MultiMap headerParams) {
if (bearerToken == null) {
return;
}
headerParams.add("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
}

private static String upperCaseBearer(String scheme) {
return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
package org.openapitools.client.auth;

import org.openapitools.client.Pair;

import java.util.Map;
import io.vertx.core.MultiMap;
import java.util.Base64;
import java.nio.charset.StandardCharsets;
import java.util.List;


Expand All @@ -27,27 +28,20 @@ public HttpBearerAuth(String scheme) {
this.scheme = scheme;
}

/**
* Gets the token, which together with the scheme, will be sent as the value of the Authorization header.
*/
public String getBearerToken() {
return bearerToken;
}

/**
* Sets the token, which together with the scheme, will be sent as the value of the Authorization header.
*/
public void setBearerToken(String bearerToken) {
this.bearerToken = bearerToken;
}

@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if(bearerToken == null) {
public void applyToParams(List<Pair> queryParams, MultiMap headerParams) {
if (bearerToken == null) {
return;
}

headerParams.put("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
headerParams.add("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
}

private static String upperCaseBearer(String scheme) {
Expand Down

0 comments on commit 485a738

Please sign in to comment.