diff --git a/README.md b/README.md index 1b156d0..cd5bfdd 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,20 @@ -# Xero API +# Xero API Client -API package for Xero authenticated access, PSR-7, PSR-15, PSR-18. +API package for Xero authenticated access. +Leverages PSR-7, PSR-17 and PSR-18. Handles the OAuth 1.0a requests, and token renewals for the *partner application*. -It does this by offering a decorated PSR-18 +It does this by offering a decorated PSR-18 client. + +Provides support for the authentication flow to capture the OAuth 1.0a tokens. Features include: * Support for *Partner Application* only at present. -* Automatic token renewal by time (including guard time) or on an expired token. -* Callback to the application for persistence of the OAuth1 token credentails - when they gety renewed. +* Automatic token renewal of a token by its local age, or on an expiry flagged by + the remote Xero API. +* Hook to the application for persistence of the OAuth1 token credentails + when they get renewed. This keeps the burden of renewals away from the application. ## Simple Usage diff --git a/src/Oauth1/Authorise.php b/src/Oauth1/Authorise.php index 135f8bc..033a6f8 100644 --- a/src/Oauth1/Authorise.php +++ b/src/Oauth1/Authorise.php @@ -54,13 +54,6 @@ public function getTemporaryToken() 'oauth_callback' => $this->getConfigItem('callback_uri'), ]; - if ($this->getConfigItem('redirect_on_error')) { - // This should force a cancel to come back to the consumer - // site, but I'm not sure it is working. - - $queryParameters['redirectOnError'] = 'true'; - } - // Construct URI. $oauth1Endpoint = $this->getOauth1Endpoint(); @@ -105,6 +98,13 @@ public function authoriseUrl(OauthTokenInterface $temporaryToken) $queryParameters['oauth_token'] = $oauthToken; } + if ($this->getConfigItem('redirect_on_error')) { + // This should force a cancel to come back to the consumer + // site, but I'm not sure it is working. + + $queryParameters['redirectOnError'] = 'true'; + } + $oauth1Endpoint = $this->getOauth1Endpoint(); $redirectUserUri = $oauth1Endpoint->getRedirectUserUri() diff --git a/src/Oauth1/Token.php b/src/Oauth1/Token.php index e67aff1..644422a 100644 --- a/src/Oauth1/Token.php +++ b/src/Oauth1/Token.php @@ -402,6 +402,16 @@ public function withOauthProblem(string $oauthProblem): self return (clone $this)->setOauthProblem($oauthProblem); } + /** + * Undocumented, some results come back with an "error" + * GET parameter. Map them onto an OAuth error. + */ + public function setError(string $error): self + { + $this->oauthProblem = $error; + return $this; + } + /** * Get/set/with OAuth reason. */ @@ -424,6 +434,16 @@ public function withOauthProblemAdvice(string $oauthProblemAdvice): self return (clone $this)->setOauthProblemAdvice($oauthProblemAdvice); } + /** + * Undocumented, some results come back with an "error_description" + * GET parameter. Map them onto an OAuth error. + */ + public function setErrorDescription(string $errorDescription): self + { + $this->oauthProblemAdvice = $errorDescription; + return $this; + } + /** * @return bool true if the object contains an OAuth error */