Search code examples
phpzend-framework2oauth-2.0laminas-api-tools

Why am I getting error when I use Postman and oauth2 for login access case in apiagility?


I am new to Zend Framework 2. I am trying to get the login access scenario working with Postman (chrome extension). I have gone through the forum but I'm not sure if I'm missing something or not. So here are the steps that I have taken so far: In MYSQL I have set up the tables accordingly and there is a user with the following fields in the oauth_clients table:

  • client_id : testclient
  • client_secret : testpass
  • redirect_uri : /oauth/receivecode (I'm not sure about the value of this one could someone please shed some light on this?)
  • grant_type : password ( I want to use the service for authentication and authorization to access a website or login access scenario)

The rest of the fields are NULL. No other entries in other tables. I set the parameters in Postman like this:

  • Authorization : Oauth2

Headers:

  • Accept : application/json
  • Content-Type : application/json

The raw body is like:

{
    "client_id":"testclient",
    "client_secret":"testpass",
    "grant_type":"password"
}

I post the request to: www.dummy.dev/oauth/authorize

When I post the request this is what I get:

{
  "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
  "title": "invalid_request",
  "status": 302,
  "detail": "Invalid or missing response type"
}

Why do I get this error message?


Solution

  • redirect uri is not necessary and could be left null in the database as well. The correct uri to POST is www.dummy.dev/oauth and the raw parameters in Postman are:

    {
        "client_id":"dev.dummy",
        "username":"testclient",
        "password":"testpass",
        "grant_type":"password"
    }
    

    The value of password is stored and encoded (with bcrypt) in the database. client_id and client_secret are not important in this scenario as my own website is the client of my API.