[PLUGIN][OAuth2] Add OAuth2 support

This commit is contained in:
Diogo Peralta Cordeiro 2022-01-14 14:30:55 +00:00
parent 559f6d650b
commit 7959ea497b
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
14 changed files with 986 additions and 58 deletions

6
.env
View File

@ -41,3 +41,9 @@ MESSENGER_TRANSPORT_DSN_HIGH=doctrine://default?queue_name=high
MESSENGER_TRANSPORT_DSN_LOW=doctrine://default?queue_name=low MESSENGER_TRANSPORT_DSN_LOW=doctrine://default?queue_name=low
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages # MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
###< symfony/messenger ### ###< symfony/messenger ###
###> trikoder/oauth2-bundle ###
# Fallback OAuth2 encryption key
# Please override this with a secure value: https://oauth2.thephpleague.com/installation/#string-password
OAUTH2_ENCRYPTION_KEY=6cfc355e274dc909f82730c8741eb1e0
###< trikoder/oauth2-bundle ###

View File

@ -20,7 +20,7 @@ class HostMeta extends XrdController
public function setXRD() public function setXRD()
{ {
if (Event::handle('StartHostMetaLinks', [&$this->xrd->links])) { if (Event::handle('StartHostMetaLinks', [&$this->xrd->links]) !== Event::stop) {
Event::handle('EndHostMetaLinks', [&$this->xrd->links]); Event::handle('EndHostMetaLinks', [&$this->xrd->links]);
} }
} }

View File

@ -19,12 +19,11 @@
"lstrojny/functional-php": "^1.17", "lstrojny/functional-php": "^1.17",
"masterminds/html5": "^2.7", "masterminds/html5": "^2.7",
"mf2/mf2": "^0.4.6", "mf2/mf2": "^0.4.6",
"nyholm/psr7": "^1.4",
"odolbeau/phone-number-bundle": "^3.1", "odolbeau/phone-number-bundle": "^3.1",
"oro/doctrine-extensions": "^2.0", "oro/doctrine-extensions": "^2.0",
"php-ds/php-ds": "^1.2", "php-ds/php-ds": "^1.2",
"phpdocumentor/reflection-docblock": "^5.2", "phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "6.*", "sensio/framework-extra-bundle": "^5.5",
"someonewithpc/memcached-polyfill": "^1.0", "someonewithpc/memcached-polyfill": "^1.0",
"someonewithpc/redis-polyfill": "dev-master", "someonewithpc/redis-polyfill": "dev-master",
"symfony/asset": "5.4.*", "symfony/asset": "5.4.*",

623
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "db8e2506856c53c049c3338ab21cfc88", "content-hash": "9c0a2f7b8e803cba4400571f9a087948",
"packages": [ "packages": [
{ {
"name": "alchemy/binary-driver", "name": "alchemy/binary-driver",
@ -221,6 +221,72 @@
], ],
"time": "2021-09-13T08:41:34+00:00" "time": "2021-09-13T08:41:34+00:00"
}, },
{
"name": "defuse/php-encryption",
"version": "v2.3.1",
"source": {
"type": "git",
"url": "https://github.com/defuse/php-encryption.git",
"reference": "77880488b9954b7884c25555c2a0ea9e7053f9d2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/defuse/php-encryption/zipball/77880488b9954b7884c25555c2a0ea9e7053f9d2",
"reference": "77880488b9954b7884c25555c2a0ea9e7053f9d2",
"shasum": ""
},
"require": {
"ext-openssl": "*",
"paragonie/random_compat": ">= 2",
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "^4|^5|^6|^7|^8|^9"
},
"bin": [
"bin/generate-defuse-key"
],
"type": "library",
"autoload": {
"psr-4": {
"Defuse\\Crypto\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Hornby",
"email": "taylor@defuse.ca",
"homepage": "https://defuse.ca/"
},
{
"name": "Scott Arciszewski",
"email": "info@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "Secure PHP Encryption Library",
"keywords": [
"aes",
"authenticated encryption",
"cipher",
"crypto",
"cryptography",
"encrypt",
"encryption",
"openssl",
"security",
"symmetric key cryptography"
],
"support": {
"issues": "https://github.com/defuse/php-encryption/issues",
"source": "https://github.com/defuse/php-encryption/tree/v2.3.1"
},
"time": "2021-04-09T23:57:26+00:00"
},
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
"version": "1.13.2", "version": "1.13.2",
@ -2599,6 +2665,281 @@
}, },
"time": "2021-04-11T16:10:46+00:00" "time": "2021-04-11T16:10:46+00:00"
}, },
{
"name": "lcobucci/clock",
"version": "2.1.0",
"source": {
"type": "git",
"url": "https://github.com/lcobucci/clock.git",
"reference": "903513d28e85376a33385ebc601afd2ee69e5653"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lcobucci/clock/zipball/903513d28e85376a33385ebc601afd2ee69e5653",
"reference": "903513d28e85376a33385ebc601afd2ee69e5653",
"shasum": ""
},
"require": {
"php": "^8.0"
},
"require-dev": {
"infection/infection": "^0.25",
"lcobucci/coding-standard": "^8.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^9.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Lcobucci\\Clock\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Luís Cobucci",
"email": "lcobucci@gmail.com"
}
],
"description": "Yet another clock abstraction",
"support": {
"issues": "https://github.com/lcobucci/clock/issues",
"source": "https://github.com/lcobucci/clock/tree/2.1.0"
},
"funding": [
{
"url": "https://github.com/lcobucci",
"type": "github"
},
{
"url": "https://www.patreon.com/lcobucci",
"type": "patreon"
}
],
"time": "2021-10-31T21:32:07+00:00"
},
{
"name": "lcobucci/jwt",
"version": "4.1.5",
"source": {
"type": "git",
"url": "https://github.com/lcobucci/jwt.git",
"reference": "fe2d89f2eaa7087af4aa166c6f480ef04e000582"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lcobucci/jwt/zipball/fe2d89f2eaa7087af4aa166c6f480ef04e000582",
"reference": "fe2d89f2eaa7087af4aa166c6f480ef04e000582",
"shasum": ""
},
"require": {
"ext-hash": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-sodium": "*",
"lcobucci/clock": "^2.0",
"php": "^7.4 || ^8.0"
},
"require-dev": {
"infection/infection": "^0.21",
"lcobucci/coding-standard": "^6.0",
"mikey179/vfsstream": "^1.6.7",
"phpbench/phpbench": "^1.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/php-invoker": "^3.1",
"phpunit/phpunit": "^9.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Lcobucci\\JWT\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Luís Cobucci",
"email": "lcobucci@gmail.com",
"role": "Developer"
}
],
"description": "A simple library to work with JSON Web Token and JSON Web Signature",
"keywords": [
"JWS",
"jwt"
],
"support": {
"issues": "https://github.com/lcobucci/jwt/issues",
"source": "https://github.com/lcobucci/jwt/tree/4.1.5"
},
"funding": [
{
"url": "https://github.com/lcobucci",
"type": "github"
},
{
"url": "https://www.patreon.com/lcobucci",
"type": "patreon"
}
],
"time": "2021-09-28T19:34:56+00:00"
},
{
"name": "league/event",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/event.git",
"reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/event/zipball/d2cc124cf9a3fab2bb4ff963307f60361ce4d119",
"reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"henrikbjorn/phpspec-code-coverage": "~1.0.1",
"phpspec/phpspec": "^2.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
}
},
"autoload": {
"psr-4": {
"League\\Event\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frank de Jonge",
"email": "info@frenky.net"
}
],
"description": "Event package",
"keywords": [
"emitter",
"event",
"listener"
],
"support": {
"issues": "https://github.com/thephpleague/event/issues",
"source": "https://github.com/thephpleague/event/tree/master"
},
"time": "2018-11-26T11:52:41+00:00"
},
{
"name": "league/oauth2-server",
"version": "8.3.3",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/oauth2-server.git",
"reference": "f5698a3893eda9a17bcd48636990281e7ca77b2a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/oauth2-server/zipball/f5698a3893eda9a17bcd48636990281e7ca77b2a",
"reference": "f5698a3893eda9a17bcd48636990281e7ca77b2a",
"shasum": ""
},
"require": {
"defuse/php-encryption": "^2.2.1",
"ext-json": "*",
"ext-openssl": "*",
"lcobucci/jwt": "^3.4.6 || ^4.0.4",
"league/event": "^2.2",
"php": "^7.2 || ^8.0",
"psr/http-message": "^1.0.1"
},
"replace": {
"league/oauth2server": "*",
"lncd/oauth2": "*"
},
"require-dev": {
"laminas/laminas-diactoros": "^2.4.1",
"phpstan/phpstan": "^0.12.57",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpunit/phpunit": "^8.5.13",
"roave/security-advisories": "dev-master"
},
"type": "library",
"autoload": {
"psr-4": {
"League\\OAuth2\\Server\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alex Bilbie",
"email": "hello@alexbilbie.com",
"homepage": "http://www.alexbilbie.com",
"role": "Developer"
},
{
"name": "Andy Millington",
"email": "andrew@noexceptions.io",
"homepage": "https://www.noexceptions.io",
"role": "Developer"
}
],
"description": "A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.",
"homepage": "https://oauth2.thephpleague.com/",
"keywords": [
"Authentication",
"api",
"auth",
"authorisation",
"authorization",
"oauth",
"oauth 2",
"oauth 2.0",
"oauth2",
"protect",
"resource",
"secure",
"server"
],
"support": {
"issues": "https://github.com/thephpleague/oauth2-server/issues",
"source": "https://github.com/thephpleague/oauth2-server/tree/8.3.3"
},
"funding": [
{
"url": "https://github.com/sephster",
"type": "github"
}
],
"time": "2021-10-11T20:41:49+00:00"
},
{ {
"name": "league/uri-parser", "name": "league/uri-parser",
"version": "1.4.1", "version": "1.4.1",
@ -4625,25 +4966,25 @@
}, },
{ {
"name": "sensio/framework-extra-bundle", "name": "sensio/framework-extra-bundle",
"version": "v6.2.5", "version": "v5.6.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git", "url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git",
"reference": "812b11b75298577984f90758aeb7bdc8ecd22c20" "reference": "430d14c01836b77c28092883d195a43ce413ee32"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/812b11b75298577984f90758aeb7bdc8ecd22c20", "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/430d14c01836b77c28092883d195a43ce413ee32",
"reference": "812b11b75298577984f90758aeb7bdc8ecd22c20", "reference": "430d14c01836b77c28092883d195a43ce413ee32",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/annotations": "^1.0", "doctrine/annotations": "^1.0",
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/config": "^4.4|^5.0|^6.0", "symfony/config": "^4.4|^5.0",
"symfony/dependency-injection": "^4.4|^5.0|^6.0", "symfony/dependency-injection": "^4.4|^5.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0", "symfony/framework-bundle": "^4.4|^5.0",
"symfony/http-kernel": "^4.4|^5.0|^6.0" "symfony/http-kernel": "^4.4|^5.0"
}, },
"conflict": { "conflict": {
"doctrine/doctrine-cache-bundle": "<1.3.1", "doctrine/doctrine-cache-bundle": "<1.3.1",
@ -4653,23 +4994,25 @@
"doctrine/dbal": "^2.10|^3.0", "doctrine/dbal": "^2.10|^3.0",
"doctrine/doctrine-bundle": "^1.11|^2.0", "doctrine/doctrine-bundle": "^1.11|^2.0",
"doctrine/orm": "^2.5", "doctrine/orm": "^2.5",
"symfony/browser-kit": "^4.4|^5.0|^6.0", "nyholm/psr7": "^1.1",
"symfony/doctrine-bridge": "^4.4|^5.0|^6.0", "symfony/browser-kit": "^4.4|^5.0",
"symfony/dom-crawler": "^4.4|^5.0|^6.0", "symfony/doctrine-bridge": "^4.4|^5.0",
"symfony/expression-language": "^4.4|^5.0|^6.0", "symfony/dom-crawler": "^4.4|^5.0",
"symfony/finder": "^4.4|^5.0|^6.0", "symfony/expression-language": "^4.4|^5.0",
"symfony/monolog-bridge": "^4.0|^5.0|^6.0", "symfony/finder": "^4.4|^5.0",
"symfony/monolog-bridge": "^4.0|^5.0",
"symfony/monolog-bundle": "^3.2", "symfony/monolog-bundle": "^3.2",
"symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0", "symfony/phpunit-bridge": "^4.4.9|^5.0.9",
"symfony/security-bundle": "^4.4|^5.0|^6.0", "symfony/psr-http-message-bridge": "^1.1",
"symfony/twig-bundle": "^4.4|^5.0|^6.0", "symfony/security-bundle": "^4.4|^5.0",
"symfony/yaml": "^4.4|^5.0|^6.0", "symfony/twig-bundle": "^4.4|^5.0",
"symfony/yaml": "^4.4|^5.0",
"twig/twig": "^1.34|^2.4|^3.0" "twig/twig": "^1.34|^2.4|^3.0"
}, },
"type": "symfony-bundle", "type": "symfony-bundle",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "6.1.x-dev" "dev-master": "5.6.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -4697,9 +5040,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/sensiolabs/SensioFrameworkExtraBundle/issues", "issues": "https://github.com/sensiolabs/SensioFrameworkExtraBundle/issues",
"source": "https://github.com/sensiolabs/SensioFrameworkExtraBundle/tree/v6.2.5" "source": "https://github.com/sensiolabs/SensioFrameworkExtraBundle/tree/v5.6.1"
}, },
"time": "2022-01-02T16:55:10+00:00" "time": "2020-08-25T19:10:18+00:00"
}, },
{ {
"name": "someonewithpc/memcached-polyfill", "name": "someonewithpc/memcached-polyfill",
@ -8573,6 +8916,94 @@
], ],
"time": "2021-12-25T19:45:36+00:00" "time": "2021-12-25T19:45:36+00:00"
}, },
{
"name": "symfony/psr-http-message-bridge",
"version": "v2.1.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/psr-http-message-bridge.git",
"reference": "22b37c8a3f6b5d94e9cdbd88e1270d96e2f97b34"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/psr-http-message-bridge/zipball/22b37c8a3f6b5d94e9cdbd88e1270d96e2f97b34",
"reference": "22b37c8a3f6b5d94e9cdbd88e1270d96e2f97b34",
"shasum": ""
},
"require": {
"php": ">=7.1",
"psr/http-message": "^1.0",
"symfony/http-foundation": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"nyholm/psr7": "^1.1",
"psr/log": "^1.1 || ^2 || ^3",
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
"symfony/config": "^4.4 || ^5.0 || ^6.0",
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^5.4@dev || ^6.0"
},
"suggest": {
"nyholm/psr7": "For a super lightweight PSR-7/17 implementation"
},
"type": "symfony-bridge",
"extra": {
"branch-alias": {
"dev-main": "2.1-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Bridge\\PsrHttpMessage\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "PSR HTTP message bridge",
"homepage": "http://symfony.com",
"keywords": [
"http",
"http-message",
"psr-17",
"psr-7"
],
"support": {
"issues": "https://github.com/symfony/psr-http-message-bridge/issues",
"source": "https://github.com/symfony/psr-http-message-bridge/tree/v2.1.2"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-11-05T13:13:39+00:00"
},
{ {
"name": "symfony/redis-messenger", "name": "symfony/redis-messenger",
"version": "v5.4.2", "version": "v5.4.2",
@ -10568,6 +10999,88 @@
], ],
"time": "2021-12-29T22:21:17+00:00" "time": "2021-12-29T22:21:17+00:00"
}, },
{
"name": "trikoder/oauth2-bundle",
"version": "v3.2.0",
"source": {
"type": "git",
"url": "https://github.com/trikoder/oauth2-bundle.git",
"reference": "58788136d3856a3e0c7fb41364943af8bc89101c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/trikoder/oauth2-bundle/zipball/58788136d3856a3e0c7fb41364943af8bc89101c",
"reference": "58788136d3856a3e0c7fb41364943af8bc89101c",
"shasum": ""
},
"require": {
"doctrine/doctrine-bundle": "^1.8|^2.0",
"doctrine/orm": "^2.7",
"league/oauth2-server": "^8.0",
"php": ">=7.2",
"psr/http-factory": "^1.0",
"sensio/framework-extra-bundle": "^5.5",
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/psr-http-message-bridge": "^2.0",
"symfony/security-bundle": "^4.4|^5.0"
},
"require-dev": {
"ext-timecop": "*",
"ext-xdebug": "*",
"laminas/laminas-diactoros": "^2.2",
"nyholm/psr7": "^1.2",
"phpunit/phpunit": "^8.5|^9.4",
"symfony/browser-kit": "^4.4|^5.0",
"symfony/phpunit-bridge": "^5.0"
},
"suggest": {
"defuse/php-encryption": "For better performance when doing encryption",
"nelmio/cors-bundle": "For handling CORS requests",
"nyholm/psr7": "For a super lightweight PSR-7/17 implementation"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Trikoder\\Bundle\\OAuth2Bundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Antonio Pauletich",
"email": "antonio.pauletich@trikoder.net"
},
{
"name": "Berislav Balogović",
"email": "berislav.balogovic@trikoder.net"
},
{
"name": "Petar Obradović",
"email": "petar.obradovic@trikoder.net"
}
],
"description": "Symfony bundle which provides OAuth 2.0 authorization/resource server capabilities.",
"homepage": "https://www.trikoder.net/",
"keywords": [
"oauth2"
],
"support": {
"issues": "https://github.com/trikoder/oauth2-bundle/issues",
"source": "https://github.com/trikoder/oauth2-bundle/tree/v3.2.0"
},
"time": "2020-10-26T15:54:32+00:00"
},
{ {
"name": "twig/extra-bundle", "name": "twig/extra-bundle",
"version": "v3.3.7", "version": "v3.3.7",
@ -11775,27 +12288,27 @@
}, },
{ {
"name": "composer/xdebug-handler", "name": "composer/xdebug-handler",
"version": "2.0.4", "version": "3.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/composer/xdebug-handler.git", "url": "https://github.com/composer/xdebug-handler.git",
"reference": "0c1a3925ec58a4ec98e992b9c7d171e9e184be0a" "reference": "12f1b79476638a5615ed00ea6adbb269cec96fd8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/composer/xdebug-handler/zipball/0c1a3925ec58a4ec98e992b9c7d171e9e184be0a", "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/12f1b79476638a5615ed00ea6adbb269cec96fd8",
"reference": "0c1a3925ec58a4ec98e992b9c7d171e9e184be0a", "reference": "12f1b79476638a5615ed00ea6adbb269cec96fd8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"composer/pcre": "^1", "composer/pcre": "^1",
"php": "^5.3.2 || ^7.0 || ^8.0", "php": "^7.2.5 || ^8.0",
"psr/log": "^1 || ^2 || ^3" "psr/log": "^1 || ^2 || ^3"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^1.0", "phpstan/phpstan": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1", "phpstan/phpstan-strict-rules": "^1.1",
"symfony/phpunit-bridge": "^4.2 || ^5.0 || ^6.0" "symfony/phpunit-bridge": "^6.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -11821,7 +12334,7 @@
"support": { "support": {
"irc": "irc://irc.freenode.org/composer", "irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/xdebug-handler/issues", "issues": "https://github.com/composer/xdebug-handler/issues",
"source": "https://github.com/composer/xdebug-handler/tree/2.0.4" "source": "https://github.com/composer/xdebug-handler/tree/3.0.1"
}, },
"funding": [ "funding": [
{ {
@ -11837,7 +12350,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-01-04T17:06:45+00:00" "time": "2022-01-04T18:29:42+00:00"
}, },
{ {
"name": "doctrine/data-fixtures", "name": "doctrine/data-fixtures",
@ -12001,52 +12514,52 @@
}, },
{ {
"name": "friendsofphp/php-cs-fixer", "name": "friendsofphp/php-cs-fixer",
"version": "v3.4.0", "version": "v3.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git",
"reference": "47177af1cfb9dab5d1cc4daf91b7179c2efe7fad" "reference": "333f15e07c866e33e2765e84ba1e0b88e6a3af3b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/47177af1cfb9dab5d1cc4daf91b7179c2efe7fad", "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/333f15e07c866e33e2765e84ba1e0b88e6a3af3b",
"reference": "47177af1cfb9dab5d1cc4daf91b7179c2efe7fad", "reference": "333f15e07c866e33e2765e84ba1e0b88e6a3af3b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"composer/semver": "^3.2", "composer/semver": "^3.2",
"composer/xdebug-handler": "^2.0", "composer/xdebug-handler": "^3.0",
"doctrine/annotations": "^1.12", "doctrine/annotations": "^1.13",
"ext-json": "*", "ext-json": "*",
"ext-tokenizer": "*", "ext-tokenizer": "*",
"php": "^7.2.5 || ^8.0", "php": "^7.4 || ^8.0",
"php-cs-fixer/diff": "^2.0", "php-cs-fixer/diff": "^2.0",
"symfony/console": "^4.4.20 || ^5.1.3 || ^6.0", "symfony/console": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^4.4.20 || ^5.0 || ^6.0", "symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/filesystem": "^4.4.20 || ^5.0 || ^6.0", "symfony/filesystem": "^5.4 || ^6.0",
"symfony/finder": "^4.4.20 || ^5.0 || ^6.0", "symfony/finder": "^5.4 || ^6.0",
"symfony/options-resolver": "^4.4.20 || ^5.0 || ^6.0", "symfony/options-resolver": "^5.4 || ^6.0",
"symfony/polyfill-mbstring": "^1.23", "symfony/polyfill-mbstring": "^1.23",
"symfony/polyfill-php80": "^1.23", "symfony/polyfill-php80": "^1.23",
"symfony/polyfill-php81": "^1.23", "symfony/polyfill-php81": "^1.23",
"symfony/process": "^4.4.20 || ^5.0 || ^6.0", "symfony/process": "^5.4 || ^6.0",
"symfony/stopwatch": "^4.4.20 || ^5.0 || ^6.0" "symfony/stopwatch": "^5.4 || ^6.0"
}, },
"require-dev": { "require-dev": {
"justinrainbow/json-schema": "^5.2", "justinrainbow/json-schema": "^5.2",
"keradus/cli-executor": "^1.5", "keradus/cli-executor": "^1.5",
"mikey179/vfsstream": "^1.6.8", "mikey179/vfsstream": "^1.6.10",
"php-coveralls/php-coveralls": "^2.5.2", "php-coveralls/php-coveralls": "^2.5.2",
"php-cs-fixer/accessible-object": "^1.1", "php-cs-fixer/accessible-object": "^1.1",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2", "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1",
"phpspec/prophecy": "^1.15", "phpspec/prophecy": "^1.15",
"phpspec/prophecy-phpunit": "^1.1 || ^2.0", "phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^8.5.21 || ^9.5", "phpunit/phpunit": "^9.5",
"phpunitgoodpractices/polyfill": "^1.5", "phpunitgoodpractices/polyfill": "^1.5",
"phpunitgoodpractices/traits": "^1.9.1", "phpunitgoodpractices/traits": "^1.9.1",
"symfony/phpunit-bridge": "^5.2.4 || ^6.0", "symfony/phpunit-bridge": "^6.0",
"symfony/yaml": "^4.4.20 || ^5.0 || ^6.0" "symfony/yaml": "^5.4 || ^6.0"
}, },
"suggest": { "suggest": {
"ext-dom": "For handling output formats in XML", "ext-dom": "For handling output formats in XML",
@ -12078,7 +12591,7 @@
"description": "A tool to automatically fix PHP code style", "description": "A tool to automatically fix PHP code style",
"support": { "support": {
"issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues", "issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues",
"source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v3.4.0" "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v3.5.0"
}, },
"funding": [ "funding": [
{ {
@ -12086,7 +12599,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2021-12-11T16:25:08+00:00" "time": "2022-01-14T00:29:20+00:00"
}, },
{ {
"name": "jchook/phpunit-assert-throws", "name": "jchook/phpunit-assert-throws",
@ -12444,12 +12957,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "66b515292c080298a44a2cd15680711f706ca7bf" "reference": "15bcf0390f49f393d20e21c16672d732356ba692"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/66b515292c080298a44a2cd15680711f706ca7bf", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/15bcf0390f49f393d20e21c16672d732356ba692",
"reference": "66b515292c080298a44a2cd15680711f706ca7bf", "reference": "15bcf0390f49f393d20e21c16672d732356ba692",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -12501,7 +13014,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-01-12T13:05:10+00:00" "time": "2022-01-14T12:36:03+00:00"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",

View File

@ -21,4 +21,5 @@ return [
SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true], SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true],
Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true], Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true],
Fidry\PsyshBundle\PsyshBundle::class => ['all' => true], Fidry\PsyshBundle\PsyshBundle::class => ['all' => true],
Trikoder\Bundle\OAuth2Bundle\TrikoderOAuth2Bundle::class => ['all' => true],
]; ];

View File

@ -42,6 +42,14 @@ security:
samesite: '%remember_me_samesite%' samesite: '%remember_me_samesite%'
token_provider: 'Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider' token_provider: 'Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider'
api_token:
pattern: ^/oauth/token$
security: false
api:
pattern: ^/api
security: true
stateless: true
# activate different ways to authenticate # activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication # https://symfony.com/doc/current/security.html#firewalls-authentication
@ -53,3 +61,4 @@ security:
access_control: access_control:
- { path: ^/admin, roles: ROLE_ADMIN } - { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/settings, roles: ROLE_USER } - { path: ^/settings, roles: ROLE_USER }
- { path: ^/authorize, roles: IS_AUTHENTICATED_REMEMBERED }

View File

@ -0,0 +1,13 @@
trikoder_oauth2:
authorization_server:
private_key: '%kernel.project_dir%/var/oauth/private.key'
private_key_passphrase: null # Passphrase of the private key, if any
encryption_key: '%env(string:OAUTH2_ENCRYPTION_KEY)%' # (Optional) Change this
resource_server:
public_key: '%kernel.project_dir%/var/oauth/public.key'
persistence:
doctrine: null

View File

@ -0,0 +1,3 @@
oauth2:
resource: '@TrikoderOAuth2Bundle/Resources/config/routes.xml'
prefix: '/oauth'

View File

@ -0,0 +1,106 @@
<?php
declare(strict_types = 1);
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
/**
* ActivityPub implementation for GNU social
*
* @package OAuth2
* @category API
*
* @author Diogo Peralta Cordeiro <@diogo.site>
* @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
namespace Plugin\OAuth2\Controller;
use App\Core\Controller;
use App\Core\DB\DB;
use App\Core\Log;
use App\Util\Common;
use Plugin\OAuth2\Entity\OAuth2ClientMeta;
use Symfony\Component\HttpFoundation\JsonResponse;
use Trikoder\Bundle\OAuth2Bundle\Model\Client;
use Trikoder\Bundle\OAuth2Bundle\Model\Grant;
use Trikoder\Bundle\OAuth2Bundle\Model\RedirectUri;
use Trikoder\Bundle\OAuth2Bundle\Model\Scope;
/**
* App Management Endpoint
*
* @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Apps extends Controller
{
public function onPost(): JsonResponse
{
Log::debug('OAuth2 Apps: Received a POST request.');
Log::debug('OAuth2 Apps: Request content: ', [$body = $this->request->getContent()]);
$args = json_decode($body, true);
$identifier = hash('md5', random_bytes(16)); // Random string Length should be between 43 and 128
$secret = Common::base64url_encode(hash('sha256', random_bytes(57)));
$client = new Client($identifier, $secret);
$client->setActive(true);
$client->setAllowPlainTextPkce(false);
$redirectUris = array_map(
static fn (string $redirectUri): RedirectUri => new RedirectUri($redirectUri),
explode(' ', $args['redirect_uris']),
);
$client->setRedirectUris(...$redirectUris);
$client->setGrants(new Grant('client_credentials'));
$scopes = array_map(
static fn (string $scope): Scope => new Scope($scope),
explode(' ', $args['scopes']),
);
$client->setScopes(...$scopes);
DB::persist($client);
DB::persist($additional_meta = OAuth2ClientMeta::create([
'identifier' => $client->getIdentifier(),
'client_name' => $args['client_name'],
'website' => $args['website'],
]));
Log::debug('OAuth2 Apps: Created App: ', [$client, $additional_meta]);
$app_meta = [
'id' => (string) $additional_meta->getId(),
'name' => $additional_meta->getClientName(),
'website' => $additional_meta->getWebsite(),
'redirect_uri' => (string) $client->getRedirectUris()[0],
'client_id' => $client->getIdentifier(),
'client_secret' => $client->getSecret(),
];
Log::debug('OAuth2 Apps: Create App Meta: ', [$app_meta]);
DB::flush();
// Success
return new JsonResponse($app_meta, status: 200, headers: ['content_type' => 'application/json; charset=utf-8']);
}
}

View File

@ -0,0 +1,144 @@
<?php
declare(strict_types = 1);
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
/**
* ActivityPub implementation for GNU social
*
* @package GNUsocial
* @category OAuth2
*
* @author Diogo Peralta Cordeiro <@diogo.site>
* @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
namespace Plugin\OAuth2\Entity;
use App\Core\Entity;
use DateTimeInterface;
/**
* OAuth application registration record
*
* @copyright 2018-2019, 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class OAuth2ClientMeta extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $id;
private string $identifier;
private string $client_name;
private ?string $website = null;
private DateTimeInterface $created;
private DateTimeInterface $modified;
public function getId(): int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getIdentifier(): string
{
return $this->identifier;
}
public function setIdentifier(string $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getClientName(): string
{
return $this->client_name;
}
public function setClientName(string $client_name): self
{
$this->client_name = $client_name;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): self
{
$this->website = $website;
return $this;
}
public function setCreated(DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getCreated(): DateTimeInterface
{
return $this->created;
}
public function setModified(DateTimeInterface $modified): self
{
$this->modified = $modified;
return $this;
}
public function getModified(): DateTimeInterface
{
return $this->modified;
}
// @codeCoverageIgnoreEnd
// }}} Autocode
/**
* Return table definition for Schema setup and Entity usage.
*
* @return array array of column definitions
*/
public static function schemaDef(): array
{
return [
'name' => 'oauth2_client_meta',
'fields' => [
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
'identifier' => ['type' => 'varchar', 'length' => 32, 'description' => 'foreign key to oauth2_client->identifier'],
'client_name' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'name of the application'],
'website' => ['type' => 'text', 'not null' => false, 'description' => 'application homepage - used for source link'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['id'],
];
}
}

83
plugins/OAuth2/OAuth2.php Normal file
View File

@ -0,0 +1,83 @@
<?php
declare(strict_types = 1);
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
/**
* ActivityPub implementation for GNU social
*
* @package GNUsocial
* @category API
*
* @author Diogo Peralta Cordeiro <@diogo.site>
* @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
namespace Plugin\OAuth2;
use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Core\Router\RouteLoader;
use App\Core\Router\Router;
use Plugin\OAuth2\Controller\Apps;
use XML_XRD_Element_Link;
/**
* Adds OAuth2 support to GNU social when enabled
*
* @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class OAuth2 extends Plugin
{
public const OAUTH_ACCESS_TOKEN_REL = 'http://apinamespace.org/oauth/access_token';
public const OAUTH_REQUEST_TOKEN_REL = 'http://apinamespace.org/oauth/request_token';
public const OAUTH_AUTHORIZE_REL = 'http://apinamespace.org/oauth/authorize';
public function version(): string
{
return '3.0.0';
}
/**
* This code executes when GNU social creates the page routing, and we hook
* on this event to add our Inbox and Outbox handler for ActivityPub.
*
* @param RouteLoader $r the router that was initialized
*/
public function onAddRoute(RouteLoader $r): bool
{
$r->connect(
'oauth2_apps',
'/api/v1/apps',
Apps::class,
['http-methods' => ['POST']],
);
return Event::next;
}
public function onEndHostMetaLinks(array &$links): bool
{
$links[] = new XML_XRD_Element_link(self::OAUTH_REQUEST_TOKEN_REL, Router::url('oauth2_apps', type: Router::ABSOLUTE_URL));
$links[] = new XML_XRD_Element_link(self::OAUTH_AUTHORIZE_REL, Router::url('oauth2_authorize', type: Router::ABSOLUTE_URL));
$links[] = new XML_XRD_Element_link(self::OAUTH_ACCESS_TOKEN_REL, Router::url('oauth2_token', type: Router::ABSOLUTE_URL));
return Event::next;
}
}

View File

@ -0,0 +1,6 @@
{
"require": {
"nyholm/psr7": "*",
"trikoder/oauth2-bundle": "*"
}
}

View File

@ -325,4 +325,18 @@ abstract class Common
{ {
return self::actor()?->getTopLanguage() ?? Language::getByLocale(self::$request->headers->has('accept-language') ? I18n::clientPreferredLanguage(self::$request->headers->get('accept-language')) : self::config('site', 'language')); return self::actor()?->getTopLanguage() ?? Language::getByLocale(self::$request->headers->has('accept-language') ? I18n::clientPreferredLanguage(self::$request->headers->get('accept-language')) : self::config('site', 'language'));
} }
// Convert the ArrayBuffer to string using Uint8 array.
// btoa takes chars from 0-255 and base64 encodes.
// Then convert the base64 encoded to base64url encoded.
// (replace + with -, replace / with _, trim trailing =)
public static function base64url_encode(string $data): string
{
return rtrim(strtr(strtr(base64_encode($data), '+', '-'), '/', '_'), '=');
}
public static function base64url_decode(string $data): string
{
return base64_decode(str_pad(strtr(strtr($data, '_', '/'), '-', '+'), \mb_strlen($data) % 4, '=', \STR_PAD_RIGHT));
}
} }

View File

@ -65,6 +65,9 @@
"composer/xdebug-handler": { "composer/xdebug-handler": {
"version": "1.4.6" "version": "1.4.6"
}, },
"defuse/php-encryption": {
"version": "v2.3.1"
},
"doctrine/annotations": { "doctrine/annotations": {
"version": "1.0", "version": "1.0",
"recipe": { "recipe": {
@ -223,6 +226,18 @@
"landrok/activitypub": { "landrok/activitypub": {
"version": "0.5.6" "version": "0.5.6"
}, },
"lcobucci/clock": {
"version": "2.1.0"
},
"lcobucci/jwt": {
"version": "4.1.5"
},
"league/event": {
"version": "2.2.0"
},
"league/oauth2-server": {
"version": "8.3.3"
},
"league/uri-parser": { "league/uri-parser": {
"version": "1.4.1" "version": "1.4.1"
}, },
@ -704,6 +719,9 @@
"symfony/proxy-manager-bridge": { "symfony/proxy-manager-bridge": {
"version": "v5.2.4" "version": "v5.2.4"
}, },
"symfony/psr-http-message-bridge": {
"version": "v2.1.2"
},
"symfony/redis-messenger": { "symfony/redis-messenger": {
"version": "v5.4.0" "version": "v5.4.0"
}, },
@ -862,6 +880,19 @@
"theseer/tokenizer": { "theseer/tokenizer": {
"version": "1.2.0" "version": "1.2.0"
}, },
"trikoder/oauth2-bundle": {
"version": "3.2",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "master",
"version": "3.0",
"ref": "43774de114904e86d18de0cea92f368d8e3c7499"
},
"files": [
"config/packages/trikoder_oauth2.yaml",
"config/routes/trikoder_oauth2.yaml"
]
},
"twig/extra-bundle": { "twig/extra-bundle": {
"version": "v3.3.0" "version": "v3.3.0"
}, },