-
-
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 java webclient-specific template and samples
- Loading branch information
1 parent
485a738
commit 1c688a6
Showing
2 changed files
with
68 additions
and
46 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...penapi-generator/src/main/resources/Java/libraries/webclient/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 @@ | ||
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; | ||
} | ||
|
||
} |
75 changes: 29 additions & 46 deletions
75
...nt/petstore/java/webclient/src/main/java/org/openapitools/client/auth/HttpBearerAuth.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} |