Skip to content

Commit

Permalink
add java webclient-specific template and samples
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwcarlson committed Jan 31, 2019
1 parent 485a738 commit 1c688a6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package {{invokerPackage}}.auth;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import org.springframework.http.HttpHeaders;
import org.springframework.util.Base64Utils;
import org.springframework.util.MultiValueMap;

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

public String getBearerAuth() {
return bearerAuth;
}

public void setBearerAuth(String bearerAuth) {
this.bearerAuth = bearerAuth;
}

@Override
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams) {
if (bearerToken == null) {
return;
}
headerParams.add(HttpHeaders.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
@@ -1,56 +1,39 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


package org.openapitools.client.auth;

import org.openapitools.client.Pair;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import java.util.Map;
import java.util.List;
import org.springframework.http.HttpHeaders;
import org.springframework.util.Base64Utils;
import org.springframework.util.MultiValueMap;


public class HttpBearerAuth implements Authentication {
private final String scheme;
private String bearerToken;

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) {
return;
private final String scheme;
private String bearerToken;

public HttpBearerAuth(String scheme) {
this.scheme = scheme;
}

public String getBearerAuth() {
return bearerAuth;
}

headerParams.put("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
}
public void setBearerAuth(String bearerAuth) {
this.bearerAuth = bearerAuth;
}

@Override
public void applyToParams(MultiValueMap<String, String> queryParams, HttpHeaders headerParams) {
if (bearerToken == null) {
return;
}
headerParams.add(HttpHeaders.AUTHORIZATION, (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
}

private static String upperCaseBearer(String scheme) {
return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme;
}

private static String upperCaseBearer(String scheme) {
return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme;
}
}

0 comments on commit 1c688a6

Please sign in to comment.