title: Could not retrieve app only tokens for office 365
body: <p>I followed the blog to develop an application that reads mails of users without having them signed in: <a href="http://blogs.msdn.com/b/exchangedev/archive/2015/01/21/building-demon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow.aspx?CommentPosted=true#commentmessage" rel="nofollow">http://blogs.msdn.com/b/exchangedev/archive/2015/01/21/building-demon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow.aspx?CommentPosted=true#commentmessage</a>   </p>
  
  <p>I got the id token and got the tenant Id. When i try to get the access token it throws an error:</p>
  
  <pre><code>{"error":"invalid_client","error_description":"AADSTS70002: Error validating cre
  dentials. AADSTS50012: Client assertion contains an invalid signature.\r\nTrace
  ID: 9646a93b-0094-4736-8d21-aed08f04b06e\r\nCorrelation ID: 8dd562af-556d-4d90-9
  f71-a60f5a232215\r\nTimestamp: 2015-03-03 10:47:25Z","error_codes":[70002,50012]
  ,"timestamp":"2015-03-03 10:47:25Z","trace_id":"9646a93b-0094-4736-8d21-aed08f04
  b06e","correlation_id":"8dd562af-556d-4d90-9f71-a60f5a232215","submit_url":null,
  "context":null}
  </code></pre>
  
  <p>But I created the certificate as per the instructions. I am not using ADAL library. I am using go language. So i followed the steps in a stack overflow link: <a href="https://stackoverflow.com/questions/28351558/office-365-rest-api-daemon-week-authentication">Office 365 Rest API - Daemon week authentication</a></p>
  
  <p>I signed the string using HMAC base64 encoded it and URL encoded it and then appended to the string as explained in the above post. This is my client assertion </p>
  
  <pre><code>eyJhbGciOiJSUzI1NiIsIng1dCI6IjZlLzEra01scHhuTHArZFJ4d1BqS21EdmZCQT0ifQ.eyJhdWQiOiJodHRwczovL2xvZ2luLndpbmRvd3MubmV0L2ZmNjQxNTFmLTIwM2EtNGM0MC1hZDcxLTExOTE2YjY2Yzg3My9vYXV0aDIvdG9rZW4iLCJleHAiOjE0MjU3Mzc2MDEsImlzcyI6Ijk3MjhiOGFiLTVhOGUtNGM0OC05YTZkLTZmMzFjMWYyZTdkYyIsImp0aSI6IjMyMDZiYWI5LTVmYmUtNDA3ZS02OWY2LTJlNGRjNDQ3NzQxYSIsIm5iZiI6MTQyNTc0MjYwMSwic3ViIjoiOTcyOGI4YWItNWE4ZS00YzQ4LTlhNmQtNmYzMWMxZjJlN2RjIn0.pG4okCzcgXZbS067U9BkGWid6Z6ExU7pbPYOlm2mSAg
  </code></pre>
  
  <p>Where am I going wrong?</p>