function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andries.NeyensAndries.Neyens 

Login using javascript remoting

Hi all,

we are trying to use AngularJS as a community site.
Problem is that the first page is accessible as a guest user.
All remote action calls are public.
At a certain point, the calls must be made protected (via profile and apex class security)

Here we want to use some sort of login via remote actions using Site.Login
But helas, this is not working.
Session id's returned are still for guest users (but login was successful, can be seen in the login history)
Only way to let this work is use the standard login page that somehow sets session id's via cookies?
no idea how to mimic this ??

andries
Shiran FernandoShiran Fernando
Hi Andries, 

I'm having the same issue. Have you got this resolved?  If so, could you please share the solution?

cheers

Shiran
Andries.NeyensAndries.Neyens
Shiran,

we did solve it! The key tip is:

Visualforce.remoting.oauthAccessToken = <access_token>;

(https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_oauth.htm)

You can use oAuth to retrieve the token. We did that in a new popup window with a callback to a page with some javascript to pass it back to the parent.
Of course, all remote actions should be publicly accessible. And in code you can check on access (we did that on profile, Guest user vs Community user)


 
Shiran FernandoShiran Fernando
Hi Andres,

Thanks for the reply. I managed to resolve this with a different workaround.

Cheers,
Shiran
Andries.NeyensAndries.Neyens
Please share Shiran, you never know if I can refactor some stuff..
Shiran FernandoShiran Fernando
Hi Andries,

Actually I gave up the VF remoting method since the sychronous(direct apex controller method) call worked just fine. What I wanted to do was register a new community user and log him in a single action. That worked fine.

Cheers,
Shiran