Forum Discussion

raguv12ps's avatar
4 years ago

Create a user session through API in Community

Is there any API in community, where we can create a user session in community on behalf of the user.

I have created a common user in community and when a anonymous users hits a specific page, I want to login as that common user on anonymous user's behalf.

Is the above possible?

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)

    Hi raguv12ps.

    This sounds like something you could do using an account with the Switch to another user permission and Session Key login with the Community REST API v1. I've not tried this in the scenario you're working with though.

    We have an example of this in our Create subscriptions for another user guide in the Dev Doc Portal. The create subscription part won't apply, the steps to get the required session keys should.

    The basic steps would be something like:

    • Create a session key for yourself using a Community account with the Switch to another user permission.
    • Create a second session key for the "common user" using your retrieved session key.
    • With the common user's session key, perform the desired action.

     

    • phoneboy's avatar
      phoneboy
      Director

      I'm thinking about how to do something similar to "sandbox" Switch User functionality, namely to prevent them switching to an Admin user.
      That would imply doing this in a component, so not sure the flow mentioned in that article is something I can actually accomplish. 
      Does the actual "switch user" action have an endpoint we can call via a restadmin call or similar?