Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/OAuth2ServiceProvider.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Nord\Lumen\OAuth2;
2
3
use Exception;
4
use Illuminate\Contracts\Container\Container;
5
use League\OAuth2\Server\Grant\AbstractGrant;
6
use League\OAuth2\Server\Grant\RefreshTokenGrant;
7
use League\OAuth2\Server\Storage\AuthCodeInterface;
8
use League\OAuth2\Server\Storage\RefreshTokenInterface;
9
use Nord\Lumen\OAuth2\Contracts\OAuth2Service as OAuth2ServiceContract;
10
use Nord\Lumen\OAuth2\Exceptions\InvalidArgument;
11
use Illuminate\Config\Repository as ConfigRepository;
12
use Illuminate\Support\ServiceProvider;
13
use League\OAuth2\Server\AuthorizationServer;
14
use League\OAuth2\Server\Grant\PasswordGrant;
15
use League\OAuth2\Server\ResourceServer;
16
use League\OAuth2\Server\Storage\AccessTokenInterface;
17
use League\OAuth2\Server\Storage\ClientInterface;
18
use League\OAuth2\Server\Storage\ScopeInterface;
19
use League\OAuth2\Server\Storage\SessionInterface;
20
21
class OAuth2ServiceProvider extends ServiceProvider
22
{
23
    const CONFIG_KEY = 'oauth2';
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function register()
29
    {
30
        $this->app->configure(self::CONFIG_KEY);
0 ignored issues
show
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean registerConfiguredProviders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
31
32
        $this->registerBindings($this->app, $this->app['config']);
33
        $this->registerFacades();
34
    }
35
36
37
    /**
38
     * Registers container bindings.
39
     *
40
     * @param Container        $container
41
     * @param ConfigRepository $config
42
     */
43
    protected function registerBindings(Container $container, ConfigRepository $config)
44
    {
45
        $container->bind(OAuth2Service::class, function ($container) use ($config) {
46
            return $this->createService($container, $config[self::CONFIG_KEY]);
47
        });
48
49
        $container->alias(OAuth2Service::class, OAuth2ServiceContract::class);
50
    }
51
52
53
    /**
54
     * Registers facades.
55
     */
56
    protected function registerFacades()
57
    {
58
        if (!class_exists('OAuth2')) {
59
            class_alias(OAuth2Facade::class, 'OAuth2');
60
        }
61
    }
62
63
64
    /**
65
     * Creates the service instance.
66
     *
67
     * @param Container $container
68
     * @param array     $config
69
     *
70
     * @return OAuth2Service
71
     */
72
    protected function createService(Container $container, array $config)
73
    {
74
        $authorizationServer = $this->createAuthorizationServer($container, $config);
75
        $resourceServer      = $this->createResourceServer($container);
76
77
        return new OAuth2Service($authorizationServer, $resourceServer);
78
    }
79
80
81
    /**
82
     * Creates the authorization instance.
83
     *
84
     * @param Container $container
85
     * @param array     $config
86
     *
87
     * @return AuthorizationServer
88
     * @throws Exception
89
     */
90
    protected function createAuthorizationServer(Container $container, array $config)
91
    {
92
        // TODO: Support scopes
93
94
        $authorizationServer = $container->make(AuthorizationServer::class);
95
96
        $authorizationServer->setSessionStorage($container->make(SessionInterface::class));
97
        $authorizationServer->setAccessTokenStorage($container->make(AccessTokenInterface::class));
98
        $authorizationServer->setRefreshTokenStorage($container->make(RefreshTokenInterface::class));
99
        $authorizationServer->setClientStorage($container->make(ClientInterface::class));
100
        $authorizationServer->setScopeStorage($container->make(ScopeInterface::class));
101
        $authorizationServer->setAuthCodeStorage($container->make(AuthCodeInterface::class));
102
103
        $this->configureAuthorizationServer($authorizationServer, $config);
104
105
        return $authorizationServer;
106
    }
107
108
109
    /**
110
     * Configures the authorization server instance.
111
     *
112
     * @param AuthorizationServer $authorizationServer
113
     * @param array               $config
114
     */
115
    protected function configureAuthorizationServer(AuthorizationServer $authorizationServer, array $config)
116
    {
117
        if (isset($config['scope_param'])) {
118
            $authorizationServer->requireScopeParam($config['scope_param']);
119
        }
120
        if (isset($config['default_scope'])) {
121
            $authorizationServer->setDefaultScope($config['default_scope']);
122
        }
123
        if (isset($config['state_param'])) {
124
            $authorizationServer->requireStateParam($config['state_param']);
125
        }
126
        if (isset($config['scope_delimiter'])) {
127
            $authorizationServer->setScopeDelimiter($config['scope_delimiter']);
128
        }
129
        if (isset($config['access_token_ttl'])) {
130
            $authorizationServer->setAccessTokenTTL($config['access_token_ttl']);
131
        }
132
133
        $this->configureGrantTypes($authorizationServer, $config['grant_types']);
134
    }
135
136
137
    /**
138
     * Configures the grant types for the authorization server instance.
139
     *
140
     * @param AuthorizationServer $authorizationServer
141
     * @param array               $config
142
     *
143
     * @throws InvalidArgument
144
     */
145
    protected function configureGrantTypes(AuthorizationServer $authorizationServer, array $config)
146
    {
147
        // TODO: Support configuring of the remaining grant types
148
        foreach ($config as $name => $params) {
149
            if (!isset($params['class']) || !class_exists($params['class'])) {
150
                continue;
151
            }
152
153
            /** @var AbstractGrant $grantType */
154
            $grantType = new $params['class'];
155
156
            if (isset($params['access_token_ttl'])) {
157
                $grantType->setAccessTokenTTL($params['access_token_ttl']);
158
            }
159
160
            if ($grantType instanceof PasswordGrant) {
161
                /** @var PasswordGrant $grantType */
162
                if (isset($params['callback'])) {
163
                    $grantType->setVerifyCredentialsCallback($params['callback']);
164
                }
165
            }
166
167
            if ($grantType instanceof RefreshTokenGrant) {
168
                /** @var RefreshTokenGrant $grantType */
169
                if (isset($params['refresh_token_rotate'])) {
170
                    $grantType->setRefreshTokenRotation($params['refresh_token_rotate']);
171
                }
172
                if (isset($params['refresh_token_ttl'])) {
173
                    $grantType->setRefreshTokenTTL($params['refresh_token_ttl']);
174
                }
175
            }
176
177
            $authorizationServer->addGrantType($grantType);
178
        }
179
    }
180
181
182
    /**
183
     * Creates the resource server.
184
     *
185
     * @param Container $container
186
     *
187
     * @return ResourceServer
188
     */
189
    protected function createResourceServer(Container $container)
190
    {
191
        return $container->make(ResourceServer::class);
192
    }
193
}
194