GithubHelp home page GithubHelp logo

dalalsunil1986 / oauth2-server-httpfoundation-bridge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bshaffer/oauth2-server-httpfoundation-bridge

0.0 1.0 0.0 39 KB

Integrate HttpFoundation into your oauth2-server library

License: MIT License

PHP 100.00%

oauth2-server-httpfoundation-bridge's Introduction

oauth2-server-httpfoundation-bridge

A bridge to HttpFoundation for oauth2-server-php.

Build Status

oauth2-server-httpfoundation-bridge is a wrapper for oauth2-server-php which returns Symfony\Component\HttpFoundation\Response instead of OAuth2\Response, and uses Symfony\Component\HttpFoundation\Request instead of OAuth2\Request.

If you are integrating OAuth2 into a Silex, Symfony, or Laravel 4 app, (or any app using HttpFoundation), this will make your application much cleaner

Installation

Composer is the best way to install this library. Add this line to composer.json:

{
    "require": {
        "bshaffer/oauth2-server-httpfoundation-bridge": "v1.0",
        ...
    },
    ...
}

And then run composer.phar install

Match tags with the oauth2-server-php library when possible. v1.1 is the latest tag.

Creating the request

Creating the request object is the same as before, except now you use the OAuth2\HttpFoundationBridge\Request class:

$request = OAuth2\HttpFoundationBridge\Request::createFromGlobals();
$app->run($request);

The Request object is now compatible with both HttpFoundation and oauth2-server-php

// getBaseUrl is unique to HttpFoundation
$baseUrl = $request->getBaseUrl();

// call oauth server
$server->grantAccessToken($request);

If the HttpFoundation request already exists, you can use the static createFromRequest function to build the OAuth2\HttpFoundationBridge\Request instance:

use OAuth2\HttpFoundationBridge\Request as BridgeRequest;

// in your controller layer, the $request object is passed in
public function execute(Request $request)
{
    //... (instantiate server/response objects)
    $bridgeRequest = BridgeRequest::createFromRequest($request);
    $server->grantAccessToken($bridgeRequest, $response);
}

Creating the response

The OAuth2\HttpFoundationBridge\Response object extends Symfony\Component\HttpFoundation\JsonResponse, and implements OAuth2\ResponseInterface, allowing you to pass this in and return it from your controllers. In Symfony and Silex, this will be all that is needed to integrate the server:

use OAuth2\HttpFoundationBridge\Response as BridgeResponse;

// in your controller layer, the $request object is passed in
public function execute(Request $request)
{
    //... (instantiate server/response objects)
    $response = new BridgeResponse();
    return $server->handleTokenRequest($request, $response);
}

Note: this object will return JSON. Implement your own class using OAuth2\ResponseInterface to support a different content-type.

Examples

Contact

Please contact Brent Shaffer (bshafs gmail com) for more information

oauth2-server-httpfoundation-bridge's People

Contributors

asierchio avatar barryvdh avatar bshaffer avatar julien-c avatar steffkes 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.