public function authorizeCallback() { // If there is an error parameter, show that error $error = $this->request->get('error'); if (!empty($error)) { HtmlPage::renderError5xx(500, "<pre>OAuth Error: " . $this->request->get('error') . "\n" . '<a href="/authorize_callback">Retry</a></pre>'); return; } // Get OAuth2 settings $authorizeUrl = Config::get('oauth.authorization_url'); $clientId = Config::get('oauth.client'); $clientSecret = Config::get('oauth.secret'); $redirectUrl = Config::get('oauth.redirect_uri'); $userAgent = Config::get('oauth.user_agent'); // Prepare OAuth2 client to request an authorization code $client = new Client($clientId, $clientSecret, Client::AUTH_TYPE_AUTHORIZATION_BASIC); $client->setCurlOption(CURLOPT_USERAGENT, $userAgent); // Request an authorization code if there isn't one in the GET // parameter code, if there is one, request an access token $code = $this->request->get('code'); if (empty($code)) { $this->session->delete('accessToken'); $authUrl = $client->getAuthenticationUrl($authorizeUrl, $redirectUrl, array('scope' => 'identity', 'state' => 'As64xA3ueT6sjxiazAA7278yhs6103jx', 'duration' => 'permanent')); header('Location: ' . $authUrl); } else { $this->session->requestOAuth2AccessToken($code); header('Location: /'); return; } }
/** * @return string */ public function getAuthenticationUrl() { $authConf = Config::$a['oauth']['providers'][$this->authProvider]; $callback = sprintf(Config::$a['oauth']['callback'], $this->authProvider); $client = new Client($authConf['clientId'], $authConf['clientSecret'], Client::AUTH_TYPE_AUTHORIZATION_BASIC); return $client->getAuthenticationUrl('https://ssl.reddit.com/api/v1/authorize', $callback, array('scope' => 'identity', 'state' => md5(time() . 'eFdcSA_'))); }
/** * @return string */ public function getAuthenticationUrl() { $authConf = Config::$a['oauth']['providers'][$this->authProvider]; $callback = sprintf(Config::$a['oauth']['callback'], $this->authProvider); $client = new Client($authConf['clientId'], $authConf['clientSecret']); $client->setAccessTokenType(Client::ACCESS_TOKEN_BEARER); return $client->getAuthenticationUrl('https://accounts.google.com/o/oauth2/auth', $callback, array('scope' => 'openid email', 'state' => 'security_token=' . Session::getSessionId())); }
/** * @return string */ public function getAuthenticationUrl() { $authConf = Config::$a['oauth']['providers'][$this->authProvider]; $callback = sprintf(Config::$a['oauth']['callback'], $this->authProvider); $client = new Client($authConf['clientId'], $authConf['clientSecret']); $client->setAccessTokenType(Client::ACCESS_TOKEN_OAUTH); return $client->getAuthenticationUrl('https://api.twitch.tv/kraken/oauth2/authorize', $callback, array('scope' => 'user_read')); }
/** * @Route("/oauth", name="oauth") */ public function oauthAction(Request $request) { $client_test_token = $this->getParameter('oauth.test_token'); if ($client_test_token != NULL) { $this->get('logger')->info("Authenticating with test token"); $session = $request->getSession(); $session->set('oauth_token', $client_test_token); return $this->redirectToRoute('homepage'); } $client_id = $this->getParameter('oauth.client_id'); $client_secret = $this->getParameter('oauth.client_secret'); $base_url = $this->getParameter('oauth.base_url'); $send_url = $base_url . '/oauth/authorize'; $client = new Client($client_id, $client_secret); $redirectUrl = $request->getSchemeAndHttpHost() . $this->get('router')->generate('oauth_callback'); $authUrl = $client->getAuthenticationUrl($send_url, $redirectUrl); $this->get('logger')->info("Redirecting to {$authUrl}"); return new RedirectResponse($authUrl); }
public function getData() { $clientId = $this->getClientId(); $clientSecret = $this->getClientSecret(); $merchantId = $this->getMerchantId(); $amount = $this->getAmount(); $description = $this->getDescription(); $redirectUrl = $this->getRedirectUrl(); $oauth2path = $this->getPath(); define("CLIENT_ID", $clientId); define("CLIENT_SECRET", $clientSecret); define("REDIRECT_URI", $redirectUrl); define("AUTHORIZATION_ENDPOINT", "https://paguei.online/app/api/authorize"); define("TOKEN_ENDPOINT", "https://paguei.online/app/api/token"); $client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET); if (!isset($_GET['code'])) { $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI); header('Location: ' . $auth_url); die('Redirect'); } else { $params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI); $response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code', $params); $info = $response['result']; $client->setAccessToken($info['access_token']); $id = $merchantId; $description = urlencode($description); $urlfetch = 'https://paguei.online/app/api/transfer'; $urlfetch2 = $urlfetch . '/' . $id . '/' . $amount . '/' . $description . '.json'; $response = $client->fetch($urlfetch2); return $response; } }
/** * Get Authorization URL (usually for redirect) * * @param array $params Optional key/value query parameters to send * @return string */ public function getAuthorizationUrl($params = array()) { return $this->client->getAuthenticationUrl($this->getAuthUrl(), $this->redirectUrl, $params); }
public function getAuthenticationUrl($state) { return $this->client->getAuthenticationUrl($this->urls['auth'], $this->redirectUri, ['state' => $state]); }