Git Product home page Git Product logo

oauth-php's Introduction

OAuth-PHP

A PHP Library for OAuth 1 and OAuth 2 workflows.

Installation

composer require dan-rogers/oauth-php

Usage

OAuth 1 Example

  • Use an array of options to create a config for your auth generation.
  • Construct a new OAuth1Config object and use the array as the argument.
  • Construct a new OAuth1 object and use your OAuth1Config object as the argument.
  • Call generateAuthorization().

So long as you have provided the correct information for the OAuth1 step you are on, it will generate a valid auth header.

For more information on OAuth 1 usage see:

#!/usr/bin/php
<?php

use OAuth\OAuth1\OAuth1;
use OAuth\OAuth1\OAuth1Config;

require __DIR__ . '/vendor/autoload.php';

$config  = new OAuth1Config([
    'oauth_callback' => 'https://my_website/my_service/auth',
    'oauth_consumer_key' => 'CONSUMER_KEY',
    'consumer_secret' => 'CONSUMER_SECRET',
    'realm' => 'MY_REALM',
    'oauth_signature_method' => OAuth1Config::HMAC_SHA256,
]);

$oauth = new OAuth1($config);
$auth_header = $oauth->generateAuthorization('https://third_party/token_endpoint', 'POST');

// Example usage using PHP CURL

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'https://third_party/token_endpoint',
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Authorization: ' . $auth_header,
        'Content-Length: 0',
    ],
]);

$response = curl_exec($ch);

oauth-php's People

Contributors

danrvp avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.