/** 
  * Gets an access token that will be cached using a session. 
  *
  * This method works by first trying to load the token from the user's 
  * session, and, if a saved OAuth token isn't found, this method will send 
  * an API request. The OAuth token will then be saved in session 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 session issue  
  */
 protected function getSessionToken()
 {
     // Try loading token from session
     $token = isset($_SESSION['token']) ? unserialize($_SESSION['token']) : null;
     // load redirect URL
     include __DIR__ . '/../../config.php';
     // No token or token is expired... send token request
     if (!$token || $token->isAccessTokenExpired()) {
         $codeURL = $this->oauthFQDN . '/oauth/authorize';
         $codeRequest = new OAuthCodeRequest($codeURL, $this->clientId, $this->scope, $authorize_redirect_uri);
         $code = $codeRequest->getCode();
         $tokenSrvc = new OAuthTokenService($this->oauthFQDN, $this->clientId, $this->clientSecret);
         $token = $tokenSrvc->getTokenUsingCode($code);
         $_SESSION['token'] = serialize($token);
     }
     return $token;
 }
<?php

include __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/OAuth/OAuthCodeRequest.php';
use Att\Api\OAuth\OAuthCodeRequest;
$scope = "WEBRTCMOBILE";
$codeUrl = $FQDN . '/oauth/v4/authorize';
$codeRequest = new OAuthCodeRequest($codeUrl, $api_key, $scope, $authorize_redirect_uri);
$url = $codeRequest->getCodeLocation();
$arr = array('consent_url' => $url);
echo json_encode($arr);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 /**
  * Generate the oauth redirect URL depending on the scope requested by the client.
  * The scope is specified as a parameter in the GET request and passed to the provider
  * library to obtain the appropriate oAuth URL
  *
  * @param {String} scope a comma separated list of services that the app requires access to
  * @param {String} return_url address to redirect the callback to after authcode is obtained
  * @param {String} $custom_param a comma separated value to by pass on-net OR suppress landing page
  *
  * @return {string} Returns the oAuth URL 
  * @method oauthUrl
  *
  */
 public function oauthUrl($scope, $return_url, $custom_param)
 {
     $encoded_return_url = urlencode($return_url);
     $redirect_uri = $this->local_server . "/att/callback.php?scopes=" . $scope . "&returnUrl=" . $encoded_return_url;
     // Create object to get an OAuth Code Location URL
     $oacr = new OAuthCodeRequest($this->base_url . "/oauth/v4/authorize", $this->client_id, $scope, $redirect_uri);
     // Append custom param, if it was sent or is set in the config file
     $oAuthUrl = $oacr->getCodeLocation();
     if ($custom_param != null) {
         if (DEBUG) {
             Debug::init();
             Debug::write("Custom params are: {$custom_param}\n");
             Debug::end();
         }
         $oAuthUrl = $oAuthUrl . '&custom_param=' . $custom_param;
     }
     if (DEBUG) {
         Debug::init();
         Debug::write("OAuth URL for authorize is: {$oAuthUrl}\n");
         Debug::end();
     }
     return $oAuthUrl;
 }
/** 
 * Gets the URL to redirect an application to for authorization.
 *
 * This function uses the parameters specified in the configuration file.
 *
 * @return string URL to redirect for authorization
 */
function getCodeLocation()
{
    $codeUrl = getFqdn() . '/oauth/v4/authorize';
    $codeRequest = new OAuthCodeRequest($codeUrl, CLIENT_ID, SCOPE, AUTHORIZE_REDIRECT_URI);
    return $codeRequest->getCodeLocation();
}