public function onHttpRequest(\React\Http\Request $request, $response)
    {
        if ($request->getPath() !== "/auth/github/callback") {
            $response->writeHead(404, ['Content-Type' => 'text/plain']);
            $response->end("Not Found");
            return;
        }

        $query = $request->getQuery();
        if (!isset($query['state']) || !isset($query['code'])) {
            $response->writeHead(200, ['Content-Type' => 'text/plain']);
            $response->end("No Code or State query params found");
            return;
        }

        //If we don't already have a promise for this state, create one
        if (!isset($this->promises[$query['state']])) {
            $deferred                        = new Deferred();
            $this->promises[$query['state']] = $deferred;
        }

        $accessToken = $this->getAccessToken($query['code']);
        if ($accessToken) {
            $email = $this->getEmails($accessToken)[0]->email;
            $this->promises[$query['state']]->resolve(["SUCCESS", ["authid" => $email]]);

        } else {
            $this->promises[$query['state']]->resolve(["FAILURE"]);
        }

        $response->writeHead(200, ['Content-Type' => 'text/html']);
        $response->end("<script>window.close();</script>");


    }
public function onHttpRequest(\React\Http\Request $request, $response)
    {
        if ($request->getPath() !== "/auth/github/callback") {
            $response->writeHead(404, ['Content-Type' => 'text/plain']);
            $response->end("Not Found");
            return;
        }

        $query = $request->getQuery();
        if (!isset($query['state']) || !isset($query['code'])) {
            $response->writeHead(200, ['Content-Type' => 'text/plain']);
            $response->end("No Code or State query params found");
            return;
        }

        //If we don't already have a promise for this state, create one
        if (!isset($this->promises[$query['state']])) {
            $deferred                        = new Deferred();
            $this->promises[$query['state']] = $deferred;
        }

        $accessToken = $this->getAccessToken($query['code']);
        if ($accessToken) {
            $email = $this->getEmails($accessToken)[0]->email;
            $this->promises[$query['state']]->resolve(["SUCCESS", ["authid" => $email]]);

        } else {
            $this->promises[$query['state']]->resolve(["FAILURE"]);
        }

        $response->writeHead(200, ['Content-Type' => 'text/html']);
        $response->end("<script>window.close();</script>");


    }
public function onHttpRequest ( \ React \ Http \ Request $ request , $ response ) { if ( $ request -> getPath ( ) !== "/auth/github/callback" ) { $ response -> writeHead ( 404 , [ 'Content-Type' => 'text/plain' ] ) ; $ response -> end ( "Not Found" ) ; return ; } $ query = $ request -> getQuery ( ) ; if ( ! isset ( $ query [ 'state' ] ) || ! isset ( $ query [ 'code' ] ) ) { $ response -> writeHead ( 200 , [ 'Content-Type' => 'text/plain' ] ) ; $ response -> end ( "No Code or State query params found" ) ; return ; } //If we don't already have a promise for this state, create one if ( ! isset ( $ this -> promises [ $ query [ 'state' ] ] ) ) { $ deferred = new Deferred ( ) ; $ this -> promises [ $ query [ 'state' ] ] = $ deferred ; } $ accessToken = $ this -> getAccessToken ( $ query [ 'code' ] ) ; if ( $ accessToken ) { $ email = $ this -> getEmails ( $ accessToken ) [ 0 ] -> email ; $ this -> promises [ $ query [ 'state' ] ] -> resolve ( [ "SUCCESS" , [ "authid" => $ email ] ] ) ; } else { $ this -> promises [ $ query [ 'state' ] ] -> resolve ( [ "FAILURE" ] ) ; } $ response -> writeHead ( 200 , [ 'Content-Type' => 'text/html' ] ) ; $ response -> end ( "<script>window.close();</script>" ) ; }
Handle process on http request

@param \React\Http\Request $request
@param \React\Http\Request $response
Handle process on http request