Commit | Line | Data |
---|---|---|
e6624d81 RK |
1 | <?php |
2 | /* This Source Code Form is subject to the terms of the Mozilla Public | |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
5 | ||
6 | // Simple server based on https://bshaffer.github.io/oauth2-server-php-docs/cookbook | |
7 | ||
133aecbe | 8 | // $dbata needs to be set and be an associative array with the members 'dsn', 'username', and 'password'. |
e6624d81 RK |
9 | |
10 | // Autoloading (composer is preferred, but for this example let's just do this) | |
11 | require_once('../oauth2-server-php/src/OAuth2/Autoloader.php'); | |
12 | OAuth2\Autoloader::register(); | |
13 | ||
14 | // $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost" | |
133aecbe | 15 | $storage = new OAuth2\Storage\Pdo($dbdata); |
e6624d81 RK |
16 | |
17 | // Pass a storage object or array of storage objects to the OAuth2 server class | |
18 | $server = new OAuth2\Server($storage); | |
19 | ||
20 | // Add the "Client Credentials" grant type (it is the simplest of the grant types) | |
21 | $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage)); | |
22 | ||
23 | // Add the "Authorization Code" grant type (this is where the oauth magic happens) | |
24 | $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage)); | |
25 | ||
26 | ?> |