Skip to content

Commit

Permalink
feat: bearer (refs #111)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 30, 2021
1 parent 9cb1ff1 commit 0e0fb52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RestClient {
private static RestClient mockedRestClient;
private final Map<String, Optional<String>> urlCache = new ConcurrentHashMap<>();
private String basicAuthString;

private String bearer;
private Map<String, String> headers;

public RestClient() {}
Expand All @@ -40,6 +40,11 @@ public RestClient withTokenAuthCredentials(final String token) {
return this;
}

public RestClient withBearer(final String bearer) {
this.bearer = bearer;
return this;
}

public RestClient withHeaders(final Map<String, String> headers) {
this.headers = headers;
return this;
Expand Down Expand Up @@ -71,7 +76,9 @@ private Optional<String> doGet(final String urlParam) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
}
}
if (this.basicAuthString != null) {
if (this.bearer != null) {
conn.setRequestProperty("Authorization", "Bearer " + this.bearer);
} else if (this.basicAuthString != null) {
conn.setRequestProperty("Authorization", "Basic " + this.basicAuthString);
}
return Optional.of(this.getResponse(conn));
Expand Down

0 comments on commit 0e0fb52

Please # to comment.