-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add vertx-specific HttpBearerAuth template and samples
- Loading branch information
1 parent
fb46ef2
commit 485a738
Showing
2 changed files
with
45 additions
and
12 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...es/openapi-generator/src/main/resources/Java/libraries/vertx/auth/HttpBearerAuth.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters