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

Incorrect syntax near keyword IS when using tables for private keys #908

Open camerow opened 6 years ago

camerow commented 6 years ago

I ran into this issue trying to create a small sandbox using OAuth2 at work. I'm using the bones of the Getting Started code:

$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));

// Pass a storage object or array of storage objects to the OAuth2 server class
$server = new OAuth2\Server(
    $storage,
    [
        'allow_implicit' => true,
        'use_openid_connect' => true,
        'always_issue_new_refresh_token' => true,
        'issuer' => $_SERVER['HTTP_HOST']
    ]
);

// Add the "Client Credentials" grant type (it is the simplest of the grant types)
$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
$server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, [
    'always_issue_new_refresh_token' => true
]));
$server->addStorage($storage, 'public_key');

$request = OAuth2\Request::createFromGlobals();
$response = new OAuth2\Response();
$response = $server->handleAuthorizeRequest($request, $response, true);

Using the default Pdo class yields the following error.

Incorrect syntax near the keyword 'IS'.' in D:\home\site\wwwroot\vendor\bshaffer\oauth2-server-php\src\OAuth2\Storage\Pdo.php:619

The query is SELECT private_key FROM dbo.oauth_public_keys WHERE client_id='SOME_CLIENT_ID' OR client_id IS NULL ORDER BY client_id IS NOT NULL DESC and I was able to solve it by removing IS NOT NULL

https://github.com/bshaffer/oauth2-server-php/blob/061f81496dbe52fc0514c1642b366eac1b125310/src/OAuth2/Storage/Pdo.php#L617

TheArtOfPour commented 6 years ago

Mind if I take a look?

TheArtOfPour commented 6 years ago

PR up https://github.com/bshaffer/oauth2-server-php/pull/911