title: MS CRM 2013 Online OAuth unsupported_grant_type - authorization_code
body: <p>We have an ASP.NET MVC 4 application that runs inside an iframe in MS CRM 2013. The web application uses the MS CRM web services (Organization web service) to retrieve and save data. To do so, it needs to authenticate. For on-premises we are using windows authentication and impersonate with the currently logged user in MS CRM (user id is passed to the iframe URL). It works like a charm.</p>
  
  <p>However for MS CRM 2013 Online, since we want to avoid storing any user credentials in our application, we have chosen to use OAuth. Any suggestion how to achieve the same in a different way are most welcome since it does not seam right to use a method mostly for non-dot-net clients.</p>
  
  <p>We are able to get the code calling: <code>https://login.windows.net/{0}/oauth2/authorize?response_type=code&amp;resource={1}&amp;client_id={2}&amp;redirect_uri={3}</code>. But when I ask for the token, I get a 400 Bad Request error.</p>
  
  <p>Request</p>
  
  <p>Method: POST</p>
  
  <p>URL: <code>https://login.windows.net/{0}/oauth2/token?api-version=1.0</code></p>
  
  <p>Header:</p>
  
  <pre><code>User-Agent: Fiddler
  Host: login.windows.net
  Content-Length: 563
  Content-Type: application/x-www-form-urlencoded
  </code></pre>
  
  <p>Body:</p>
  
  <pre><code>grant_type=authorization_code&amp;code={0}&amp;redirect_uri={1}&amp;resource={2}
  </code></pre>
  
  <p>Response</p>
  
  <pre><code>{"error":"unsupported_grant_type","error_description":"ACS70003: The access grant \u0027authorization_code\u0027 is not supported...}
  </code></pre>
  
  <p>The comments under this article (<a href="http://blogs.msdn.com/b/aadgraphteam/archive/2013/05/17/using-oauth-2-0-authorization-code-grant-for-delegated-access-of-directory-via-aad-graph.aspx?CommentPosted=true#commentmessage" rel="nofollow">http://blogs.msdn.com/b/aadgraphteam/archive/2013/05/17/using-oauth-2-0-authorization-code-grant-for-delegated-access-of-directory-via-aad-graph.aspx?CommentPosted=true#commentmessage</a>) suggest that this is a Azure AD bug but it should have been fixed by now, I guess. Am I doing something wrong?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Enoch</p>