123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- require_once INSTALLDIR.'/plugins/OpenID/openid.php';
- class OpenidserverAction extends Action
- {
- var $oserver;
- function prepare(array $args = array())
- {
- parent::prepare($args);
- $this->oserver = oid_server();
- return true;
- }
- function handle()
- {
- parent::handle();
- $request = $this->oserver->decodeRequest();
- if (in_array($request->mode, array('checkid_immediate',
- 'checkid_setup'))) {
- if (!$this->scoped instanceof Profile) {
- if($request->immediate){
-
- $response = $this->generateDenyResponse($request);
- }else{
-
-
-
-
-
- common_set_returnto($_SERVER['REQUEST_URI']);
- common_redirect(common_local_url('login'), 303);
- }
- } elseif (in_array($request->identity, $this->scoped->getAliases()) || $request->idSelect()) {
- $user_openid_trustroot = User_openid_trustroot::pkeyGet(
- array('user_id'=>$this->scoped->getID(), 'trustroot'=>$request->trust_root));
- if(empty($user_openid_trustroot)){
- if($request->immediate){
-
- $response = $this->generateDenyResponse($request);
- }else{
- common_ensure_session();
- $_SESSION['openid_trust_root'] = $request->trust_root;
- $allowResponse = $this->generateAllowResponse($request, $this->scoped);
- $this->oserver->encodeResponse($allowResponse);
- $denyResponse = $this->generateDenyResponse($request);
- $this->oserver->encodeResponse($denyResponse);
- $_SESSION['openid_allow_url'] = $allowResponse->encodeToUrl();
- $_SESSION['openid_deny_url'] = $denyResponse->encodeToUrl();
-
-
-
-
-
- common_redirect(common_local_url('openidtrust'), 303);
- }
- } else {
-
- $response = $this->generateAllowResponse($request, $this->scoped);
- }
- } elseif ($request->immediate) {
- $response = $this->generateDenyResponse($request);
- } else {
-
-
-
- $this->clientError(sprintf(_m('You are not authorized to use the identity %s.'),$request->identity),$code=403);
- }
- } else {
- $response = $this->oserver->handleRequest($request);
- }
- if($response){
- $response = $this->oserver->encodeResponse($response);
- if ($response->code != AUTH_OPENID_HTTP_OK) {
- header(sprintf("HTTP/1.1 %d ", $response->code),
- true, $response->code);
- }
- if($response->headers){
- foreach ($response->headers as $k => $v) {
- header("$k: $v");
- }
- }
- $this->raw($response->body);
- }else{
-
- $this->clientError(_m('Just an OpenID provider. Nothing to see here, move along...'),$code=500);
- }
- }
- function generateAllowResponse($request, Profile $profile){
- $response = $request->answer(true, null, $profile->getUrl());
- $user = $profile->getUser();
- $sreg_data = array(
- 'fullname' => $profile->getFullname(),
- 'nickname' => $profile->getNickname(),
- 'email' => $user->email,
- 'language' => $user->language,
- 'timezone' => $user->timezone);
- $sreg_request = Auth_OpenID_SRegRequest::fromOpenIDRequest($request);
- $sreg_response = Auth_OpenID_SRegResponse::extractResponse(
- $sreg_request, $sreg_data);
- $sreg_response->toMessage($response->fields);
- return $response;
- }
- function generateDenyResponse($request){
- $response = $request->answer(false);
- return $response;
- }
- }
|