KaiRo bug 412 - Use composer to load oauth2-server-php and doctrine DBAL
[authserver.git] / app / server.inc.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
133aecbe 8// $dbata needs to be set and be an associative array with the members 'dsn', 'username', and 'password'.
e6624d81 9
e6624d81 10// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
ea0452ad
RK
11$oauth2_storage = new OAuth2\Storage\Pdo($dbdata);
12
13// Set configuration
14$oauth2_config = array(
15 'require_exact_redirect_uri' => false,
16 'always_issue_new_refresh_token' => true, // Needs to be handed below as well as there it's not constructed from within the server object.
17 'refresh_token_lifetime' => 90*24*3600,
18);
e6624d81
RK
19
20// Pass a storage object or array of storage objects to the OAuth2 server class
ea0452ad 21$server = new OAuth2\Server($oauth2_storage, $oauth2_config);
e6624d81
RK
22
23// Add the "Client Credentials" grant type (it is the simplest of the grant types)
ea0452ad 24//$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
e6624d81
RK
25
26// Add the "Authorization Code" grant type (this is where the oauth magic happens)
ea0452ad
RK
27$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($oauth2_storage));
28
29// Add the "Refresh Token" grant type (required to get longer-living resource access by generating new access tokens)
30$server->addGrantType(new OAuth2\GrantType\RefreshToken($oauth2_storage, array('always_issue_new_refresh_token' => true)));
e6624d81
RK
31
32?>