Plugin Directory

Changeset 595581


Ignore:
Timestamp:
09/06/2012 09:01:34 PM (14 years ago)
Author:
jascott
Message:

rough OAuth implementation

Location:
kickpress/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kickpress/trunk/kickpress-oauth.php

    r595539 r595581  
    8282}
    8383
     84function kickpress_oauth_authenticate() {
     85    kickpress_oauth_provider::authenticate();
     86}
     87
    8488class kickpress_oauth {
    8589    public static function get_args() {
     
    248252    protected $_verifier;
    249253   
     254    protected $_user_id;
     255    protected $_blog_id;
     256   
    250257    public function __construct( $args = array() ) {
    251258        parent::__construct( $args );
     
    263270    public function set_verifier( $verifier ) {
    264271        $this->_verifier = $verifier;
     272    }
     273   
     274    public function set_user_id( $user_id ) {
     275        $this->_user_id = $user_id;
     276    }
     277   
     278    public function set_blog_id( $blog_id ) {
     279        $this->_blog_id = $blog_id;
    265280    }
    266281   
     
    461476    }
    462477   
     478    public static function authenticate( $args = null ) {
     479        self::$_action = 'authenticate';
     480       
     481        if ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
     482            $consumer = self::validate_consumer( $args );
     483           
     484            if ( ! is_wp_error( $consumer ) )
     485                wp_set_current_user( $consumer->user_id );
     486        }
     487    }
     488   
    463489    public static function validate_consumer( $args = null ) {
    464490        if ( ! isset( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
     
    473499        if ( is_null( $args ) ) $args = self::get_args();
    474500       
    475         $provider  = new self();
     501        $provider = new self();
    476502       
    477503        if ( $oauth = $provider->parse_signature() ) {
     
    483509                $token_actions = array(
    484510                    'access-token',
    485                     'resource'
     511                    'authenticate'
    486512                );
    487513               
     
    507533                            }
    508534                        }
    509                     } elseif ( 'oauth-resource' == self::$_action ) {
     535                    } elseif ( 'authenticate' == self::$_action ) {
    510536                        $meta = kickpress_user_meta_query( 0,
    511537                            'kickpress\_oauth\_access\_token\_%',
     
    513539                       
    514540                        if ( $meta = array_shift( $meta ) ) {
    515                             $token        = $option->oauth_token;
    516                             $token_secret = $option->oauth_token_secret;
     541                            $token        = $meta->oauth_token;
     542                            $token_secret = $meta->oauth_secret;
     543                           
     544                            $consumer->set_user_id( $meta->user_id );
     545                            $consumer->set_blog_id( $meta->blog_id );
    517546                        }
    518547                    }
  • kickpress/trunk/kickpress-redirects.php

    r587972 r595581  
    4444    $blogurl = ((get_option('home')) ? get_option('home') : get_option('siteurl'));
    4545    preg_match('#^[hpst]+://.*?(/.*)$#', $blogurl, $subdir);
     46
     47    kickpress_oauth_authenticate();
    4648
    4749    if ( isset($subdir[1]) ) {
Note: See TracChangeset for help on using the changeset viewer.