Could not retrieve app only tokens for office 365

I followed the blog to develop an application that reads mails of users without having them signed in: 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

I got the id token and got the tenant Id. When i try to get the access token it throws an error:

{"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}

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: Office 365 Rest API - Daemon week authentication

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

eyJhbGciOiJSUzI1NiIsIng1dCI6IjZlLzEra01scHhuTHArZFJ4d1BqS21EdmZCQT0ifQ.eyJhdWQiOiJodHRwczovL2xvZ2luLndpbmRvd3MubmV0L2ZmNjQxNTFmLTIwM2EtNGM0MC1hZDcxLTExOTE2YjY2Yzg3My9vYXV0aDIvdG9rZW4iLCJleHAiOjE0MjU3Mzc2MDEsImlzcyI6Ijk3MjhiOGFiLTVhOGUtNGM0OC05YTZkLTZmMzFjMWYyZTdkYyIsImp0aSI6IjMyMDZiYWI5LTVmYmUtNDA3ZS02OWY2LTJlNGRjNDQ3NzQxYSIsIm5iZiI6MTQyNTc0MjYwMSwic3ViIjoiOTcyOGI4YWItNWE4ZS00YzQ4LTlhNmQtNmYzMWMxZjJlN2RjIn0.pG4okCzcgXZbS067U9BkGWid6Z6ExU7pbPYOlm2mSAg

Where am I going wrong?

Upvotes: 1

Views: 1408

Answers (1)

Jason Johnston
Jason Johnston

Reputation: 17702

The error indicates there's a problem with your signature. Comparing with a working one, it is way shorter. Be sure you're signing the string with an RSA SHA-256 hash. Using HMAC is probably causing the issue.

Upvotes: 2

Related Questions