/** * ********************************************** * Request Verification Code * https://msdn.microsoft.com/en-us/library/ff749592.aspx * * The following example shows a URL that enables * a user to provide consent to an application by * using a Windows Live ID. * * When successful, this URL returns the user to * your application, along with a verification * code. * ********************************************** */ public function requestVerificationCode($transactionId) { $params = array('response_type' => 'code', 'redirect_uri' => urlencode($this->getCallbackUri()), 'client_id' => $this->getClientId(), 'client_secret' => $this->getClientSecret(), 'scope' => urlencode(self::SCOPE), 'access_type' => 'offline', 'approval_prompt' => 'force'); $authUrl = $this->getAuthorizationUrl() . '?' . build_query($params); $this->getLogger()->debug('Requesting verification code from Microsoft'); PostmanUtils::redirect($authUrl); }
/** * The authorization sequence begins when your application redirects a browser to a Google URL; * the URL includes query parameters that indicate the type of access being requested. * * As in other scenarios, Google handles user authentication, session selection, and user consent. * The result is an authorization code, which Google returns to your application in a query string. * * (non-PHPdoc) * * @see PostmanAuthenticationManager::requestVerificationCode() */ public function requestVerificationCode($transactionId) { $params = array('response_type' => 'code', 'redirect_uri' => urlencode($this->getCallbackUri()), 'client_id' => $this->getClientId(), 'state' => $transactionId, 'language' => get_locale()); $authUrl = $this->getAuthorizationUrl() . '?' . build_query($params); $this->getLogger()->debug('Requesting verification code from Yahoo'); PostmanUtils::redirect($authUrl); }
/** * The authorization sequence begins when your application redirects a browser to a Google URL; * the URL includes query parameters that indicate the type of access being requested. * * As in other scenarios, Google handles user authentication, session selection, and user consent. * The result is an authorization code, which Google returns to your application in a query string. * * (non-PHPdoc) * * @see PostmanAuthenticationManager::requestVerificationCode() */ public function requestVerificationCode($transactionId) { $params = array('response_type' => 'code', 'redirect_uri' => urlencode($this->getCallbackUri()), 'client_id' => $this->getClientId(), 'scope' => urlencode(self::SCOPE_FULL_ACCESS), 'access_type' => 'offline', 'approval_prompt' => 'force', 'state' => $transactionId, 'login_hint' => $this->senderEmail); $authUrl = $this->getAuthorizationUrl() . '?' . build_query($params); $this->getLogger()->debug('Requesting verification code from Google'); PostmanUtils::redirect($authUrl); }
/** * Handles the authorization grant */ function handleAuthorizationGrant() { $logger = $this->logger; $options = $this->options; $authorizationToken = $this->authorizationToken; $logger->debug('Authorization in progress'); $transactionId = PostmanSession::getInstance()->getOauthInProgress(); // begin transaction PostmanUtils::lock(); $authenticationManager = PostmanAuthenticationManagerFactory::getInstance()->createAuthenticationManager(PostmanTransportRegistry::getInstance()->getCurrentTransport(), $options, $authorizationToken); try { if ($authenticationManager->processAuthorizationGrantCode($transactionId)) { $logger->debug('Authorization successful'); // save to database $authorizationToken->save(); $this->messageHandler->addMessage(__('The OAuth 2.0 authorization was successful. Ready to send e-mail.', 'postman-smtp')); } else { $this->messageHandler->addError(__('Your email provider did not grant Postman permission. Try again.', 'postman-smtp')); } } catch (PostmanStateIdMissingException $e) { $this->messageHandler->addError(__('The grant code from Google had no accompanying state and may be a forgery', 'postman-smtp')); } catch (Exception $e) { $logger->error('Error: ' . get_class($e) . ' code=' . $e->getCode() . ' message=' . $e->getMessage()); /* translators: %s is the error message */ $this->messageHandler->addError(sprintf(__('Error authenticating with this Client ID. [%s]', 'postman-smtp'), '<em>' . $e->getMessage() . '</em>')); } // clean-up PostmanUtils::unlock(); PostmanSession::getInstance()->unsetOauthInProgress(); // redirect home PostmanUtils::redirect(PostmanUtils::POSTMAN_HOME_PAGE_RELATIVE_URL); }
/** * For whatever reason, PostmanUtils::get..url doesn't work here? :( */ function redirectToLogPage() { PostmanUtils::redirect(PostmanUtils::POSTMAN_EMAIL_LOG_PAGE_RELATIVE_URL); die; }