/** * Gets an access token that will be cached using a file. * * This method works first trying to load the file specified in config, * and, if a saved OAuth token isn't found, this method will send an API * request. The OAuth token will then be saved for future use. * * @return OAuthToken OAuth token that can be used for authorization * @throws OAuthException if API request was not successful or if * there was a file IO issue */ function getFileToken() { $token = OAuthToken::loadToken(OAUTH_FILE); if ($token == null || $token->isAccessTokenExpired()) { $tokenSrvc = new OAuthTokenService(FQDN, CLIENT_ID, CLIENT_SECRET); $token = $tokenSrvc->getTokenUsingScope(SCOPE); // save token for future use $token->saveToken(OAUTH_FILE); } return $token; }
/** * Gets an access token that will be cached using a file. * * This method works first trying to load the file specified in config, * and, if a saved OAuth token isn't found, this method will send an API * request. The OAuth token will then be saved for future use. * * @return OAuthToken OAuth token that can be used for authorization * @throws OAuthException if API request was not successful or if * there was a file IO issue */ function getFileToken() { require __DIR__ . '/../config.php'; // maintain backwards compability with older configs if (isset($api_key)) { $clientId = $api_key; } if (isset($secret_key)) { $clientSecret = $secret_key; } if (isset($oauth_file)) { $oauthFile = $oauth_file; } $token = OAuthToken::loadToken($oauthFile); if ($token == null || $token->isAccessTokenExpired()) { $tokenSrvc = new OAuthTokenService($FQDN, $clientId, $clientSecret); $token = $tokenSrvc->getTokenUsingScope($scope); // save token for future use $token->saveToken($oauthFile); } return $token; }
session_start(); require __DIR__ . '/../config.php'; require_once __DIR__ . '/../lib/OAuth/OAuthToken.php'; require_once __DIR__ . '/../lib/OAuth/OAuthTokenService.php'; require_once __DIR__ . '/../lib/Util/Util.php'; require_once __DIR__ . '/../lib/Speech/SpeechService.php'; use Att\Api\OAuth\OAuthToken; use Att\Api\OAuth\OAuthTokenService; use Att\Api\Util\Util; use Att\Api\Speech\SpeechService; $arr = null; try { $token = OAuthToken::loadToken($oauth_file); if ($token == null || $token->isAccessTokenExpired()) { $tokenSrvc = new OAuthTokenService($FQDN, $api_key, $secret_key); $token = $tokenSrvc->getTokenUsingScope($scope); $token->saveToken($oauth_file); } $speechSrvc = new SpeechService($FQDN, $token); $speechContext = $_POST['speechContext']; $speechFile = $_POST['speechFile']; $xArg = $_POST['x_arg']; $subContext = $_POST['x_subcontext']; $chunked = isset($_POST['chunked']) ? true : null; $allowedFiles = array('boston_celtics.wav', 'california.amr', 'coffee.amr', 'doctors.wav', 'nospeech.wav', 'samplerate_conflict_error.wav', 'this_is_a_test.spx', 'too_many_channels_error.wav', 'boston_celtics.wav'); if (!in_array($speechFile, $allowedFiles, true)) { throw new Exception('Invalid speech file specified'); } $flocation = $audioFolder . '/' . $speechFile; if ($speechContext !== 'Gaming') { $subContext = null;
/** * Gets an access token that will be cached using a file. * * This method works first trying to load the file specified in config, * and, if a saved OAuth token isn't found, this method will send an API * request. The OAuth token will then be saved for future use. * * @return OAuthToken OAuth token that can be used for authorization * @throws OAuthException if API request was not successful or if * there was a file IO issue */ protected function getFileToken() { // load location where to save token include __DIR__ . '/../../config.php'; if (!isset($oauth_file)) { // set default if can't load $oauth_file = 'token.php'; } $token = OAuthToken::loadToken($oauth_file); if ($token == null || $token->isAccessTokenExpired()) { $tokenSrvc = new OAuthTokenService($this->oauthFQDN, $this->clientId, $this->clientSecret); $token = $tokenSrvc->getTokenUsingScope($this->scope); // save token for future use $token->saveToken($oauth_file); } return $token; }
use Att\Api\OAuth\OAuthTokenService; use Att\Api\OAuth\OAuthCode; use Att\Api\Restful\RestfulEnvironment; use Exception; if (isset($proxy_host) && isset($proxy_port)) { RestfulEnvironment::setProxy($proxy_host, $proxy_port); } if (isset($accept_all_certs)) { RestfulEnvironment::setAcceptAllCerts($accept_all_certs); } try { $tokenSrvc = new OAuthTokenService($FQDN, $api_key, $secret_key); $token = null; if (isset($_POST['code'])) { $code = new OAuthCode($_POST['code']); $token = $tokenSrvc->getTokenUsingCode($code); } else { $token = $tokenSrvc->getTokenUsingScope('WEBRTC'); } $_SESSION['token'] = serialize($token); $arr = array('access_token' => $token->getAccessToken(), 'refresh_token' => $token->getRefreshToken(), 'expires_in' => $token->getExpiresIn()); echo json_encode($arr); } catch (Exception $e) { if (function_exists('http_response_code')) { http_response_code(500); } else { header("HTTP/1.1 500 Internal Server Error"); } echo json_encode($e->getMessage()); } /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */