Example #1
0
function checkAuthResult()
{
    $code = getVariable('code', FALSE);
    $state = getVariable('state', FALSE);
    $provider = createProvider([], []);
    $oauthUnguessable = getSessionVariable('oauthUnguessable', null);
    if (!$code || !$state || !$oauthUnguessable) {
        return;
    }
    if ($state !== $oauthUnguessable) {
        //Miss-match on what we're tring to validated.
        echo "Mismatch on secret'";
        return;
    }
    try {
        $api = $provider->make('DebugGithub');
        //$client
        /** @var  $api DebugGithub */
        $command = $api->oauthAuthorize(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, $code, "http://" . SERVER_HOSTNAME . "/github/return.php");
        $accessResponse = $command->execute();
        setSessionVariable(GITHUB_ACCESS_RESPONSE_KEY, $accessResponse);
        if ($accessResponse->oauthScopes) {
            echo "You are now authed for the following scopes:<br/>";
            foreach ($accessResponse->oauthScopes as $scope) {
                echo $scope . "<br/>";
            }
        }
    } catch (GithubArtaxServiceException $fae) {
        echo "Exception processing response: " . $fae->getMessage();
    }
}
Example #2
0
<h3><a href='/'>Oauth test home</a> </h3>
END;
/** @var  $accessResponse \GithubService\Model\AccessResponse */
$accessResponse = getSessionVariable(GITHUB_ACCESS_RESPONSE_KEY);
if ($accessResponse) {
    if (!$accessResponse instanceof GithubService\Model\AccessResponse) {
        //class was renamed...or something else bad happened.
        setSessionVariable(GITHUB_ACCESS_RESPONSE_KEY, null);
        $accessResponse = null;
    }
}
$shareClasses = [];
if ($accessResponse) {
    $shareClasses['GithubService\\Model\\AccessResponse'] = $accessResponse;
}
$provider = createProvider([], $shareClasses);
//These actions need to be done before the rest of the page.
$action = getVariable('action');
switch ($action) {
    case 'delete':
        unsetSessionVariable(GITHUB_ACCESS_RESPONSE_KEY);
        $accessResponse = null;
        break;
    case 'revoke':
        revokeAuthority($accessResponse);
        break;
}
try {
    if ($accessResponse == null) {
        echo "<p>You are not github authorised. Please choose the permissions you want to test with:</p>";
        processUnauthorizedActions();
Example #3
0
<?php

use GithubService\GithubArtaxService\GithubService;
use ArtaxServiceBuilder\ResponseCache\NullResponseCache;
use Amp\Artax\Client as ArtaxClient;
use ArtaxServiceBuilder\BadResponseException;
use ArtaxServiceBuilder\Oauth2Token;
use GithubService\Hydrator\HydratorException;
require_once "testBootstrap.php";
$injector = createProvider();
$reactor = \Amp\reactor();
$cache = new NullResponseCache();
$client = new ArtaxClient();
$client->setOption(ArtaxClient::OP_MS_CONNECT_TIMEOUT, 5000);
$client->setOption(ArtaxClient::OP_MS_KEEP_ALIVE_TIMEOUT, 1000);
$githubAPI = new GithubService($client, $reactor, $cache, "Danack/test");
$token = @file_get_contents("../../GithubToken.txt");
$oauthToken = null;
if ($token) {
    $oauthToken = new Oauth2Token($token);
}
try {
    $tagListRequest = $githubAPI->listRepoTags(null, "Danack", "GithubArtaxService");
    $tagList = $tagListRequest->execute();
    foreach ($tagList as $tag) {
        /** @var $tag \GithubService\Model\Tag */
        printf("tag name %s, commmit %s \n", $tag->name, $tag->commit->sha);
    }
    $emojiResult = $githubAPI->listEmojis(null)->execute();
    foreach ($emojiResult->emojis as $emoji) {
        echo $emoji->name . " \n";