0

Steps I am following.

  1. I am sending the authenticate parameter as 1 to public.php file and recieving the oauth_token and oauth_token_secret.

http://localhost/XeroOAuth-PHP-master/public.php?authenticate=1

Here at this stage session is generated as below

Array ( [oauth] => Array ( [oauth_token] => XXX [oauth_token_secret] => XXX [oauth_callback_confirmed] => true )

)

  1. Next step, I am calling this url http://localhost/XeroOAuth-PHP-master/public.php?oauth_verifier=1&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC

At this stage it throws below error, which says permission_denied.

Error: oauth_problem=permission_denied&oauth_problem_advice=The%20consumer%20was%20denied%20access%20to%20this%20resource.

Below is the entire Error format I receive in the page.

XeroOAuth Object ( [_xero_defaults] => Array ( [xero_url] => https://api.xero.com/ [site] => https://api.xero.com [authorize_url] => https://api.xero.com/oauth/Authorize [signature_method] => HMAC-SHA1 )

[_xero_consumer_options] => Array
    (
        [request_token_path] => oauth/RequestToken
        [access_token_path] => oauth/AccessToken
        [authorize_path] => oauth/Authorize
    )

[_action] => 
[_nonce_chars] => 
[params] => Array
    (
    )

[headers] => Array
    (
        [Accept] => application/xml
        [Content-Length] => 0
        [Expect] => 
    )

[auto_fixed_time] => 
[buffer] => 
[request_params] => Array
    (
    )

[_xero_curl_options] => Array
    (
        [curl_connecttimeout] => 30
        [curl_timeout] => 20
        [curl_ssl_verifypeer] => 2
        [curl_cainfo] => C:\xampp\htdocs\XeroOAuth-PHP-master/certs/ca-bundle.crt
        [curl_followlocation] => 
        [curl_ssl_verifyhost] => 2
        [curl_proxy] => 
        [curl_proxyuserpwd] => 
        [curl_encoding] => 
        [curl_verbose] => 1
    )

[config] => Array
    (
        [xero_url] => https://api.xero.com/
        [site] => https://api.xero.com
        [authorize_url] => https://api.xero.com/oauth/Authorize
        [signature_method] => HMAC-SHA1
        [request_token_path] => oauth/RequestToken
        [access_token_path] => oauth/AccessToken
        [authorize_path] => oauth/Authorize
        [curl_connecttimeout] => 30
        [curl_timeout] => 20
        [curl_ssl_verifypeer] => 2
        [curl_cainfo] => C:\xampp\htdocs\XeroOAuth-PHP-master/certs/ca-bundle.crt
        [curl_followlocation] => 
        [curl_ssl_verifyhost] => 2
        [curl_proxy] => 
        [curl_proxyuserpwd] => 
        [curl_encoding] => 
        [curl_verbose] => 1
        [application_type] => Public
        [oauth_callback] => localhost
        [user_agent] => Xero-OAuth-PHP Public
        [consumer_key] => XXX
        [shared_secret] => XXX
        [core_version] => 2.0
        [payroll_version] => 1.0
        [file_version] => 1.0
        [access_token] => XXX
        [access_token_secret] => XXX
        [host] => https://api.xero.com/oauth/
        [multipart] => 
    )

[method] => GET
[url] => https://api.xero.com/oauth/AccessToken
[sign] => Array
    (
        [parameters] => Array
            (
                [oauth_consumer_key] => YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7
                [oauth_nonce] => Ubrb
                [oauth_signature_method] => HMAC-SHA1
                [oauth_timestamp] => 1504002299
                [oauth_token] => 3CHDO7HFISTMVJXDX7IIPMRJUZH2FC
                [oauth_verifier] => 1
                [oauth_version] => 1.0
                [oauth_signature] => o9ucXeTTvA04tQgLTBX5AuMoX2Y=
            )

        [signature] => o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D
        [signed_url] => https://api.xero.com/oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0
        [header] => OAuth oauth_consumer_key="YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7", oauth_nonce="Ubrb", oauth_signature="o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1504002299", oauth_token="3CHDO7HFISTMVJXDX7IIPMRJUZH2FC", oauth_verifier="1", oauth_version="1.0"
        [sbs] => GET&https%3A%2F%2Fapi.xero.com%2Foauth%2FAccessToken&oauth_consumer_key%3DYDOVURHNHW7RIHJ384ZYJ7TMVQT8W7%26oauth_nonce%3DUbrb%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1504002299%26oauth_token%3D3CHDO7HFISTMVJXDX7IIPMRJUZH2FC%26oauth_verifier%3D1%26oauth_version%3D1.0
    )

[format] => xml
[response] => Array
    (
        [headers] => Array
            (
                [cache_control] => private
                [content_type] => text/html; charset=utf-8
                [date] => Tue, 29 Aug 2017 10:25:01 GMT
                [strict_transport_security] => max-age=31536000
                [www_authenticate] => OAuth Realm="10.144.115.64"
                [content_length] => 115
                [connection] => keep-alive
            )

        [code] => 401
        [response] => oauth_problem=permission_denied&oauth_problem_advice=The%20consumer%20was%20denied%20access%20to%20this%20resource.
        [info] => Array
            (
                [url] => https://api.xero.com/oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0
                [content_type] => text/html; charset=utf-8
                [http_code] => 401
                [header_size] => 267
                [request_size] => 418
                [filetime] => -1
                [ssl_verify_result] => 0
                [redirect_count] => 0
                [total_time] => 1.438
                [namelookup_time] => 0
                [connect_time] => 0.328
                [pretransfer_time] => 1.016
                [size_upload] => 0
                [size_download] => 115
                [speed_download] => 79
                [speed_upload] => 0
                [download_content_length] => 115
                [upload_content_length] => -1
                [starttransfer_time] => 1.438
                [redirect_time] => 0
                [redirect_url] => 
                [primary_ip] => 54.209.35.242
                [certinfo] => Array
                    (
                    )

                [primary_port] => 443
                [local_ip] => 192.168.1.35
                [local_port] => 60675
                [request_header] => GET /oauth/AccessToken?oauth_consumer_key=YDOVURHNHW7RIHJ384ZYJ7TMVQT8W7&oauth_nonce=Ubrb&oauth_signature=o9ucXeTTvA04tQgLTBX5AuMoX2Y%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1504002299&oauth_token=3CHDO7HFISTMVJXDX7IIPMRJUZH2FC&oauth_verifier=1&oauth_version=1.0 HTTP/1.1

Host: api.xero.com User-Agent: Xero-OAuth-PHP Public Accept-Encoding: deflate, gzip Accept: application/xml Content-Length: 0

            )

        [format] => xml
    )

)

1 Answers1

0

This error is returned if you try to swap a request token for an access token when the access token hasn't yet been authorised for an organisation.

There should be a step in the flow of your application which redirects the user to https://api.xero.com/oauth/Authorize?oauth_token=[OAUTH_TOKEN_HERE] - once the Xero user has selected the organisation they're giving access to and given the ok, your second call should work.

rustyskates
  • 856
  • 4
  • 10