public function testGetAuthorizationUrlClientWithState()
 {
     $state = 'this is my state';
     $authUrl = $this->ctctOAuth2->getAuthorizationUrl(false, $state);
     $baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
     $params = array('response_type' => 'token', 'client_id' => $this->apiKey, 'redirect_uri' => $this->redirectUri, 'state' => $state);
     $expectedUrl = $baseUrl . '?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986);
     $this->assertEquals($expectedUrl, $authUrl);
 }
 public function __construct($processResponse = true)
 {
     $this->redirect_uri = $this->getRedirectUri(false);
     parent::__construct(CTCT_APIKEY, CTCT_APISECRET, $this->redirect_uri, new KWSRestClient(CTCT_APIKEY));
     if ($processResponse) {
         $this->processResponse();
     }
 }
    function simpleCC_option_page()
    {
        // indicated that the options have been updated
        if (isset($_GET['settings-updated'])) {
            echo '<div id="setting-error-settings_updated" class="updated settings-error">';
            echo '<p><strong>Settings saved</strong></p></div>';
        }
        ?>
				<!-- display form in admin menu -->
				<div class="wrap">
					<h2>Simple Constant Contact Options Page</h2>
					<form action="options.php" method="post" id="simpleCC-options-form">
						<?php 
        settings_fields('simpleCC_options');
        ?>
				
						<div>
							<h3 class="title">To Get Access Token:</h3>
								<p> 
									&bull;Click <strong>"Get Access Token"</strong> Button.<br />
									&bull;Login into your Constant Contact then authorize the <strong>"Simple Constant Contact"</strong> plugin. <br />
									&bull;Copy the access token and paste it in the input box below labeled <strong>"Constant Contact Access Token"</strong>.<br />
								</p>
		        		</div> 	
		        		<hr>		
		        		<table class="form-table">
		        			<tbody>
		        				<tr>
		        					<th scope="row">
		        						<label for="simpleCC_listname">Constant Contact Access Token: </label> 
		        					</th>
		        					<td>
		        						<input type="text" size="35" id="simpleCC_accesstoken" name="simpleCC_accesstoken" value="<?php 
        echo esc_attr(get_option('simpleCC_accesstoken'));
        ?>
" />
										<button type="button" id="simpleCC_accesstoken" 
											<?php 
        $oauth = new CtctOAuth2(get_option('simpleCC_apikey'), get_option('simpleCC_secret'), get_option('simpleCC_redirect'));
        $url = $oauth->getAuthorizationUrl();
        ?>
											onclick="window.open('<?php 
        echo $url;
        ?>
');">Get Access Token </button>
		        					</td>
		        				</tr>
		        				<tr>
		        					<th scope="row">
		        						<label for="simpleCC_listname">Constant Contact List Name: </label> 	
		        					</th>
		        					<td>
		        						<input type="text" size="35" id="simpleCC_listname" name="simpleCC_listname" value="<?php 
        echo esc_attr(get_option('simpleCC_listname'));
        ?>
" />
		        					</td>
		        				</tr>
		        			</tbody>
		        		</table>
		        		<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"  /></p>
					</form>
				</div>		
			<?php 
    }
This example flow illustrates how to get an access token for a Constant Contact account owner using the OAuth2 server flow. 
You must have a valid Constant Contact API Key, consumer sercret, and associated redirect_uri. All of these can be obtained from
http://constantcontact.mashery.com.
-->

<?php 
// require the autloader
require_once '../src/Ctct/autoload.php';
use Ctct\Auth\CtctOAuth2;
use Ctct\Exceptions\OAuth2Exception;
// Enter your Constant Contact APIKEY, CONSUMER_SECRET, and REDIRECT_URI
define("APIKEY", "ENTER YOUR API KEY");
define("CONSUMER_SECRET", "ENTER YOUR CONSUMER SECRET");
define("REDIRECT_URI", "ENTER YOUR REDIRECT URI");
// instantiate the CtctOAuth2 class
$oauth = new CtctOAuth2(APIKEY, CONSUMER_SECRET, REDIRECT_URI);
?>

<body>
<div class="well">
    <h3>OAuth 2 Authorization Example</h3>

    <?php 
// print any error from Constant Contact that occurs during the authorization process
if (isset($_GET['error'])) {
    echo '<span class="label label-important">OAuth2 Error!</span>';
    echo '<div class="container alert-error"><pre class="failure-pre">';
    echo 'Error: ' . $_GET['error'];
    echo '<br />Description: ' . $_GET['error_description'];
    echo '</pre></div>';
    die;