Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I Verify oAuth? #2

Closed
burakbuylu opened this issue Oct 29, 2020 · 1 comment
Closed

How do I Verify oAuth? #2

burakbuylu opened this issue Oct 29, 2020 · 1 comment

Comments

@burakbuylu
Copy link

Hello,

Here is my code;
`
session_start();

use Etsy\Etsy;

require_once('vendor/autoload.php');

$consumer_key = 'xxxx';
$consumer_secret = 'xxxx';

Etsy::setConfig([
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'scope' => ['listings_r', 'transactions_r', 'listings_w'],
'callback_uri' => 'http://localhost/etsy/callback.php'
]);
$etsy = new Etsy;

if (!isset($_SESSION['temp_credentials'])) {
$temp_credentials = $etsy->getTemporaryCredentials();

$_SESSION['temp_credentials']['identifier'] = $etsy->getTemporaryCredentials()->getIdentifier();
$_SESSION['temp_credentials']['secret'] = $etsy->getTemporaryCredentials()->getSecret();

header('Location: ' . $etsy->getAuthorizationUrl());
die();

}

$temp_credentials = $etsy->createTemporaryCredentials($_SESSION['temp_credentials']['identifier'], $_SESSION['temp_credentials']['secret']);

try {
$token_credentials = $etsy->getTokenCredentials($etsy->getTemporaryCredentials(), $_SESSION['oauth_token'], $_SESSION['oauth_verifier']);
print_r($token_credentials);
} catch (\Exception $e) {
die($e->getMessage());
}
`

And my callback file;
`session_start();

$_SESSION['oauth_token'] = $_GET['oauth_token'];
$_SESSION['oauth_verifier'] = $_GET['oauth_verifier'];

header('Location: index.php');`

But I cannot verify? Where is the problem?

@rhysnhall
Copy link
Owner

In your try/catch, you are getting a new set of temporary credentials again. You want to pass in the ones you previously created.

Change:
$token_credentials = $etsy->getTokenCredentials($etsy->getTemporaryCredentials(), $_SESSION['oauth_token'], $_SESSION['oauth_verifier']);

To:
$token_credentials = $etsy->getTokenCredentials($temp_credentials, $_SESSION['oauth_token'], $_SESSION['oauth_verifier']);

@ELY3M ELY3M mentioned this issue Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants