This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
ConfigProvider.php
103 lines (97 loc) · 4.61 KB
/
ConfigProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @see https://github.com/zendframework/zend-expressive-authentication-oauth2 for the canonical source repository
* @copyright Copyright (c) 2017-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-authentication-oauth2/blob/master/LICENSE.md
* New BSD License
*/
declare(strict_types=1);
namespace Zend\Expressive\Authentication\OAuth2;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Grant\AuthCodeGrant;
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
use League\OAuth2\Server\Grant\ImplicitGrant;
use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Grant\RefreshTokenGrant;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use League\OAuth2\Server\ResourceServer;
use Zend\Expressive\Authentication\AuthenticationInterface;
use Zend\Expressive\Authentication\OAuth2\Grant\AuthCodeGrantFactory;
use Zend\Expressive\Authentication\OAuth2\Grant\ClientCredentialsGrantFactory;
use Zend\Expressive\Authentication\OAuth2\Grant\ImplicitGrantFactory;
use Zend\Expressive\Authentication\OAuth2\Grant\PasswordGrantFactory;
use Zend\Expressive\Authentication\OAuth2\Grant\RefreshTokenGrantFactory;
use Zend\Expressive\Authentication\OAuth2\Repository\Pdo;
/**
* @codeCoverageIgnore
*/
class ConfigProvider
{
/**
* Return the configuration array.
*/
public function __invoke() : array
{
return [
'dependencies' => $this->getDependencies(),
'authentication' => include __DIR__ . '/../config/oauth2.php',
'routes' => $this->getRoutes()
];
}
/**
* Returns the container dependencies
*/
public function getDependencies() : array
{
return [
'aliases' => [
// Choose a different adapter changing the alias value
AccessTokenRepositoryInterface::class => Pdo\AccessTokenRepository::class,
AuthCodeRepositoryInterface::class => Pdo\AuthCodeRepository::class,
ClientRepositoryInterface::class => Pdo\ClientRepository::class,
RefreshTokenRepositoryInterface::class => Pdo\RefreshTokenRepository::class,
ScopeRepositoryInterface::class => Pdo\ScopeRepository::class,
UserRepositoryInterface::class => Pdo\UserRepository::class,
AuthenticationInterface::class => OAuth2Adapter::class
],
'factories' => [
AuthorizationMiddleware::class => AuthorizationMiddlewareFactory::class,
AuthorizationHandler::class => AuthorizationServerFactory::class,
TokenEndpointHandler::class => TokenEndpointHandlerFactory::class,
OAuth2Adapter::class => OAuth2AdapterFactory::class,
AuthorizationServer::class => AuthorizationServerFactory::class,
ResourceServer::class => ResourceServerFactory::class,
// Pdo adapter
Pdo\PdoService::class => Pdo\PdoServiceFactory::class,
Pdo\AccessTokenRepository::class => Pdo\AccessTokenRepositoryFactory::class,
Pdo\AuthCodeRepository::class => Pdo\AuthCodeRepositoryFactory::class,
Pdo\ClientRepository::class => Pdo\ClientRepositoryFactory::class,
Pdo\RefreshTokenRepository::class => Pdo\RefreshTokenRepositoryFactory::class,
Pdo\ScopeRepository::class => Pdo\ScopeRepositoryFactory::class,
Pdo\UserRepository::class => Pdo\UserRepositoryFactory::class,
// Default Grants
ClientCredentialsGrant::class => ClientCredentialsGrantFactory::class,
PasswordGrant::class => PasswordGrantFactory::class,
AuthCodeGrant::class => AuthCodeGrantFactory::class,
ImplicitGrant::class => ImplicitGrantFactory::class,
RefreshTokenGrant::class => RefreshTokenGrantFactory::class,
]
];
}
public function getRoutes() : array
{
return [
[
'name' => 'oauth',
'path' => '/oauth',
'middleware' => AuthorizationMiddleware::class,
'allowed_methods' => ['GET', 'POST']
],
];
}
}