also put piwik tracking into token request
[authserver.git] / app / token.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
77f0f9ff
RK
6// Called with e.g. curl .../token -d 'grant_type=authorization_code&client_id=testclient&client_secret=testpass&code=&state=f00bar&redirect_uri=http%3A%2F%2Ffake.example.com%2F'
7// Response is always JSON.
e6624d81 8
133aecbe
RK
9// Include the common auth system files (including the OAuth2 Server object).
10require_once(__DIR__.'/authsystem.inc.php');
6b4b2661
RK
11if ($settings['piwik_enabled']) {
12 // We do not send out an HTML file, so we need to do the Piwik tracking ourselves.
13 require_once($settings['piwik_tracker_path'].'PiwikTracker.php');
14 PiwikTracker::$URL = ((strpos($settings['piwik_url'], '://') === false) ? 'http://localhost' : '' ).$settings['piwik_url'];
15 $piwikTracker = new PiwikTracker($idSite = $settings['piwik_site_id']);
16 $piwikTracker->doTrackPageView('Token Request');
17}
e6624d81 18
b21c0933 19$errors = $utils->checkForSecureConnection();
e6624d81 20
b21c0933
RK
21if (!count($errors)) {
22 // Handle a request for an OAuth2.0 Access Token and send the response to the client
23 $server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
24}
25else {
26 print(json_encode(array('error' => 'insecure_connection',
27 'error_description' => 'Your connection is insecure. Token requests can only be made on secure connections.')));
28}
e6624d81 29?>