PHP extension-oauth

Source: Internet
Author: User
Tags oauth oauth header oauthexception

I. Overview and Installation

This extension provides a binding between the OAuth consumer and the provider. OAuth is an authorization protocol built on HTTP that allows applications to securely access data without having to store user names and passwords.

Pecl/oauth requires PHP 5.1 or later, as well as Ext/hash and Ext/pcre.

If you select Pecl/oauth at build time, you can selectively require libcurl. If you use the Libcurl configuration, you must build HTTPS support.

Information related to installing this PECL extension can be found in the installation section titled PECL Extensions in the manual.

Ii. Examples of Use

<?php$req_url = ' Https://fireeagle.yahooapis.com/oauth/request_token '; $authurl = ' https://fireeagle.yahoo.net/ Oauth/authorize '; $acc _url = ' Https://fireeagle.yahooapis.com/oauth/access_token '; $api _url = ' https:// fireeagle.yahooapis.com/api/0.1 '; $conskey = ' Your_consumer_key '; $conssec = ' Your_consumer_secret '; Session_Start () ;//When state=1 the next request should contain a oauth_token. If not then return 0if (!isset ($_get[' Oauth_token ')) && $_session[' state ']==1) $_session[' state '] = 0;try {$oauth = NE    W OAuth ($conskey, $conssec, Oauth_sig_method_hmacsha1,oauth_auth_type_uri);    $oauth->enabledebug (); if (!isset ($_get[' Oauth_token ')) &&!$_session[' state ') {$request _token_info = $oauth->getrequesttoken (        $req _url);        $_session[' secret '] = $request _token_info[' Oauth_token_secret ');        $_session[' state '] = 1; Header (' Location: '. $authurl. '?        Oauth_token= '. $request _token_info[' Oauth_token ');    Exit } else if ($_session[' state ']==1) {$oauth->settoken ($_get[' Oauth_token '],$_session[' secret ']);        $access _token_info = $oauth->getaccesstoken ($acc _url);        $_session[' state '] = 2;        $_session[' token '] = $access _token_info[' Oauth_token ');    $_session[' secret '] = $access _token_info[' Oauth_token_secret ');    } $oauth->settoken ($_session[' token '],$_session[' secret ');    $oauth->fetch ("$api _url/user.json");    $json = Json_decode ($oauth->getlastresponse ()); Print_r ($json);} catch (Oauthexception $E) {print_r ($E);}? >

Third, correlation function

oauth_get_sbs-generate a signature word's baseline string

oauth_urlencode-encoding URIs as RFC 3986 specifications

Iv. related classes and their member functions

OAuth class

oauth::__construct-Creating an OAuth object

oauth::__destruct-Destruction function

OAuth::d isabledebug-to turn off verbose debugging

OAuth::d isableredirects-off redirection

OAuth::d isablesslchecks-off SSL check

oauth::enabledebug-Enable verbose debugging

oauth::enableredirects-Enable redirection

oauth::enablesslchecks-Enable SSL Check

oauth::fetch-get an OAuth protected resource

oauth::generatesignature-Generate a signature

oauth::getaccesstoken-Get an access token

oauth::getcapath-Obtaining CA Information

Oauth::getlastresponse-get the last response

oauth::getlastresponseheaders-Get header information for the last response

oauth::getlastresponseinfo-getting HTTP information about the last response

oauth::getrequestheader-Generating OAuth header information string signatures

oauth::getrequesttoken-Get a Request token

oauth::setauthtype-Setting the authorization type

oauth::setcapath-Setting the CA path and information

oauth::setnonce-setting the current flag for subsequent requests

oauth::setrequestengine-Setting the target request engine

oauth::setrsacertificate-Setting up RSA certificates

oauth::setsslchecks-tuning a specific SSL request check

oauth::settimestamp-setting timestamps

oauth::settoken-setting tokens and secret

oauth::setversion-Setting the OAuth version

Oauthprovider class

oauthprovider::addrequiredparameter-adding the required parameters

oauthprovider::callconsumerhandler-Call Consumernoncehandler callback function

oauthprovider::calltimestampnoncehandler-Call Timestampnoncehandler callback function

oauthprovider::calltokenhandler-Call Tokennoncehandler callback function

oauthprovider::checkoauthrequest-checking for an OAuth request

oauthprovider::__construct-creating a new Oauthprovider object

oauthprovider::consumerhandler-Setting the Consumerhandler handle callback function

oauthprovider::generatetoken-generates a random token

Oauthprovider::is2leggedendpoint-is2leggedendpoint

oauthprovider::isrequesttokenendpoint-setting Isrequesttokenendpoint

oauthprovider::removerequiredparameter-Remove a required parameter

oauthprovider::reportproblem-reporting Problems

oauthprovider::setparam-setting a parameter

oauthprovider::setrequesttokenpath-Setting the request token path

oauthprovider::timestampnoncehandler-Setting the Timestampnoncehandler handle callback function

oauthprovider::tokenhandler-Setting the Tokenhandler handle callback function

Oauthexception class

Oauthexception-oauthexception class

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.