0

I am exploring some REST APIs. Various APIs requests are initiated from a visualforce page and are processed by apex in controller. At some point we are thinking to provide a 'Advanced Options' link in visualforce page. This link should redirect user to web application login without entering his credentials (credentials are stored in Salesforce). I tried processing this request by apex and failed to do so.I followed below steps:

  1. Clicking 'Advanced Options' called login method in apex.
  2. Successfully Called REST based login api method
  3. Created a Pagereference object for post-login landing page.
  4. Collected cookies from response and put those all to Pagereference object. Pagereference was sent back to browser to load.

Cookies are the mechanism that web application use for providing access and to determine valid session. I was redirected back to login page although cookies were set properly in the browser. Can this be because cookies are non-transferable by their security definition. My browser and apex cloud server will belong to different IP and it was server who collected those cookies by calling login method. Am I right in choosing above approach or should I choose some client API request method(like JS,jquey ajax).

1

Unfortunately, when you are using Cookies with PageReference it wouldn't work since Salesforce prepends "apex__" prefix to all of your cookies.

Instead, you could use pure JavaScript (or some JS libraries) to set clean cookies and redirect or you could show some link to help user redirect.

| improve this answer | |
  • Thank you @Patlatus. That was helpful while I am making my mind towards jQuery – Mukesh Verma Jun 1 '16 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.