2

Drupal 8. I'm new with simple Oauth. I had manage to do this: enter image description here

But I want to do it with the Raw format, cuz my frontend is in Angular, so I will send a Json to Drupal.

This is my first try:

{
    "grant_type":"password", 
    "client_id":"f011cc58-40ce-43a9-8f71-842494e3a997", 
    "client_secret":"abc123", 
    "username":"test", 
    "password":"test"
}

And this is the response:

{ "error": "invalid_grant", "message": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.", "hint": "Check the configuration to see if the grant is enabled." }

I have set up the Content-type: Application/json but I got the same result.

Any idea??

enter image description here

2
  • Not a structure issue, the error says something to do with your Refresh Token refresh token is invalid, expired, revoked... So you need a new one, I hope this helps Refresh Token Grant
    – No Sssweat
    Commented Apr 5, 2018 at 6:45
  • @NoSssweat But I am working just with the client_id It doesn´t expire. And... the other reason for the error, is the authorization grant
    – ValRob
    Commented Apr 5, 2018 at 12:11

2 Answers 2

0

It will depend if the backend can receive a JSON format.

In my case, I am working with the Drupal 8 Module simple Oauth. and the The format for OAuth 2.0 Bearer tokens is actually described in a separate spec, RFC 6750.

More concrete here

The entity-body follows the encoding requirements of the "application/x-www-form-urlencoded" content-type as defined by HTML 4.01 [W3C.REC-html401-19991224].

So, In my particular case, I will try to send a form-data from angular.

0

You need to stringify your data. To do this install npm package qs, then create object

const data = {
    "grant_type":"password", 
    "client_id":"f011cc58-40ce-43a9-8f71-842494e3a997", 
    "client_secret":"abc123", 
    "username":"test", 
    "password":"test"
}

And use in request

axios.post('oauth/token', qs.stringify(data))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.