Skip to content

get_client_credentials_token never sends the configured scopes; App Store README example also has a syntax error #399

Backlog

Description

@hackermengzhi

Version

18.5.0 (master at 0f1bdaa)

1. scopes is ignored for client credentials

ApiClient#initialize stores credentials[:scopes], but get_client_credentials_token only posts the grant type:

https://github.com/XeroAPI/xero-ruby/blob/0f1bdaa/lib/xero-ruby/api_client.rb#L167-L174

def get_client_credentials_token
  data = {
    grant_type: @grant_type
  }
  token_request(data, '/token')
end

With the README's App Store setup (scopes: 'marketplace.billing openid profile email'), the request body captured by stubbing Faraday.post is:

POST https://identity.xero.com/connect/token
body: grant_type=client_credentials

The README says the App Store token needs to be requested "with the marketplace.billing scope", but there is no way to get the SDK to send it. Custom connections also can't request fewer scopes than the connection grants.

Suggested fix:

data = { grant_type: @grant_type }
data[:scope] = @scopes if @scopes

(@scopes is already a space-delimited string, as used by authorization_url.)

2. README snippet doesn't parse

The App Store example is missing a comma after grant_type: 'client_credentials':

https://github.com/XeroAPI/xero-ruby/blob/0f1bdaa/README.md?plain=1#L174-L179

$ ruby -c snippet.rb
snippet.rb:1: syntax errors found (SyntaxError)
  expected a `}` to close the hash literal

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions