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); }
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> •Click <strong>"Get Access Token"</strong> Button.<br /> •Login into your Constant Contact then authorize the <strong>"Simple Constant Contact"</strong> plugin. <br /> •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 }
if (isset($_GET['code'])) { try { $accessToken = $oauth->getAccessToken($_GET['code']); } catch (OAuth2Exception $ex) { echo '<span class="label label-important">OAuth2 Error!</span>'; echo '<div class="container alert-error"><pre class="failure-pre">'; echo 'Error: ' . $ex->getMessage(); echo '</pre></div>'; die; } echo '<span class="label label-success">Access Token Retrieved!</span>'; echo '<div class="container alert-success"><pre class="success-pre">'; print_r($accessToken); echo '</pre></div>'; } else { ?> <!-- If the 'code' query parameter is not present, display the link the user needs to visit to initiate the oauth flow --> <button class="btn btn-primary" type="button" onclick="window.location.href='<?php echo $oauth->getAuthorizationUrl(); ?> ';">Get Access Token </button> <?php } ?> </div> </body> </html>