[SalesForce] Rest API Login – Customer Portal User

I need to do a login of our customer portal users in a mobile app (not using mobile SDK), for authenticating internal users it's working the REST API but for the Customer Portal Users is not.

The body:

username="Username"&client_secret="Secret From Connected App"&password="Password"&grant_type=password&client_id="Client ID from Connected App"

What I need to do to make this work? Is there any guide?

Best Answer

I worked through a similar situation. I'm assuming that you are using OAuth, and in a nutshell it boils down the login URL. Internal Users are naturally going to login.salesforce.com, but your portal User are going to have to go to the Site Login URL. Here's the link to the article from that got me going, and here's the excerpt that's at the heart of it.

The first step in enabling OAuth for your Portal users is to associate a Force.com Site with your Portal, if you have not already done so. The Site provides your Portal with a unique URL and allows you to create a custom login page. Apps that wish to login users for the Portal must use the hostname from the Site’s secure URL when redirecting users to the OAuth 2.0 authorization service. For example, rather than redirecting to

https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=your_client_id&redirect_uri=your_redirect_uri

instead use

https://mysite.secure.force.com/services/oauth2/authorize?response_type=code&client_id=your_client_id&redirect_uri=your_redirect_uri