private function credentials($type) { $api = new OAuth2Service(); $server = $api->init($type); $req = Request::createFromGlobals(); $result = $server->handleTokenRequest($req); $params = $result->getParameters(); if ($result->getStatusCode() != 200) { $this->ajaxReturn(array('code' => $result->getStatusCode(), 'info' => $params), "json"); } else { $this->ajaxReturn(array('code' => 0, 'info' => $params), "json"); } }
public function authorize() { $api = new OAuth2Service(); $server = $api->init(OAuth2Service::ALL); if (!$server->verifyResourceRequest(Request::createFromGlobals())) { $resp = $server->getResponse(); $params = $resp->getParameters(); return array('status' => $resp->getStatusCode(), 'info' => $params['error_description']); //,"json"); } return array('status' => 0, 'info' => '你通过了Api的验证'); //,"json"); }
private function authorization_code($client_id, $state, $redirect_uri) { $oauth2 = new OAuth2Service(); $server = $oauth2->init(OAuth2Service::AUTHORIZATION_CODE); $request = Request::createFromGlobals(); $response = new Response(); // validate the authorize request if (!$server->validateAuthorizeRequest($request, $response)) { $params = $response->getParameters(); $this->apiReturnErr($params); // $response->send(); die; } // display an authorization form if (empty($_POST)) { $clients = apiCall(ClientsApi::GET_INFO, array(array('client_id' => $client_id))); if (!$clients['status']) { $this->apiReturnErr($clients['info']); } $client_name = $clients['info']['client_name']; $this->assign("client_name", $client_name); echo $this->fetch("partials/login"); exit; } // print the authorization code if the user has authorized your client $is_authorized = $_POST['authorized'] === 'yes'; $server->handleAuthorizeRequest($request, $response, $is_authorized); if ($is_authorized) { // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40); redirect($redirect_uri . '?code=' . $code . '&state=' . $state); } $params = $response->getParameters(); $this->apiReturnErr($params); }