Coder Social home page Coder Social logo

oauth-client's Introduction

Php OAuth Client (Sdk)

tokens table structure :

    CREATE TABLE tokens (
        client_id TEXT NOT NULL PRIMARY KEY,
        client_secret TEXT NOT NULL,
        credentials TEXT NOT NULL,
        type TEXT NOT NULL,
        expires_at datetime
    );

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


require_once 'vendor/autoload.php';


$client_id = 1;
$client_secret = 'DONjJxACnkVqzHPoHOoUmfEmUjnDnXJiT0PuqCzO';

$tokenRepository = new \mhndev\oauthClient\repository\TokenRepositorySqlite(
    (new \mhndev\oauthClient\SqLiteConnection(__DIR__.DIRECTORY_SEPARATOR.'db.sqlite'))->connect()
);

$guzzleClient = new \GuzzleHttp\Client();

$guzzleHandler = new \mhndev\oauthClient\handlers\GuzzleHandler(
    $guzzleClient,
    'http://dev.digipeyk.com:8030'
);

// if you want to pass api ednpoints and you are not going to use default endpoints please pass the third argument as follow:
// consider you can just override as many endpoint as you want, and you are not forced to override all endpoints
$guzzleHandler = new \mhndev\oauthClient\handlers\GuzzleHandler(
    $guzzleClient,
    'http://dev.digipeyk.com:8030',
    ['removeIdentifier' => '/api/removeUserIdentifier']
);

$oauth_client = new \mhndev\oauthClient\Client($guzzleHandler, $tokenRepository);

$token = $oauth_client->getClientToken($client_id, $client_secret);

//register endpoint
$user_register = $oauth_client->register(
    'hamid',
    '123456',
    ['email'=>'[email protected]'],
    $token
);

var_dump($user_register);

// whois endpoint

$user_whoIs = $oauth_client->getWhois(
    'email',
    '[email protected]',
    $token
);


var_dump($user_whoIs);

// get Token Info

$tokenValueObject = new \mhndev\valueObjects\implementations\Token(
    $token->getCredentials(), $token->getType()
);

$tokenInfo = $oauth_client->getTokenInfo($tokenValueObject);

var_dump($tokenInfo);



echo '<br><br><br><br><br>';

// now using mock handler instead as handler

$mockHandler = new \mhndev\oauthClient\handlers\MockHandler();

$oauth_client2 = new \mhndev\oauthClient\Client($mockHandler, $tokenRepository);


$tokenFromMock = $oauth_client2->getClientToken('wefwergderf', 'werwrgfer');

var_dump($tokenFromMock);

$result = $oauth_client2->register(
    'majid',
    '123456',
    ['email' => '[email protected]'],
    new \mhndev\oauthClient\entity\common\Token(
        'Bearer',
        '34r3t354t54tr',
        $client_id,
        $client_secret
    )
);


var_dump($result);

todo : toArray for oauth objects

oauth-client's People

Contributors

halaei avatar majidakbari avatar mhndev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.