bshaffer / oauth2-server-php

A library for implementing an OAuth2 Server in php
http://bshaffer.github.io/oauth2-server-php-docs
MIT License
3.26k stars 950 forks source link

Unable to obtain access token unless $_POST is replaced by $_REQUEST in Request class constructor #920

Open anaqreon opened 6 years ago

anaqreon commented 6 years ago

I'm using version v1.10.0 (d158878425392fe5a0cc34f15dbaf46315ae0ed9). When I request an authorization token using cURL in PHP, I am unable to succeed unless I change the line in Request.php from https://github.com/bshaffer/oauth2-server-php/blob/89d3745dd6c633358f5ea052cbb5e0b908ffccf2/src/OAuth2/Request.php#L234 to

$request = new $class($_GET, $_REQUEST, array(), $_COOKIE, $_FILES, $_SERVER);

When I review the cURL error log everything appears to be correct (see below). Ultimately the error is issued by TokenController.php but I cannot determine why changing $_POST to $_REQUEST in the createFromGlobals() function is necessary.

Please let me know what other information I can provide to make my problem clearer and easier to troubleshoot. Thanks in advance.

2018-03-03T13:06:55Z:LOG_INFO:jnetekpgv8iefeb1hgd844akl6:Oauth2testvehicle.php:157:post: {
    "return_code": 400,
    "success": false,
    "header": "HTTP\/1.1 400 Bad Request\r\nDate: Sat, 03 Mar 2018 13:06:55 GMT\r\nServer: Apache\/2.4.10 (Debian)\r\nSet-Cookie: PHPSESSID=nvekmesqjbv790pou57gpatu47; path=\/; HttpOnly\r\nExpires: Thu, 19 Nov 1981 08:52:00 GMT\r\nCache-Control: no-store\r\nPragma: no-cache\r\nContent-Length: 97\r\nConnection: close\r\nContent-Type: application\/json\r\n\r\n",
    "body": "{\"error\":\"invalid_request\",\"error_description\":\"The grant type was not specified in the request\"}",
    "error": "",
    "debug": {
        "url": "http:\/\/hub.localhost\/token\/?grant_type=authorization_code&redirect_uri=http%3A%2F%2Fhub.localhost%2Foauth2testvehicle&client_id=oauth2_test_app&code=fd90a6df9bb5d2c0724abbfcf76920b12926496f",
        "content_type": "application\/json",
        "http_code": 400,
        "header_size": 319,
        "request_size": 331,
        "filetime": -1,
        "ssl_verify_result": 0,
        "redirect_count": 0,
        "total_time": 0.021454,
        "namelookup_time": 0.004657,
        "connect_time": 0.004747,
        "pretransfer_time": 0.006769,
        "size_upload": 0,
        "size_download": 97,
        "speed_download": 4521,
        "speed_upload": 0,
        "download_content_length": 97,
        "upload_content_length": -1,
        "starttransfer_time": 0.021422,
        "redirect_time": 0,
        "redirect_url": "",
        "primary_ip": "127.0.0.1",
        "certinfo": [],
        "primary_port": 80,
        "local_ip": "127.0.0.1",
        "local_port": 42301,
        "request_header": "POST \/token\/?grant_type=authorization_code&redirect_uri=http%3A%2F%2Fhub.localhost%2Foauth2testvehicle&client_id=oauth2_test_app&code=fd90a6df9bb5d2c0724abbfcf76920b12926496f HTTP\/1.1\r\nAuthorization: Basic b2F1dGgyX3Rlc3RfYXBwOjExNWM3NWFhYWIzYTU4NzY=\r\nUser-Agent: Mozilla\/5.0 (compatible; zot)\r\nHost: hub.localhost\r\nAccept: *\/*\r\n\r\n"
    }
}
2018-03-03T13:06:55Z:LOG_INFO:jnetekpgv8iefeb1hgd844akl6:Oauth2testvehicle.php:159:post: {
    "error": "invalid_request",
    "error_description": "The grant type was not specified in the request"
}