コード例 #1
0
ファイル: common.php プロジェクト: honchoman/singpolyma
function doAuth($info, $trusted = null, $fail_cancels = false)
{
    if (!$info) {
        // There is no authentication information, so bail
        return authCancel(null);
    }
    $req_url = $info->identity;
    $user = getLoggedInUser();
    setRequestInfo($info);
    if ($req_url != $user) {
        return login_render(array(), $req_url, $req_url);
    }
    $sites = getSessionSites();
    $trust_root = $info->trust_root;
    $fail_cancels = $fail_cancels || isset($sites[$trust_root]);
    $trusted = isset($trusted) ? $trusted : isTrusted($req_url, $trust_root);
    if ($trusted) {
        setRequestInfo();
        $server =& getServer();
        $response =& $info->answer(true);
        $webresponse =& $server->encodeResponse($response);
        $new_headers = array();
        foreach ($webresponse->headers as $k => $v) {
            $new_headers[] = $k . ": " . $v;
        }
        return array($new_headers, $webresponse->body);
    } elseif ($fail_cancels) {
        return authCancel($info);
    } else {
        return trust_render($info);
    }
}
コード例 #2
0
function doAuth($info, $trusted = null, $fail_cancels = false, $idpSelect = null)
{
    if (!$info) {
        // There is no authentication information, so bail
        return authCancel(null);
    }
    if ($info->idSelect()) {
        if ($idpSelect) {
            $req_url = idURL($idpSelect);
        } else {
            $trusted = false;
        }
    } else {
        $req_url = $info->identity;
    }
    $user = getLoggedInUser();
    setRequestInfo($info);
    if (!$info->idSelect() && $req_url != idURL($user)) {
        return login_render(array(), $req_url, $req_url);
    }
    $trust_root = $info->trust_root;
    if ($trusted) {
        setRequestInfo();
        $server =& getServer();
        $response =& $info->answer(true, null, $req_url);
        // Answer with some sample Simple Registration data.
        $sreg_data = array('fullname' => 'Example User', 'nickname' => 'example', 'dob' => '1970-01-01', 'email' => '*****@*****.**', 'gender' => 'F', 'postcode' => '12345', 'country' => 'ES', 'language' => 'eu', 'timezone' => 'America/New_York');
        // Add the simple registration response values to the OpenID
        // response message.
        $sreg_request = Auth_OpenID_SRegRequest::fromOpenIDRequest($info);
        $sreg_response = Auth_OpenID_SRegResponse::extractResponse($sreg_request, $sreg_data);
        $sreg_response->toMessage($response->fields);
        // Generate a response to send to the user agent.
        $webresponse =& $server->encodeResponse($response);
        $new_headers = array();
        foreach ($webresponse->headers as $k => $v) {
            $new_headers[] = $k . ": " . $v;
        }
        return array($new_headers, $webresponse->body);
    } elseif ($fail_cancels) {
        return authCancel($info);
    } else {
        return trust_render($info);
    }
}
コード例 #3
0
ファイル: actions.php プロジェクト: marcioyonamine/php-openid
/**
 * Log out the currently logged in user
 */
function action_logout()
{
    setLoggedInUser(null);
    setRequestInfo(null);
    return authCancel(null);
}
コード例 #4
0
ファイル: common.php プロジェクト: akbarhossain/openid4me
function doAuth($info, $trusted = null, $fail_cancels = false, $idpSelect = null)
{
    if (!$info) {
        // There is no authentication information, so bail
        return authCancel(null);
    }
    $auth = getAuth();
    $cert_webid_23 = str_replace('#', '%23', $auth['agent']['webid']);
    $cert_webid = str_replace('http://', '', $cert_webid_23);
    //	$cert_webid = urlencode($auth['agent']['webid']);
    if ($_SERVER['HTTPS']) {
        $host = "https://openid4.me/";
    } else {
        $host = "http://openid4.me/";
    }
    $normalized_webid = $host . $cert_webid;
    if ($info->idSelect()) {
        //        if ($idpSelect) {
        //            $req_url = idURL($idpSelect);
        if ($auth[isAuthenticated]) {
            $req_url = $normalized_webid;
        } else {
            $trusted = false;
        }
        //        } else {
        //            $trusted = false;
        //        }
    } else {
        $req_url = $info->identity;
        if ($req_url != $normalized_webid) {
            //Get link header
            $link_webid = fetch_foaf_profile($req_url);
            if ($cert_webid == $link_webid) {
                $trusted = true;
            } else {
                $agent = get_agent(urldecode($link_webid));
                /*
                					print "<pre>";
                					print_r($agent);
                					print "</pre>";
                */
                $link_webid = isset($agent['agent']['webid']) ? str_replace('#', '%23', $agent['agent']['webid']) : '';
                if ($cert_webid_23 == $link_webid) {
                    $trusted = true;
                } else {
                    $trusted = false;
                }
            }
        } else {
            $trusted = true;
        }
    }
    $user = getLoggedInUser();
    setRequestInfo($info);
    /*
        if ((!$info->idSelect()) && ($req_url != idURL($user))) {
            return login_render(array(), $req_url, $req_url);
        }
    */
    $trust_root = $info->trust_root;
    if ($trusted) {
        setRequestInfo();
        $server =& getServer();
        $response =& $info->answer(true, null, $req_url);
        // Answer with some sample Simple Registration data.
        $agent = get_agent($auth['agent']['webid']);
        $sreg_data = array();
        if ($fullname = $agent['agent']['name']) {
            $sreg_data = array_merge($sreg_data, array('fullname' => $fullname));
        }
        if ($nickname = $agent['agent']['nick'][0]) {
            $sreg_data = array_merge($sreg_data, array('nickname' => $nickname));
        }
        if ($mbox = $agent['agent']['mbox'][0]) {
            $mbox = str_replace('mailto:', '', $mbox);
            $sreg_data = array_merge($sreg_data, array('email' => $mbox));
        }
        // Add the simple registration response values to the OpenID
        // response message.
        $sreg_request = Auth_OpenID_SRegRequest::fromOpenIDRequest($info);
        $sreg_response = Auth_OpenID_SRegResponse::extractResponse($sreg_request, $sreg_data);
        $sreg_response->toMessage($response->fields);
        // Generate a response to send to the user agent.
        $webresponse =& $server->encodeResponse($response);
        $new_headers = array();
        foreach ($webresponse->headers as $k => $v) {
            $new_headers[] = $k . ": " . $v;
        }
        return array($new_headers, $webresponse->body);
    } elseif ($fail_cancels) {
        return authCancel($info);
    } else {
        return trust_render($info);
    }
}
コード例 #5
0
ファイル: server.php プロジェクト: lorea/Hydra-dev
<?php

require_once 'openid_server_include.php';
require_once 'lib/session.php';
require_once 'lib/actions.php';
if (elgg_get_viewtype() == 'xrds') {
    echo elgg_view_page($title, $body);
    exit(0);
}
$store = getOpenIDServerStore();
$server =& getServer();
$request = $server->decodeRequest();
setRequestInfo($request);
$action = getAction();
if (!function_exists($action)) {
    $action = 'action_default';
}
$resp = $action();
if (!empty($resp)) {
    writeResponse($resp);
} else {
    echo elgg_view_page($title, $body);
    exit(0);
}
コード例 #6
0
ファイル: autologin.php プロジェクト: lorea/Hydra-dev
require_once dirname(dirname(__FILE__)) . '/openid_server_include.php';
require_once 'lib/common.php';
require_once 'lib/session.php';
$iframe_template = <<<END
<iframe
width="%s"
height="%s"
src="%s"
>
</iframe>');
END;
$openid_url = getLoggedinUser();
$store = getOpenIDServerStore();
$sites = $store->getAutoLoginSites();
$request = getRequestInfo();
if ($request) {
    $return_url = $request->return_to;
    setRequestInfo(null);
} else {
    $return_url = $CONFIG->wwwroot;
}
// TODO: get this to work with posts
$iframes = '';
foreach ($sites as $site) {
    $iframes .= sprintf($iframe_template, $site->width, $site->height, sprintf($site->auto_login, $openid_url));
}
$body = elgg_view("openid_server/forms/autologin", array('iframes' => $iframes, 'return_to' => $return_url));
$CONFIG->events['login'] = array();
login();
header("Content-type:text/html");
print $body;
コード例 #7
0
ファイル: server.php プロジェクト: ahelsing/geni-portal
function action_authorize()
{
    $server =& getServer();
    $info = getRequestInfo();
    if (!$info) {
        $info = $server->decodeRequest();
    }
    // Throw away the info, we no longer need it.
    setRequestInfo();
    $trusted = isset($_POST['save']);
    if ($trusted) {
        return send_geni_user($server, $info);
    } else {
        return send_cancel($info);
    }
}
コード例 #8
0
ファイル: trust.php プロジェクト: lorea/Hydra-dev
    $user_path = substr($user, strpos($user, ":"));
    if ($info->message->isOpenID1() && $req_url_path != $user_path) {
        register_error(sprintf(elgg_echo("openid_server:loggedin_as_wrong_user"), $req_url, $user));
        forward();
    } else {
        $trust_root = $info->trust_root;
        $trusted = isset($trusted) ? $trusted : isTrusted($identity, $trust_root);
        if ($trusted) {
            setRequestInfo();
            $server =& getServer();
            if ($info->message->isOpenID1()) {
                $response =& $info->answer(true, null, $req_url);
            } else {
                $response =& $info->answer(true, null, getServerURL(), $identity);
            }
            addSregFields($response, $info, $identity);
            $webresponse =& $server->encodeResponse($response);
            $new_headers = array();
            foreach ($webresponse->headers as $k => $v) {
                $new_headers[] = $k . ": " . $v;
            }
            writeResponse(array($new_headers, $webresponse->body));
            exit(0);
        } elseif ($fail_cancels) {
            setRequestInfo();
            forward($info->getCancelURL());
        } else {
            writeResponse(trust_render($info));
        }
    }
}
コード例 #9
0
ファイル: render.php プロジェクト: alx/openid-server
function render_serve($method, &$request, &$template)
{
    global $storage;
    $server =& getServer();
    $http_request = $request;
    $request = Auth_OpenID::fixArgs($request);
    $request = $server->decodeRequest($request);
    if (!$request) {
        Server_redirect(getServerURL());
    }
    if (is_a($request, 'Auth_OpenID_ServerError')) {
        Server_handleResponse($request);
    }
    setRequestInfo($request, Server_requestSregData($http_request));
    if (in_array($request->mode, array('checkid_immediate', 'checkid_setup'))) {
        $urls = array();
        $account = Server_getAccount();
        if ($account) {
            $urls = $storage->getUrlsForAccount($account);
        }
        if ($request->immediate && !$account) {
            $response =& $request->answer(false, getServerURL());
        } else {
            if ($account && $storage->isTrusted($account, $request->trust_root) && in_array($request->identity, $urls)) {
                $response =& $request->answer(true);
                addSregData($account, $response);
            } else {
                if ($account != $storage->getAccountForUrl($request->identity)) {
                    Server_clearAccount();
                    setRequestInfo($request, Server_requestSregData($http_request));
                    $http_request['action'] = 'trust';
                    Server_needAuth($http_request);
                } else {
                    if ($storage->isTrusted($account, $request->trust_root)) {
                        $response =& $request->answer(true);
                        addSregData($account, $response);
                    } else {
                        Server_redirect(getServerURL(), 'trust');
                    }
                }
            }
        }
    } else {
        $response =& $server->handleRequest($request);
    }
    setRequestInfo();
    Server_handleResponse($response);
}