getAuthorizationUrl() 공개 정적인 메소드

Returns the PayPal URL to which the user must be redirected to start the authentication / authorization process.
public static getAuthorizationUrl ( string $redirectUri, array $scope, string $clientId, null $nonce = null, null $state = null, ApiContext $apiContext = null ) : string
$redirectUri string Uri on merchant website to where the user must be redirected to post paypal login
$scope array The access privilges that you are requesting for from the user. Pass empty array for all scopes.
$clientId string client id from developer portal See https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/#attributes for more
$nonce null
$state null
$apiContext PayPal\Rest\ApiContext Optional API Context
리턴 string Authorization URL
예제 #1
0
 /**
  * @test
  */
 public function testLoginWithCustomConfig()
 {
     $redirectUri = 'http://mywebsite.com';
     $scope = array('this', 'that', 'and more');
     $expectedBaseUrl = "https://www.paypal.com/signin/authorize";
     $this->assertEquals($expectedBaseUrl . "?client_id=DummyId&response_type=code&scope=this+that+and+more+openid&redirect_uri=" . urlencode($redirectUri), OpenIdSession::getAuthorizationUrl($redirectUri, $scope, "DummyId", null, null, $this->context), "Failed case - custom config");
 }
예제 #2
0
<?php

require __DIR__ . '/../bootstrap.php';
use PayPal\Api\OpenIdSession;
$baseUrl = getBaseUrl() . '/UserConsentRedirect.php?success=true';
// ### Get User Consent URL
// The clientId is stored in the bootstrap file
//Get Authorization URL returns the redirect URL that could be used to get user's consent
$redirectUrl = OpenIdSession::getAuthorizationUrl($baseUrl, array('openid', 'profile', 'address', 'email', 'phone', 'https://uri.paypal.com/services/paypalattributes', 'https://uri.paypal.com/services/expresscheckout', 'https://uri.paypal.com/services/invoicing'), null, null, null, $apiContext);
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Generated the User Consent URL", "URL", '<a href="' . $redirectUrl . '" >Click Here to Obtain User Consent</a>', $baseUrl, $redirectUrl);
예제 #3
0
    public function appendEventXML(array $context = null)
    {
        $result = new XMLElement('paypal');
        $cookie = new Cookie('paypal', TWO_WEEKS, __SYM_COOKIE_PATH__, null, true);
        $accessToken = $cookie->get('token');
        //$accessToken->getRefreshToken()
        // var_dump($accessToken);die;
        if (!empty($accessToken)) {
            $user = $cookie->get('user');
            $result->appendChild(General::array_to_xml($result, $user));
        } else {
            $baseUrl = SYMPHONY_URL . '/extension/paypal/consent';
            // ### Get User Consent URL
            // The clientId is stored in the bootstrap file
            //Get Authorization URL returns the redirect URL that could be used to get user's consent
            $redirectUrl = OpenIdSession::getAuthorizationUrl($baseUrl, array('openid', 'profile', 'address', 'email', 'phone', 'https://uri.paypal.com/services/paypalattributes', 'https://uri.paypal.com/services/expresscheckout'), null, null, null, $this->apiContext);
            $authend = $this->mode == 'sandbox' ? '"authend": "sandbox",' : '';
            $scriptInclude = '<span id="lippButton"></span>
					<script src="https://www.paypalobjects.com/js/external/api.js"></script>
					<script>
					paypal.use( ["login"], function(login) {
					  login.render ({
						"appid": "' . $this->clientId . '",' . $authend . '"scopes": "openid profile email address phone https://uri.paypal.com/services/paypalattributes https://uri.paypal.com/services/expresscheckout",
						"containerid": "lippButton",
						"locale": "en-us",
						"returnurl": "' . $baseUrl . '"
					  });
					});
					</script>';
            $result->appendChild(new XMLElement('authorize', $this->repairEntities($scriptInclude), array('url' => $this->repairEntities($redirectUrl))));
            // var_dump($redirectUrl);die;
        }
        $context['wrapper']->appendChild($result);
    }
예제 #4
0
<?php

require __DIR__ . '/../bootstrap.php';
use PayPal\Api\OpenIdSession;
$baseUrl = getBaseUrl() . '/UserConsentRedirect.php?success=true';
// ### Get User Consent URL
// The clientId is stored in the bootstrap file
//Get Authorization URL returns the redirect URL that could be used to get user's consent
$redirectUrl = OpenIdSession::getAuthorizationUrl($baseUrl, array('profile', 'email', 'phone'), null, null, null, $apiContext);
ResultPrinter::printResult("Generated the User Consent URL", "URL", '<a href="' . $redirectUrl . '" >Click Here to Obtain User Consent</a>', $baseUrl, $redirectUrl);
예제 #5
0
$app_return_url = '!!! URL TO THIS SCRIPT !!!';
$scope = array('openid', 'email');
#More info: https://developer.paypal.com/docs/integration/direct/identity/attributes/
#######################################################
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once dirname(__FILE__) . '/paypal-sdk/autoload.php';
use PayPal\Api\OpenIdSession;
use PayPal\Api\OpenIdTokeninfo;
use PayPal\Api\OpenIdUserinfo;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
#######################################################
#Step 1: display link to paypal
if (!isset($_GET['code']) and !isset($_GET['error'])) {
    $openidurl = OpenIdSession::getAuthorizationUrl($app_return_url, $scope, $paypal_client_id);
    echo 'Click here to <a href="https://www.paypal.com/webapps/auth/protocol/openidconnect' . $openidurl . '">log in with paypal</a>!';
    die;
}
#######################################################
#Check return data for errors
if (isset($_GET['error'])) {
    die('<h1>Error:</h1><pre>' . print_r($_GET, TRUE));
}
#######################################################
#Step 2: get user data
$api_context = new ApiContext(new OAuthTokenCredential($paypal_client_id, $paypal_secret));
$api_context->setConfig(array('mode' => 'live'));
$token = OpenIdTokeninfo::createFromAuthorizationCode(array('code' => $_GET['code']), $paypal_client_id, $paypal_secret, $api_context);
$user = OpenIdUserinfo::getUserinfo(json_decode($token, true), $api_context);
$user = json_decode($user, true);