Added helper method for "Bearer token" direct use

This commit is contained in:
Mauro Mugnaini 2020-08-18 12:40:53 +02:00
parent bb3728c421
commit 9dd3f3843e
1 changed files with 6 additions and 3 deletions

View File

@ -207,6 +207,10 @@ public class OpenIdConnectRESTHelper {
} }
public static byte[] getUserAvatar(URL avatarURL, JWTToken token) { public static byte[] getUserAvatar(URL avatarURL, JWTToken token) {
return getUserAvatar(avatarURL, token != null ? token.getAccessTokenAsBearer() : null);
}
public static byte[] getUserAvatar(URL avatarURL, String authorization) {
logger.debug("Getting user avatar from URL: {}", avatarURL); logger.debug("Getting user avatar from URL: {}", avatarURL);
ByteArrayOutputStream buffer; ByteArrayOutputStream buffer;
try { try {
@ -214,9 +218,8 @@ public class OpenIdConnectRESTHelper {
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
conn.setDoOutput(false); conn.setDoOutput(false);
conn.setDoInput(true); conn.setDoInput(true);
conn.setRequestProperty("Accept", "image/png, image/jpeg, image/gif"); conn.setRequestProperty("Accept", "image/png, image/gif");
if (token != null) { if (authorization != null) {
String authorization = token.getAccessTokenAsBearer();
logger.debug("Adding authorization header as: {}", authorization); logger.debug("Adding authorization header as: {}", authorization);
conn.setRequestProperty("Authorization", authorization); conn.setRequestProperty("Authorization", authorization);
} }