wide-dream-9658
02/14/2024, 2:44 PMgetOAuth2ConsentRequest
method of the Hydra Java client (v2.2.0).
To authenticate I created an API Key in the Ory Console and this key works when accessing the Ory REST API with Postman.
But when using the Java SDK the authentication does not work and the following sample code results in a 401: Access credentials are invalid
.
public static void main(String[] args) {
var basePath = "<https://my-customer-domain.net>";
var apiKey = "ory_pat_******";
var consentChallenge = "some-challenge";
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath(basePath);
defaultClient.setBearerToken(apiKey);
OAuth2Api apiInstance = new OAuth2Api(defaultClient);
try {
OAuth2ConsentRequest result = apiInstance.getOAuth2ConsentRequest(consentChallenge);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling OAuth2Api#getOAuth2ConsentRequest");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
After some debugging I saw that it seems that the authentication defined in the ApiClient
by defaultClient.setBearerToken(apiKey)
is not used by `OAuth2Api.getOAuth2ConsentRequestCall()`and thus the Authentication header is not set in the HTTP request.
Did I miss something or is this simply a bug?
Any help is appreciated
Klausrefined-kangaroo-48640
02/14/2024, 4:47 PMrefined-kangaroo-48640
02/14/2024, 4:47 PMwide-dream-9658
02/14/2024, 5:41 PMhttps://<my-custom-domain>/admin/oauth2/auth/requests/consent
Any ideas?wide-dream-9658
02/14/2024, 5:46 PMcurl -H "Authorization: Bearer ory_pat_****" https://<my-custom-domain>/admin/oauth2/auth/requests/consent?consent_challenge=x
results in :
{“error”:“Not Found”,“error_description”:“Unable to locate the requested resource”}wide-dream-9658
02/14/2024, 5:58 PMrefined-kangaroo-48640
02/14/2024, 9:03 PM