Aklakan commented on issue #1292:
URL: https://github.com/apache/jena/issues/1292#issuecomment-1116569668
Hi Andy, thanks alot - the snippet below works:
```java
String bearerToken = "SECRET";
HttpRequestModifier modifier = (params, headers) -> {
headers.put("Authorization", "Bearer " + bearerToken);
};
RegistryRequestModifier.get().add(url, modifier);
```
However, there is a minor follow up issue:
If the bearer token times out, then first a message is logged such as:
```
Bearer error="invalid_token", error_description="An error occurred while
attempting to decode the Jwt: Jwt expired at 2022-05-03T20:22:50Z",
error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"
```
but then it causes a non-ideal NPE in AuthLib.authenticateHeader:
```java
public class AuthLib {
private static AuthChallenge authenticateHeader(HttpResponse<?>
httpResponse) {
List<String> headers =
httpResponse.headers().allValues("WWW-Authenticate");
if ( headers.size() == 0 )
return null;
// Choose first digest or first basic.
AuthChallenge aHeader = null;
String result = null;
for ( String headerValue : headers ) {
AuthChallenge aHeader2 = AuthChallenge.parse(headerValue);
if ( aHeader2 == null )
AuthEnv.LOG.warn("Bad authentication response - ignored:
"+headerValue);
// Prefer Digest
switch(aHeader2.authScheme) { // BUG: If aHeader2 is null we get
both a log message but here it raises an NPE
case DIGEST :
return aHeader2;
case BASIC:
...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]