rtheunissen/oauth2-reddit 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

rtheunissen/oauth2-reddit

Composer 安装命令:

composer require rtheunissen/oauth2-reddit

包简介

Reddit OAuth2 provider for league/oauth2-client

README 文档

README

Build Status Scrutinizer Scrutinizer Coverage Latest Version License Join the chat at https://gitter.im/rtheunissen/oauth2-reddit

This package provides Reddit integration for thephpleague/oauth2-client.

Installation

composer require rtheunissen/oauth2-reddit

Usage

use Rudolf\OAuth2\Client\Provider\Reddit;

$reddit = new Reddit([
    'clientId'      => 'yourClientId',
    'clientSecret'  => 'yourClientSecret',
    'redirectUri'   => 'yourRedirectUri',
    'userAgent'     => 'platform:appid:version, (by /u/username)',
    'scopes'        => ['identity', 'read', ...],
]);

Requesting an access token

There are four different ways to request an access token, and you should be able to determine which to use based on the nature of your application.

Have a read through the Reddit OAuth2 Wiki to find out more.

For web apps, using 'code' and 'state'
$url = $reddit->getAuthorizationUrl([
    'duration' => $duration,  // "permanent" or "temporary" by default
]);

You'll receive both code and state when redirected from Reddit.

$accessToken = $reddit->getAccessToken('authorization_code', [
    'code'  => $code,
    'state' => $state
]);
For scripts intended for personal use, using 'username' and 'password'
$accessToken = $reddit->getAccessToken('password', [
    'username' => $username,
    'password' => $password,
]);
For installed applications

You should generate and save unique ID on your client. The ID should be unique per-device or per-user of your app. A randomized or pseudo-randomized value is acceptable for generating the ID; however, you should retain and re-use the same device_id when renewing your access token.

$accessToken = $reddit->getAccessToken('installed_client', [
    'device_id' => $deviceId,  // 20-30 character ASCII string
]);
For confidential clients (web apps / scripts)
$accessToken = $reddit->getAccessToken('client_credentials');

Refreshing an access token

The only way to get a refresh token is by using the state and code redirect flow, with the duration set as "permanent". The resulting access token will have a valid refreshToken property, which you can use to refresh the token.

Note that the refreshed token won't have a refreshToken field. You should use the same refresh token every time you refresh the current token, and simply update its accessToken and expires properties.

$refreshToken = $reddit->getAccessToken('refresh_token', [
    'refresh_token' => $accessToken->refreshToken
]);

$accessToken->accessToken = $refreshToken->accessToken;
$accessToken->expires = $refreshToken->expires;

// Remember to re-store the refreshed access token at this point

Using the access token

Reddit requires a few authorization headers when making authenticated API requests. These can be accessed using $reddit->getHeaders($token).

Note: The pending v1.0.0 release of thephpleague/oauth2-client will make this easier by providing an authenticated request object which you can adjust for each request.

Until then, you are advised to use either a dedicated HTTP client or the client used by the provider:

$client = $reddit->getHttpClient(); // Guzzle 3

rtheunissen/oauth2-reddit 适用场景与选型建议

rtheunissen/oauth2-reddit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 116.87k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2015 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 rtheunissen/oauth2-reddit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rtheunissen/oauth2-reddit 我们能提供哪些服务?
定制开发 / 二次开发

基于 rtheunissen/oauth2-reddit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 116.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 21
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 10
  • 开发语言: PHP

其他信息

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