forked from danielbcorreia/CakePHP-OAuth2-Server-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OAuth2ServerController.php
53 lines (48 loc) · 1.36 KB
/
OAuth2ServerController.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
<?php
class OAuth2ServerController extends OAuth2ServerAppController {
public $uses = array();
/**
* isAuthorized() callback.
* Allow anonymous access to all actions of this controller.
*/
public function isAuthorized() {
return true;
}
/**
* Issue a new access_token to a formerly anonymous user.
* Used by apps to authenticate via RESTful APIs.
*/
public function access_token() {
try {
$this->OAuth2Lib->grantAccessToken();
} catch(Exception $e) {
$this->fail($e);
}
}
/**
* Display an HTML login form to end-user.
* Used by third-party apps to authenticate via web browser. (Part 1 of 2)
*/
public function login() {
$this->helpers[] = 'Form';
}
/**
* Issue a new access_token to a formerly anonymous user.
* Used by third-party apps to authenticate via web browser. (Part 2 of 2)
*/
public function authorize() {
try {
$this->OAuth2Lib->finish_client_authorization(
(boolean) $this->OAuth2Lib->check_user_credentials($this->params['form']['client_id'], $this->params['form']['username'], $this->params['form']['password']),
$this->params['form']['response_type'],
$this->params['form']['client_id'],
$this->params['form']['redirect_uri'],
$this->params['form']['state'],
$this->params['form']['scope'],
$this->params['form']['username']
);
} catch(Exception $e) {
$this->fail($e);
}
}
}