I confirm Daniel Ballinger's solutionDaniel Ballinger's solution on this page.
The scope needed for the OAuth token is "web: Provide access to your data via the Web (web)". According to the Salesforce documentation on Scope Parameter Values, this "Allows the ability to use the access_token on the Web" which I presume means using the Access Token as a cookie?
Steps to download a Rich Text Area (RTA) image via OAuth and curl, or similar programmatic methods:
Make sure you have the correct scope for your OAuth access token. Go to the "Connected Apps" page for your OAuth connected app in Salesforce. Under "API (Enable OAuth Settings)" make sure the scope "web: Provide access to your data via the Web (web)" is included.
If you were using an old refresh token with the old scope, re-authorize and get a new one with the new scope which includes "web".
Get the URL of the RTA image by browsing the Knowledge article and inspecting the image src URL in your browser. The URL should look like
https://example--c.eu3.content.force.com/servlet/rtaImage?eid=ka0w0000000U2CV&feoid=00Nw0000008eLoi&refid=0EMw00000004lzh
Make a curl request setting your cookie "sid" to the OAuth access token value e.g.
curl -ik --cookie 'sid=MyOauthAccessToken' 'https://example--c.eu3.content.force.com/servlet/rtaImage?eid=ka0w0000000U2CV&feoid=00Nw0000008eLoi&refid=0EMw00000004lzh'
The request will return a 302 redirect. Do another curl with the redirect URL and set the same "sid" cookie value. Follow 3-4 subsequent redirects, using the returned redirect URL each time, until the response header includes a "Set-Cookie" giving you a new "sid" cookie value.
Set-Cookie: sid=0023457000079pu!AR8AQO8byIe2NtMi8vd3bt5vVBFqJxgDU2FkQQZd7NgHIQ49CejIVh6FAHyN4mKmSu1UDRAMpWMtUSuAuea0CY123456abcd; path=/; secure
Use the new "sid" cookie value for the next request to the redirect URL. This is the web cookie that we can use for screen scraping.
The request with the new "sid" web cookie value will return the binary data of the image in the response body.
Other methods
This other answer provides more information: http://salesforce.stackexchange.com/a/46495/36144https://salesforce.stackexchange.com/a/46495/36144 , including using frontdoor.jsp
.
We should also be able to get the web cookie that for scraping the RTA image, by programatically going to https://[YourSalesforceInstanceUrl].salesforce.com/secur/frontdoor.jsp?sid=[OAuthAccessToken]
.
The frontdoor.jsp
method is another way of getting the web cookie, and may also involve following a series of redirects before finally getting the web cookie value.