Esempio n. 1
0
function plugin_jugemkey_get_user_name()
{
    global $auth_api;
    if (!$auth_api['jugemkey']['use']) {
        return array('role' => ROLE_GUEST, 'nick' => '');
    }
    $obj = new auth_jugemkey();
    $msg = $obj->auth_session_get();
    // FIXME
    // Because user information can be acquired by token only at online, it doesn't mount.
    // $info = (empty($msg['token'])) ? '' : get_resolve_uri('jugemkey','', '', 'token='.$msg['token'].'%amp;userinfo');
    // Only, it leaves it only as a location of attestation by JugemKey.
    $info = 'http://jugemkey.jp/';
    if (!empty($msg['title'])) {
        return array('role' => ROLE_AUTH_JUGEMKEY, 'nick' => $msg['title'], 'profile' => $info, 'key' => $msg['title']);
    }
    return array('role' => ROLE_GUEST, 'nick' => '');
}
 function get_userinfo($token)
 {
     $created = substr_replace(get_date('Y-m-d\\TH:i:sO', UTIME), ':', -2, 0);
     $api_sig = auth_jugemkey::hmac_sha1($this->sec_key, $this->api_key . $created . $token);
     $headers = array('X-JUGEMKEY-API-CREATED' => $created, 'X-JUGEMKEY-API-KEY' => $this->api_key, 'X-JUGEMKEY-API-TOKEN' => $token, 'X-JUGEMKEY-API-SIG' => $api_sig);
     $data = http_request(JUGEMKEY_URL_USER, 'GET', $headers);
     $rc = array();
     $rc['rc'] = $data['rc'];
     if ($data['rc'] != 200 && $data['rc'] != 401) {
         return $rc;
     }
     $xml_parser = xml_parser_create();
     xml_parse_into_struct($xml_parser, $data['data'], $val, $index);
     xml_parser_free($xml_parser);
     foreach ($val as $x) {
         if ($x['type'] != 'complete') {
             continue;
         }
         $rc[strtolower($x['tag'])] = $x['value'];
     }
     return $rc;
 }