定制 reb3r/oauth2-server-httpfoundation-bridge 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

reb3r/oauth2-server-httpfoundation-bridge

最新稳定版本:v2.5

Composer 安装命令:

composer require reb3r/oauth2-server-httpfoundation-bridge

包简介

A bridge to HttpFoundation for oauth2-server-php

README 文档

README

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 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. v2.2 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 Christian Reber (christian.reber fujitsu com) for more information

Acknowledgements

Very big "Thank you" goes to Brent Shaffer (https://github.com/bshaffer) for the original version which I forked.

统计信息

  • 总下载量: 47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 47
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-05