Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client credential grant type is not properly sent with Apache Oltu client library?

I tried to implement an OAuth client using OAuthClientRequest in Apache Oltu. And it seems to be that it is sending client credentials in the message body not in the Basic Auth headers according to the spec. I am not sure, I may have missed some thing in the code.

Code

OAuthClientRequest.tokenLocation("http://localhost:8081/token")
                .setGrantType(GrantType.CLIENT_CREDENTIALS)
                .setClientId(clientKey)
                .setClientSecret(clientSecret)
                .buildBodyMessage();

Request

POST /token HTTP/1.1 Content-Type: application/x-www-form-urlencoded Cache-Control: no-cache Pragma: no-cache User-Agent: Java/1.6.0_29 Host: 127.0.0.1:8081 Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2 Connection: keep-alive Content-Length: 127

client_secret=f921854d-f70b-4180-9fdd-3a55032103cc&grant_type=client_credentials&client_id=3f3b4092-7576-4b26-8135-980db7864c2

like image 800
Asela Avatar asked Jan 18 '26 13:01

Asela


2 Answers

You might want to change buildBodyMessage() with buildQueryMessage()

like image 99
Antonio Sanso Avatar answered Jan 21 '26 08:01

Antonio Sanso


The OAuth2 Bearer Token specification defines three methods of sending bearer access tokens:

  • Authorization Request Header Field
  • Form-Encoded Body Parameter
  • URI Query Parameter

The method buildBodyMessage() will create a request with a Form-Encoded Body Parameter. You need to use buildHeaderMessage() instead, which is also the recommended method by the specification.

like image 41
Christian Strempfer Avatar answered Jan 21 '26 09:01

Christian Strempfer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!