add example files to auth server
[authserver.git] / server.php
CommitLineData
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
8$dsn = 'mysql:dbname=kairo_at_auth;host=localhost';
9$username = 'kairo_at_auth';
10$password = '6z0KIuUsHJhgD5rB';
11
12// error reporting (this is a demo, after all!)
13ini_set('display_errors',1);error_reporting(E_ALL);
14
15// Autoloading (composer is preferred, but for this example let's just do this)
16require_once('../oauth2-server-php/src/OAuth2/Autoloader.php');
17OAuth2\Autoloader::register();
18
19// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
20$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
21
22// Pass a storage object or array of storage objects to the OAuth2 server class
23$server = new OAuth2\Server($storage);
24
25// Add the "Client Credentials" grant type (it is the simplest of the grant types)
26$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
27
28// Add the "Authorization Code" grant type (this is where the oauth magic happens)
29$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
30
31?>