Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] PHP-OpenID (Janrain): return_to does not match return URL

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Erledigt] PHP-OpenID (Janrain): return_to does not match return URL

    Hallo zusammen,

    Bei diesem Code bekomme ich als $response->message
    PHP-Code:
    <?php
    require_once $GLOBALS[ 'config' ][ 'openid_path' ] . '/Consumer.php';
    require_once 
    $GLOBALS[ 'config' ][ 'openid_path' ] . '/FileStore.php';
    require_once 
    $GLOBALS[ 'config' ][ 'openid_path' ] . '/SReg.php';

    class 
    signin_controller extends controller
    {
      private 
    $consumer;

      public function 
    __construct( request $request, response $response )
      {
        
    $store = new Auth_OpenID_FileStore( rtrim( BASE_PATH, '/' ) . '/.oid_store' );
        
    $this->consumer = new Auth_OpenID_Consumer( $store );

        
    parent::__construct( $request, $response );
      }

      public function 
    main()
      {
        if ( isset( 
    $_SESSION[ 'openid_auth' ] ) && $_SESSION[ 'openid_auth' ] !== false )
        {
          
    header( 'Location: ' . rtrim( BASE_URL, '/' ) . '/' );
        }

        
    $view = new html_view(  $this->get_request() );

        if ( isset( 
    $_POST[ 'identity' ] ) )
        {
          if ( empty( 
    $_POST[ 'identity' ] ) )
          {
            
    $view->assign( 'err', $GLOBALS[ 'webstring' ]->get( 'Please enter a valid OpenID' ) );
          }
          else
          {
            if ( !( 
    $auth = $this->consumer->begin( trim( $_POST[ 'identity' ] ) ) ) )
            {
              
    $view->assign( 'err', $GLOBALS[ 'webstring' ]->get( 'Please enter a valid OpenID' ) );
            }
            else
            {
              if ( ( 
    $sreg = Auth_OpenID_SRegRequest::build( array( 'email' ), array( 'fullname', 'nickname', 'language' ) ) ) )
              {
                
    $auth->addExtension( $sreg );
              }

              if ( !empty( 
    $_POST[ 'linkback' ] ) && strpos( $_POST[ 'linkback' ], 'signin' ) === false )
              {
                
    $_SESSION[ 'linkback' ] = $_POST[ 'linkback' ];
              }

              if ( 
    $auth->shouldSendRedirect() )
              {
                
    $url = $auth->redirectURL( $this->get_trustroot(), $this->get_returnto() );

                if ( 
    Auth_OpenID::isFailure( $url ) )
                {
                  
    $view->assign( 'err', $GLOBALS[ 'webstring' ]->get( $url->message ) );
                }
                else
                {
                  
    header( 'Location: ' . $url );
                }
              }
              else
              {
                
    $form_id = 'openid_message';
                
    $form_html = $auth->htmlMarkup(
                  
    $this->get_trustroot(),
                  
    $this->get_returnto(),
                  
    false,
                  array( 
    'id' => $form_id )
                );

                if ( 
    Auth_OpenID::isFailure( $form_html ) )
                {
                  
    $view->assign( 'err', $GLOBALS[ 'webstring' ]->get( $form_html->message ) );
                }
                else
                {
                  print 
    $form_html;
                }
              }
            }
          }
        }

        
    $html = $view->display( 'signin.tpl' );
        
    $this->base_view->assign( 'content', $html );
        
    $this->get_response()->set_body( $this->base_view->display( 'www_base.tpl' ) );
      }

      public function 
    complete()
      {
        
    $response = $this->consumer->complete( $this->get_returnto() );

        if ( 
    $response->status == Auth_OpenID_SUCCESS )
        {
          
    $_SESSION[ 'openid_auth' ] = true;

          
    $sreg = new Auth_OpenID_SRegResponse();
          
    $obj = $sreg->fromSuccessResponse( $response );
          
    $data = $obj->contents();

          if ( !
    $this->model->check_user_exists( $data[ 'email' ] ) )
          {
            
    $this->model->insert_user( $data );
          }

          
    $this->model->do_user_updates( $data );

          if ( @
    $data[ 'language' ] )
          {
            
    $_SESSION[ 'user' ]->set_language( $data[ 'language' ] );
          }
        }

        
    $linkback = 'http://' . $_SERVER[ 'HTTP_HOST' ] . '/' . trim( BASE_URL, '/' );
        if ( isset( 
    $_SESSION[ 'linkback' ] ) && !empty( $_SESSION[ 'linkback' ] ) )
        {
          
    $linkback = $_SESSION[ 'linkback' ];
          unset( 
    $_SESSION[ 'linkback' ] );
        }

        if ( ( isset( 
    $_SESSION[ 'openid_auth' ] ) && $_SESSION[ 'openid_auth' ] !== false ) || $response->status == Auth_OpenID_CANCEL )
        {
          
    header( 'Location: ' . $linkback );
        }

        
    $view = new html_view(  $this->get_request() );
        
    $view->assign( 'err', $GLOBALS[ 'webstring' ]->get( $response->message ) );

        
    $html = $view->display( 'signin.tpl' );
        
    $this->base_view->assign( 'content', $html );
        
    $this->get_response()->set_body( $this->base_view->display( 'www_base.tpl' ) );
      }

      private function 
    get_scheme()
      {
        
    $scheme = 'http';
        if ( isset( 
    $_SERVER[ 'HTTPS' ] ) && $_SERVER[ 'HTTPS' ] == 'on' )
        {
          
    $scheme .= 's';
        }

        return 
    $scheme;
      }

      private function 
    get_trustroot()
      {
        return 
    sprintf(
          
    '%s://%s:%s%s/',
          
    $this->get_scheme(),
          
    $_SERVER[ 'SERVER_NAME' ],
          
    $_SERVER[ 'SERVER_PORT' ],
          
    rtrim( BASE_URL, '/' )
        );
      }

      private function 
    get_returnto()
      {
        return 
    sprintf( '%s/signin/complete', rtrim( $this->get_trustroot(), '/' ) );
      }
    }
    Das hier allerdings ist abgekapselt von meinem MVC und funktioniert komischerweise:
    PHP-Code:
    /**/
    // complete.php
    /**/
    <?php
    require_once 'Auth_OpenID/OpenID/Consumer.php';
    require_once 
    'Auth_OpenID/OpenID/FileStore.php';
    require_once 
    'Auth_OpenID/OpenID/SReg.php';

    $store = new Auth_OpenID_FileStore( './oid_store' );
    $consumer = new Auth_OpenID_Consumer( $store );
    $response = $consumer->complete( 'http://localhost/complete.php' );

    if ( 
    $response->status == Auth_OpenID_SUCCESS )
    {
      
    $_SESSION[ 'openid_auth' ] = true;

      
    $sreg = new Auth_OpenID_SRegResponse();
      
    $obj = $sreg->fromSuccessResponse( $response );
      
    $data = $obj->contents();
      
    var_dump( $data );
    }
    else echo 
    $response->message;
    ?>



    /**/
    // index.php
    /**/

    <?php
    require_once 'Auth_OpenID/OpenID/Consumer.php';
    require_once 
    'Auth_OpenID/OpenID/FileStore.php';
    require_once 
    'Auth_OpenID/OpenID/SReg.php';

    if ( isset( 
    $_POST[ 'identity' ] ) )
    {
      
    $store = new Auth_OpenID_FileStore( './oid_store' );
      
    $consumer = new Auth_OpenID_Consumer( $store );

      if ( empty( 
    $_POST[ 'identity' ] ) ) $err = 'Please enter a valid OpenID';
      else
      {
        if ( !( 
    $auth = $consumer->begin( trim( $_POST[ 'identity' ] ) ) ) ) $err = 'Please enter a valid OpenID';
        else
        {
          if ( ( 
    $sreg = Auth_OpenID_SRegRequest::build( array( 'email' ), array( 'fullname', 'nickname', 'language' ) ) ) )
            
    $auth->addExtension( $sreg );

          
    $url = $auth->redirectURL( 'http://localhost/', 'http://localhost/complete.php' );
          
    header( 'Location: ' . $url );
        }
      }
    }
    ?>
    <?php 
    if ( isset( $err ) ): ?>
    <div><?=$err?></div>
    <?php endif; ?>
    <form method="post">
      <label for="signin-identity-b">OpenID Identity:</label><br />
      <input type="text" name="identity" id="signin-identity-b" />
      <input type="submit" name="signin" value="Sign in" />
    </form>
    Ich sehe einfach keinen Fehler und verstehe nicht, weshalb er mir diesen Fehler ausspuckt...

    Viele Grüße
    Danny.

  • #2
    Naja - Die URLs scheinen doch unterschiedlich zu sein...

    Kommentar


    • #3
      Ja muss auch. Hab das ja unabhängig voneinander getestet

      Kommentar


      • #4
        Das Problem ist, dass der Parameter, den ich der complete-Funktion übergebe irgendwie falsch ist bzw nicht mit dem aus $_GET übereinstimmt...

        ein
        PHP-Code:
        <?php
        echo $this->get_returnto() . "\n";
        var_dump( $_GET );
        return;
        in der complete-Funktion meines Controllers bringt mir folgende Ausgabe:
        http://localhost:80/gse/signin/complete
        array(17) {
        ...
        ["openid_return_to"]=>
        string(80) "http://localhost:80/gse/signin/complete?janrain_nonce=2011-07-22T19:53:06Z06KCeA"
        ...
        }
        Ich bekomme also vom OpenID Provider den falschen openid_return_to Parameter übermittelt, verstehe aber nicht wieso?!

        EDIT: Ich habe das Gefühl, dass die Bibliothek Probleme mit meinen Rewrite-URLs hat. Sobald ich nämlich mal eine separate PHP-Datei angebe ala http://localhost/gse/complete.php funktioniert das Ganze auch einwandfrei... Am Code hab ich von der Logik her ja garnix geändert, lediglich die URL mit der die Lib nich klar kommt...

        Kommentar


        • #5
          Okay hat sich erledigt, es liegt an der Bibliothek:
          https://github.com/openid/php-openid/issues/37

          Kommentar

          Lädt...
          X