Search code examples
c#visual-studiouwpwin-universal-appwns

Error invalid_request when try to receive WNS access token


As is mentioned in official doc I am using the exact order of request building:

POST /accesstoken.srf HTTP/1.1
Host: login.live.com
grant_type: client_credentials
client_id:/here's my client id from dashboard/
client_secret: /here's my secret from dashboard/
scope: notify.windows.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

and I am getting:

400 Bad Request

Cache-Control → no-store
Connection → close
Content-Length → 76
Content-Type → application/json
Date → Fri, 01 Apr 2016 11:23:08 GMT
Pragma → no-cache
Server → Microsoft-IIS/8.5
X-Content-Type-Options → nosniff
X-WLID-Error → 0x8004101C

{
    "error": "invalid_request",
    "error_description": "Invalid request parameters"
}

I am using an online request maker, and have to mention that 2 days ago it was working perfect, I was receiving the token and expiration time as expected.

I created a new app on the store to try out new client_id and client_secret and still same problem, also tried from other PC with different external IP and no success. Is WNS a usual windows shity service or I am missing something?


Solution

  • It seems you are putting grant_type, client_id, client_secret, and scope as the Header of your request. But as it is said in the official doc:

    The cloud service submits these required parameters in the HTTP request body, using the "application/x-www-form-urlencoded" format. You must ensure that all parameters are URL encoded.

    These parameters should in the HTTP request body and URL encoded. When using Request Maker, you needn't add any request header as the default Content-Type is application/x-www-form-urlencoded. And also please do note to use URL encoded client_id and client_secret. The request would like following:
    enter image description here

    Request Headers Sent:

    POST /accesstoken.srf HTTP/1.1
    Host: login.live.com
    Accept: */*
    Content-Length: 210
    Content-Type: application/x-www-form-urlencoded
    

    Response Headers:

    Cache-Control: no-store
    Pragma: no-cache
    Content-Length: 436
    Content-Type: application/json
    Server: Microsoft-IIS/8.5
    X-Content-Type-Options: nosniff
    Date: Wed, 06 Apr 2016 09:28:04 GMT
    Connection: close
    

    Response Body:

    {"token_type":"bearer","access_token":"EgAaAQMAAAAEgAAAC4...y0yNTQ1NDU3MDAA","expires_in":86400}