3 namespace app\Controller\Github
;
5 use app\Controller\Github
;
7 class Callback
extends Github
9 function __invoke(array $args = null) {
10 if ($this->app
->getRequest()->getQuery("error")) {
11 $this->app
->getView()->addData([
12 "error" => $this->app
->getRequest()->getQuery("error_description")
16 $this->github
->fetchToken(
17 $this->app
->getRequest()->getQuery("code"),
18 $this->app
->getRequest()->getQuery("state"),
20 $this->github
->setToken($json->access_token
);
21 $this->github
->fetchUser(function($user) {
22 $this->session
->github
= $user;
25 if (isset($this->session
->returnto
)) {
26 $this->app
->redirect($this->session
->returnto
);
29 $this->app
->getBaseUrl()->mod("./github"));
31 } catch (\app\Github\Exception
$exception) {
32 $this->app
->getView()->addData(compact("exception"));
35 $this->app
->display("github/callback");