forum-oauth-center/src/OAuth.php

60 lines
1.8 KiB
PHP
Raw Normal View History

2023-09-29 09:16:43 +08:00
<?php
2023-09-29 14:49:12 +08:00
/*
* This file is part of foskym/flarum-oauth-center.
*
* Copyright (c) 2023 FoskyM.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
2023-09-29 09:16:43 +08:00
namespace FoskyM\OAuthCenter;
use OAuth2\Server;
use OAuth2\Response;
use OAuth2\Request;
use OAuth2\GrantType\ClientCredentials;
use OAuth2\GrantType\AuthorizationCode;
use OAuth2\GrantType\UserCredentials;
use OAuth2\GrantType\RefreshToken;
2023-09-29 20:50:11 +08:00
use Flarum\Settings\SettingsRepositoryInterface;
2023-09-29 09:16:43 +08:00
class OAuth
{
2023-09-29 20:50:11 +08:00
protected $settings;
public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}
2023-09-29 09:16:43 +08:00
public function response(): Response
{
return new Response;
}
public function request(): Request
{
return new Request;
}
public function storage(): Storage
{
return new Storage;
}
2023-09-29 09:16:43 +08:00
public function server(): Server
{
$storage = new Storage;
$server = new Server($storage, array(
2023-09-29 20:50:11 +08:00
'allow_implicit' => $this->settings->get('foskym-oauth-center.allow_implicit') == "1",
'enforce_state' => $this->settings->get('foskym-oauth-center.enforce_state') == "1",
'require_exact_redirect_uri' => $this->settings->get('foskym-oauth-center.require_exact_redirect_uri') == "1",
'access_lifetime' => $this->settings->get('foskym-oauth-center.access_lifetime') == "" ? 3600 : $this->settings->get('foskym-oauth-center.access_lifetime'),
2023-09-29 09:16:43 +08:00
));
$server->addGrantType(new AuthorizationCode($storage));
$server->addGrantType(new ClientCredentials($storage));
$server->addGrantType(new UserCredentials($storage));
$server->addGrantType(new RefreshToken($storage));
return $server;
}
}