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 951 forks source link

how to pass the token ?? I'm getting following error #527

Open stestrepo opened 9 years ago

stestrepo commented 9 years ago

I've used the sample lib from server-docs-php

C:>curl -u testclient:testpass http://localhost/OAuth2/token.php -d 'grant_type =authorization_code'
Fatal error: Interface 'OAuth2\Controller\ResourceControllerInterface' n ot found in C:\xampp\htdocs\OAuth2\server.php on line 43

bshaffer commented 9 years ago

Post your code in server.php here. I'm guessing you forgot to include the autoloader file.

stestrepo commented 9 years ago

<?php

$dsn = 'mysql:dbname=oauth_db;host=localhost'; $username = 'sayalig'; $password = '234';

// error reporting (this is a demo, after all!) ini_set('display_errors',1);error_reporting(E_ALL);

// Autoloading (composer is preferred, but for this example let's just do this) require_once('C:\xampp\htdocs\OAuth2\Autoloader.php'); OAuth2\Autoloader::register();

// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost" $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);

// 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));

?>

stestrepo commented 9 years ago

Can u tell me from while file is authorization code to be passed to whom (eg i'm passing it after the user approves of client accessing its resources with server.) is it right ???

bshaffer commented 9 years ago

@soauth I cannot understand your question, but the second part sounds right (you pass the code to the token.php endpoint after the user approves the client).

does the file C:\xampp\htdocs\OAuth2\Controller\ResourceControllerInterface.php exist on your machine?

stestrepo commented 9 years ago

yes

bshaffer commented 9 years ago

Oh, it's because you're on a windows machine, and the directory separators are different.

We can either correct this in a pull request, or you can run composer.phar install and then include __DIR__.'\..\vendor\autoload.php instead.

(where __dir__.'\..\ points to the root of your project)