jso / py-wink

Python library for interfacing with Wink devices by Quirky
MIT License
46 stars 25 forks source link

i guess you're wink api support! #4

Closed mrose17 closed 10 years ago

mrose17 commented 10 years ago

here's what i'm sending in the post for /oauth2/token

{"client_id":"...","client_secret":"...","username":"mrose17@gmail.com","password":"...","grant_type":"password","base_url":"https://winkapi.quirky.com"}

and here's what i get back:

{"data":{"error":"unsupported_grant_type"},"errors":[],"pagination":{}}

eh? i've looked at your code and you're sending password as well. am i missing the obvious?

jso commented 10 years ago

base_url is a parameter I made up in case the API location ever changed; it doesn't need to be sent in the request! Try omitting that one parameter, and then you'll match what I have exactly. Also, be sure you're setting the Content-Type header to 'application/json' -- that's the only other thing you need for the auth request.

On Tue, Jan 7, 2014 at 9:31 PM, mrose17 notifications@github.com wrote:

here's what i'm sending in the post for /oauth2/token

{"client_id":"...","client_secret":"...","username":"mrose17@gmail.com","password":"...","grant_type":"password","base_url":"https://winkapi.quirky.com"}

and here's what i get back:

{"data":{"error":"unsupported_grant_type"},"errors":[],"pagination":{}}

eh? i've looked at your code and you're sending password as well. am i missing the obvious?

— Reply to this email directly or view it on GitHubhttps://github.com/jso/py-wink/issues/4 .

mrose17 commented 10 years ago

thanks. i removed base_url, and verified the headers:

    { protocol: 'https:',
      slashes: true,
      auth: null,
      host: 'winkapi.quirky.com',
      port: null,
      hostname: 'winkapi.quirky.com',
      hash: null,
      search: null,
      query: null,
      pathname: '/oauth2/token',
      path: '/oauth2/token',
      href: 'https://winkapi.quirky.com/oauth2/token',
      agent: false,
      method: 'POST',
      headers: { 'Content-Type': 'application/json' } }

so, i suspect that we're sending the same thing. odd.

jso commented 10 years ago

Well, that's bizarre. I double checked, and this is what my interaction looks like. I don't see any difference.

Request URL: https://winkapi.quirky.com/oauth2/token

POST body: {"username": "_", "client_secret": "", "password": "**", "clientid": "**", "grant_type": "password"}

HTTP response headers: {'status': '201', 'x-request-id': '***', 'expires': 'Fri, 01 Jan 1990 00:00:00 GMT', 'transfer-encoding': 'chunked', 'strict-transport-security': 'max-age=31536000', 'x-runtime': '0.130222', 'connection': 'keep-alive', 'x-ua-compatible': 'IE=Edge,chrome=1', 'pragma': 'no-cache', 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate', 'date': 'Wed, 08 Jan 2014 03:43:02 GMT', 'content-type': 'application/json; charset=utf-8', 'x-rack-cache': 'invalidate, pass'}

HTTP response body: {"data":{"accesstoken":"**","refreshtoken":"**","token_type":"bearer","token_endpoint":" https://winkapi.quirky.com/oauth2/token"},"errors":[],"pagination":{}}

On Tue, Jan 7, 2014 at 9:37 PM, mrose17 notifications@github.com wrote:

thanks. i removed base_url, and verified the headers:

{ protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'winkapi.quirky.com',
  port: null,
  hostname: 'winkapi.quirky.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/oauth2/token',
  path: '/oauth2/token',
  href: 'https://winkapi.quirky.com/oauth2/token',
  agent: false,
  method: 'POST',
  headers: { 'Content-Type': 'application/json' } }

so, i suspect that we're sending the same thing. odd.

— Reply to this email directly or view it on GitHubhttps://github.com/jso/py-wink/issues/4#issuecomment-31803378 .

mrose17 commented 10 years ago

thanks. i'll try a few more things and then email them tomorrow...

jso commented 10 years ago

One really dumb idea but worth a shot -- maybe use the expanded JSON format with spaces? I know it should parse with or without them, but it might be the issue.

On Tue, Jan 7, 2014 at 9:48 PM, mrose17 notifications@github.com wrote:

thanks. i'll try a few more things and then email them tomorrow...

— Reply to this email directly or view it on GitHubhttps://github.com/jso/py-wink/issues/4#issuecomment-31803750 .

mattbornski commented 10 years ago

@mrose17 Email me a Charles web proxy session or a cURL command illustrating exactly what you're doing and I'll have a look.

mrose17 commented 10 years ago

many thanks! back in 5m.

mrose17 commented 10 years ago

@jso and @mattbornski - the repo is now public at https://github.com/TheThingSystem/node-winkapi

obviously, i'm doing something clueless here, but as to which clue i'm lacking, i'm not sure.

to test (on a system with node): edit test.'s to include "the needful" and then

    % node test.js
mrose17 commented 10 years ago

ps: feel free to push requests or issue me at https://github.com/TheThingSystem/node-winkapi/issues

mrose17 commented 10 years ago

@mattbornski i found the issue and updated the repo.

the issue is that the Wink API server doesn't like the JSON generated by JSON.stringify(). as @jso suggested, putting some whitespace in there made the parser happy! onward...