function handlePageRequest()
{
    if (!empty($_GET[ACCESSTOKEN])) {
        // There is a token available already. It should be the token flow. Ignore it.
        return;
    }
    $verifier = $_GET[CODE];
    if (!empty($verifier)) {
        $token = requestAccessTokenByVerifier($verifier);
        if ($token !== false) {
            handleTokenResponse($token);
        } else {
            handleTokenResponse(null, array(ERRORCODE => 'request_failed', ERRORDESC => 'Failed to retrieve user access token.'));
        }
        return;
    }
    $refreshToken = readRefreshToken();
    if (!empty($refreshToken)) {
        $token = requestAccessTokenByRefreshToken($refreshToken);
        if ($token !== false) {
            handleTokenResponse($token);
        } else {
            handleTokenResponse(null, array(ERRORCODE => 'request_failed', ERRORDESC => 'Failed to retrieve user access token.'));
        }
        return;
    }
    $errorCode = $_GET[ERRORCODE];
    $errorDesc = $_GET[ERRORDESC];
    if (!empty($errorCode)) {
        handleTokenResponse(null, array(ERRORCODE => $errorCode, ERRORDESC => $errorDesc));
    }
}
Exemple #2
0
    'redirect_uri'=> LIVE_CALLBACK_URL,
    'response_type'=>'code',
    'scope'=>'wl.signin,wl.basic,wl.contacts_emails',
    'redirect_type'=>'auth',
    'request_ts'=>time(),
    'response_method'=>'cookie',
    'secure_cookie'=>0),null,'&');

$auth_url  = 'https://login.live.com/oauth20_authorize.srf?' . $query;
if(!isset($_REQUEST['r']) or !isset($_REQUEST['code']))
{
    header('location:'. $auth_url);
}else
{
    require('live.php');
    $token = requestAccessTokenByVerifier($_REQUEST['code']);
    $access_token =  $token->access_token;
    $response =  sendRequest('https://apis.live.net/v5.0/me/contacts?access_token='.$access_token);
    $result = json_decode($response,1);
    $contacts = array();
    foreach($result['data'] as $data)
    {
        if(!isset($data['emails']) or !isset($data['emails']['preferred'])){
            continue;
        }
        $contacts[] = array(
            'name'=>$data['name'],
            'email'=>$data['emails']['preferred'],
        );
    }