remove: patreon api not reliable

This commit is contained in:
Irfan 2021-11-03 17:29:48 +05:00
parent 6a25d5add3
commit 938312c332
5 changed files with 1 additions and 461 deletions

View File

@ -105,13 +105,6 @@ GITHUB_REPORTING=true
GITHUB_REST="jikan-me/jikan-rest"
GITHUB_API="jikan-me/jikan"
###
# Patreon API for fetching backers
###
PATREON=false
PATREON_CLIENT_ID=
PATREON_CLIENT_SECRET=
###
# OpenAPI
###

View File

@ -1,119 +0,0 @@
<?php
namespace App\Http\Controllers\V4DB;
use Dotenv\Dotenv;
use Illuminate\Http\Request;
use Patreon\OAuth;
class PatreonController extends Controller
{
public function login(Request $request)
{
$code = $request->get('code');
if (!empty($code)) {
$oauthClient = new OAuth(env('PATREON_CLIENT_ID'), env('PATREON_CLIENT_SECRET'));
$tokens = $oauthClient->get_tokens($code, env('APP_URL').'/v4/patreon/oauth');
$accessToken = $tokens['access_token'] ?? '';
$refreshToken = $tokens['refresh_token'] ?? '';
}
if (empty($accessToken)) {
return response()->json([
'error' => 'Invalid access token'
], 400);
}
if (env('PATREON') && env('CACHING') && env('CACHE_DRIVER') == 'redis') {
app('redis')->set('patreon:access_token', $accessToken);
app('redis')->set('patreon:refresh_token', $refreshToken);
}
}
public function url(Request $request) {
$href = (new \Patreon\AuthUrl(env('PATREON_CLIENT_ID')))
->withRedirectUri(env('APP_URL').'/v4/patreon/oauth')
->withScopes([
'campaigns', 'campaigns.members', 'identity.memberships'
]);
return response()->json([
'url' => $href->buildUrl()
]);
}
/**
* @throws \Patreon\Exceptions\CurlException
* @throws \Patreon\Exceptions\APIException
* @throws \SodiumException
*/
public function campaigns(Request $request) {
if (env('PATREON') && env('CACHING') && env('CACHE_DRIVER') == 'redis') {
$patreon = new \Patreon\API(app('redis')->get('patreon:access_token'));
$campaigns = $patreon->fetch_campaigns();
return response()->json($campaigns);
}
}
public function pledges(Request $request) {
$campaignId = $request->get('campaign_id');
if (env('PATREON') && env('CACHING') && env('CACHE_DRIVER') == 'redis') {
$patreon = new \Patreon\API(app('redis')->get('patreon:access_token'));
$pledges = $patreon->fetch_page_of_members_from_campaign($campaignId, 100, 0);
// @todo Patreon doesnt return list of all active backers for some reason!
// Need to look into this, might have to scrape or try out webhooks
$pledges = $patreon->get_data(
'campaigns/'.$campaignId.'/members',
[
'page' => [
'count' => 50
],
'include' => 'currently_entitled_tiers',
'fields' => [
'member' => implode(',', [
'full_name',
'patron_status',
'lifetime_support_cents'
]),
'tier' => implode(',', [
'patron_count',
'title'
])
]
]
);
$backers = [];
foreach ($pledges['data'] as $pledge) {
if ($pledge['attributes']['patron_status'] !== 'active_patron') {
continue;
}
$backers[] = [
'full_name' => $pledge['attributes']['full_name'],
'lifetime_support_cents' => $pledge['attributes']['lifetime_support_cents'],
];
}
usort($backers, function ($item1, $item2) {
return $item2['lifetime_support_cents'] <=> $item1['lifetime_support_cents'];
});
foreach ($backers as &$backer) {
$backer = trim($backer['full_name']);
}
return response()->json([
'backers' => implode(", ", $backers)
]);
}
}
}

View File

@ -23,7 +23,6 @@
"ocramius/package-versions": "^1.4",
"predis/predis": "^1.1",
"sentry/sentry-laravel": "^2.8",
"soatok/patreon": "^0.6.0",
"symfony/yaml": "^4.1",
"vlucas/phpdotenv": "^5",
"zircote/swagger-php": "3.*"

312
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "cfe01b9da53b313251ff7b51d90a64e3",
"content-hash": "c8c59f25dfde04727863dd78d18215a1",
"packages": [
{
"name": "brick/math",
@ -3984,262 +3984,6 @@
},
"time": "2021-04-09T13:42:10+00:00"
},
{
"name": "paragonie/constant_time_encoding",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/paragonie/constant_time_encoding.git",
"reference": "f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c",
"reference": "f34c2b11eb9d2c9318e13540a1dbc2a3afbd939c",
"shasum": ""
},
"require": {
"php": "^7|^8"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8|^9",
"vimeo/psalm": "^1|^2|^3|^4"
},
"type": "library",
"autoload": {
"psr-4": {
"ParagonIE\\ConstantTime\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com",
"role": "Maintainer"
},
{
"name": "Steve 'Sc00bz' Thomas",
"email": "steve@tobtu.com",
"homepage": "https://www.tobtu.com",
"role": "Original Developer"
}
],
"description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)",
"keywords": [
"base16",
"base32",
"base32_decode",
"base32_encode",
"base64",
"base64_decode",
"base64_encode",
"bin2hex",
"encoding",
"hex",
"hex2bin",
"rfc4648"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/constant_time_encoding/issues",
"source": "https://github.com/paragonie/constant_time_encoding"
},
"time": "2020-12-06T15:14:20+00:00"
},
{
"name": "paragonie/hidden-string",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/paragonie/hidden-string.git",
"reference": "1c30373ac2fce76fb57954010ef06e990f9a49b5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/hidden-string/zipball/1c30373ac2fce76fb57954010ef06e990f9a49b5",
"reference": "1c30373ac2fce76fb57954010ef06e990f9a49b5",
"shasum": ""
},
"require": {
"paragonie/constant_time_encoding": "^2",
"paragonie/sodium_compat": "^1.6",
"php": "^7|^8"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8|^9",
"vimeo/psalm": "^3|^4"
},
"type": "library",
"autoload": {
"psr-4": {
"ParagonIE\\HiddenString\\": "./src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MPL-2.0"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "info@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "Encapsulate strings in an object to hide them from stack traces",
"homepage": "https://github.com/paragonie/hidden-string",
"keywords": [
"hidden",
"stack trace",
"string"
],
"support": {
"issues": "https://github.com/paragonie/hidden-string/issues",
"source": "https://github.com/paragonie/hidden-string/tree/v1.1.0"
},
"time": "2020-12-03T14:24:26+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v9.99.100",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a",
"shasum": ""
},
"require": {
"php": ">= 7"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*",
"vimeo/psalm": "^1"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"polyfill",
"pseudorandom",
"random"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/random_compat/issues",
"source": "https://github.com/paragonie/random_compat"
},
"time": "2020-10-15T08:29:30+00:00"
},
{
"name": "paragonie/sodium_compat",
"version": "v1.17.0",
"source": {
"type": "git",
"url": "https://github.com/paragonie/sodium_compat.git",
"reference": "c59cac21abbcc0df06a3dd18076450ea4797b321"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/c59cac21abbcc0df06a3dd18076450ea4797b321",
"reference": "c59cac21abbcc0df06a3dd18076450ea4797b321",
"shasum": ""
},
"require": {
"paragonie/random_compat": ">=1",
"php": "^5.2.4|^5.3|^5.4|^5.5|^5.6|^7|^8"
},
"require-dev": {
"phpunit/phpunit": "^3|^4|^5|^6|^7|^8|^9"
},
"suggest": {
"ext-libsodium": "PHP < 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security.",
"ext-sodium": "PHP >= 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security."
},
"type": "library",
"autoload": {
"files": [
"autoload.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"ISC"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com"
},
{
"name": "Frank Denis",
"email": "jedisct1@pureftpd.org"
}
],
"description": "Pure PHP implementation of libsodium; uses the PHP extension if it exists",
"keywords": [
"Authentication",
"BLAKE2b",
"ChaCha20",
"ChaCha20-Poly1305",
"Chapoly",
"Curve25519",
"Ed25519",
"EdDSA",
"Edwards-curve Digital Signature Algorithm",
"Elliptic Curve Diffie-Hellman",
"Poly1305",
"Pure-PHP cryptography",
"RFC 7748",
"RFC 8032",
"Salpoly",
"Salsa20",
"X25519",
"XChaCha20-Poly1305",
"XSalsa20-Poly1305",
"Xchacha20",
"Xsalsa20",
"aead",
"cryptography",
"ecdh",
"elliptic curve",
"elliptic curve cryptography",
"encryption",
"libsodium",
"php",
"public-key cryptography",
"secret-key cryptography",
"side-channel resistant"
],
"support": {
"issues": "https://github.com/paragonie/sodium_compat/issues",
"source": "https://github.com/paragonie/sodium_compat/tree/v1.17.0"
},
"time": "2021-08-10T02:43:50+00:00"
},
{
"name": "php-http/client-common",
"version": "2.4.0",
@ -5771,60 +5515,6 @@
],
"time": "2021-08-08T09:03:08+00:00"
},
{
"name": "soatok/patreon",
"version": "v0.6.0",
"source": {
"type": "git",
"url": "https://github.com/soatok/patreon-php.git",
"reference": "7258eedbe2ee959f057a764c3fb09e3318ebc3cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/soatok/patreon-php/zipball/7258eedbe2ee959f057a764c3fb09e3318ebc3cf",
"reference": "7258eedbe2ee959f057a764c3fb09e3318ebc3cf",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"paragonie/hidden-string": "^1",
"paragonie/sodium_compat": "^1",
"php": ">=7.0.0"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8",
"squizlabs/php_codesniffer": "^3.0",
"vimeo/psalm": "^2|^3"
},
"type": "library",
"autoload": {
"psr-4": {
"Patreon\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Patreon",
"email": "platform-team@patreon.com"
},
{
"name": "Soatok Dreamseeker",
"email": "soatok.dhole@gmail.com",
"homepage": "https://soatok.com"
}
],
"description": "Interact with the Patreon API via OAuth.",
"support": {
"issues": "https://github.com/soatok/patreon-php/issues",
"source": "https://github.com/soatok/patreon-php/tree/master"
},
"time": "2020-05-02T20:04:41+00:00"
},
{
"name": "swagger-api/swagger-ui",
"version": "v3.52.1",

View File

@ -22,29 +22,6 @@ $router->get('/', function () use ($router) {
]);
});
/*$router->group( @todo secure sensitive endpoints
[
'prefix' => 'patreon'
],
function () use ($router) {
$router->get('/oauth', [
'uses' => 'PatreonController@login'
]);
$router->get('/url', [
'uses' => 'PatreonController@url'
]);
$router->get('/campaigns', [
'uses' => 'PatreonController@campaigns'
]);
$router->get('/pledges', [
'uses' => 'PatreonController@pledges'
]);
}
);*/
$router->get('/anime', [
'uses' => 'SearchController@anime'
]);