Issues (29)

Controller/UniLoginController.php (7 issues)

1
<?php
2
App::uses('UniLoginUtil', 'UniLogin.Lib');
3
4
/**
5
 * UniLogin Controller.
6
 *
7
 */
8
class UniLoginController extends UniLoginAppController {
9
10
/**
11
 * An array of names of models to load.
12
 *
13
 * @var array
14
 */
15
	public $uses = [];
16
17
/**
18
 * Starts the Uni-Login login process (by redirecting the user to the authentication provider).
19
 *
20
 * @return \Cake\Network\Response|null
0 ignored issues
show
The type Cake\Network\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
 */
22
	public function login() {
23
		// Default callback url
24
		$url = ['action' => 'callback'];
25
		$returnUrl = $this->request->query('returnUrl');
26
		if ($returnUrl) {
27
			$path = parse_url($returnUrl, PHP_URL_PATH);
28
			$url['?'] = [
29
				'returnUrl' => $path,
30
			];
31
		}
32
33
		$url = Router::url($url, true);
0 ignored issues
show
The type Router was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
35
		$query = [
36
			'path' => UniLoginUtil::encodeUrl($url),
37
			'auth' => UniLoginUtil::calculateUrlFingerprint($url),
38
			'id' => Configure::read('UniLogin.provider.applicationId')
0 ignored issues
show
The type Configure was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
		];
40
41
		$redirectUrl = Configure::read('UniLogin.provider.url');
42
		$redirectUrl .= '?' . http_build_query($query);
43
44
		return $this->redirect($redirectUrl);
45
	}
46
47
/**
48
 * Receives auth response and does validation.
49
 *
50
 * @return void
51
 */
52
	public function callback() {
53
		$response = $this->request->query;
54
55
		$user = $this->request->query('user');
56
		$timestamp = $this->request->query('timestamp');
57
		$auth = $this->request->query('auth');
58
59
		$fingerprint = UniLoginUtil::calculateFingerprint($timestamp, $user);
60
61
		if ($user && $timestamp && $auth && UniLoginUtil::validateFingerprint($timestamp, $user, $fingerprint)) {
62
			$response['validated'] = true;
63
		} else {
64
			$response['validated'] = false;
65
		}
66
67
		$completeUrl = Configure::read('UniLogin.application.completeUrl');
68
69
		$returnUrl = $this->request->query('returnUrl');
70
		if ($returnUrl) {
71
			$path = parse_url($returnUrl, PHP_URL_PATH);
72
			$completeUrl = $path;
73
		}
74
75
		$response['hmac'] = UniLoginUtil::hmac($response);
76
77
		return $this->_dispatch($completeUrl, $response);
0 ignored issues
show
Are you sure the usage of $this->_dispatch($completeUrl, $response) targeting UniLoginController::_dispatch() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
78
	}
79
80
/**
81
 * Redirects user to action in application with validated response data available as POST data retrievable at
82
 * $this->request->data` at your app's controller.
83
 *
84
 * @param string $url Url in application to dispatch to
85
 * @param array $data A list with post data
86
 * @return void
87
 */
88
	protected function _dispatch($url, $data) {
89
		$CakeRequest = new CakeRequest($url);
0 ignored issues
show
The type CakeRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
90
		$CakeRequest->data = $data;
91
92
		$Dispatcher = new Dispatcher();
0 ignored issues
show
The type Dispatcher was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
		$Dispatcher->dispatch($CakeRequest, new CakeResponse());
0 ignored issues
show
The type CakeResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
94
95
		$this->_stop();
96
	}
97
}
98