Example #1
0
 /**
  * Authentication function
  * Validates and parses incoming token, and returns its payload
  *
  * To be used as a dispatcher authentication, like this:
  *
  * // Authenticate token in every request
  * Server::resource("*", [
  *     "any" => [
  *         "authentication" => "Phidias\Oauth\Controller::authenticate({request})"
  *     ]
  * ]);
  *
  */
 public static function authenticate($request)
 {
     if ($request->hasHeader("authorization")) {
         list($authorizationMethod, $authorizationCredentials) = explode(" ", $request->getHeader("authorization")[0], 2);
         switch (strtolower($authorizationMethod)) {
             case "bearer":
                 Token::load(trim($authorizationCredentials));
                 return Token::getPayload();
                 break;
         }
     }
 }
Example #2
0
<?php

use Phidias\Oauth\Token;
use Phidias\Utilities\Configuration;
Token::setSecret(Configuration::get("phidias.oauth.secret"));