Skip to content

Commit

Permalink
Fixes #11 - incorrect OAuth docs
Browse files Browse the repository at this point in the history
  • Loading branch information
baileyherbert committed Apr 4, 2020
1 parent 30896c6 commit 8ba3bb2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $oauth = new Herbert\Envato\Auth\OAuth([
]);

// Get the token (returns null if unavailable)
$token = $oauth->token;
$token = $oauth->auth;

// Redirect the user if they're not authorized yet
if (!$token) {
Expand Down Expand Up @@ -128,7 +128,7 @@ if (isset($_SESSION['oauth_session'])) {

// No saved session, so let's start a new one
else {
if ($oauth->token) {
if ($oauth->auth) {
// Save the OAuth session
$_SESSION['oauth_session'] = $oauth->session;
}
Expand All @@ -140,7 +140,7 @@ else {
}

// Create the client
$client = new Herbert\EnvatoClient($oauth->token);
$client = new Herbert\EnvatoClient($oauth->auth);
```

- The `$oauth->session` member will contain a JSON string with data for the current authorization.
Expand Down
6 changes: 5 additions & 1 deletion src/Envato/Auth/OAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ public function __get($property) {
if ($property == 'auth') {
// Only if we've just returned from authorization
if (isset($_GET['code'])) {
return ($this->generatedToken) ?: $this->generateToken(trim($_GET['code']));
if (!$this->generatedToken) {
$this->generateToken(trim($_GET['code']));
}
}

return $this->generatedToken;
}

// Handle session requests
Expand Down

0 comments on commit 8ba3bb2

Please sign in to comment.