Thank you
@cPanelLauren.
To add my note, I've been struggling with this for a while. Now I've solved it I see how trivial it was. I hope others find this faster than I did. I've quantified two working solutions. The latter is much nicer.
How do I login users to cPanel
Requirements:
- cpanel api, WHM management api
As a provider, I would like to log-in my users into their cPanel for their benefit; server to client browser. It allows me to apply stronger credentials and support login issues with tickets.
user/pass login
The [history] thread is correct - using "/login/?login-only=1" persists a users session. I feel it's designed for explicit robot
UI work - such as auto clicking and parsing. This has a number of (valid) limits:
- Login credentials require the users password
- sessions are maintained by the owning utility (the server script, or a local client (postman))
- the session is held with cookies.
And it works fine if you're viewing
within the session - such as postman or some interesting embedded wrapper.
But due to newer internet securities this isn't shareable with the browser. Therefore if the session is generated within the server-side environment, you can't pass this to the user.
This is due to the browser securing your session to the domain and
app. To test this, authenticate (and perform) Postman - then open a new tab and paste the API given "session url"; it'll work. But applying the same address to another browser will require authentication.
client behalf login
WHM API 1 Functions - create_user_session - Developer Documentation - cPanel Documentation
As an alternative I utilise the 'create_user_session' api url:
https://cloud-api:208X/json-api/cre...&user=myuser&service=cpaneld&app=Backups_Home
The endpoint authenticates for a small session window and returns a rich definition for the user session.
Code:
{'data': {'cp_security_token': '/cpsess1470532104',
'expires': 2559961754,
'service': 'cpaneld',
'session': 'myuser:random:create_user_session, random',
'url': '[URL='https://example.com/?&session=myuser%random:acreate_user_session%random'},
... }
hand-off the user to the given url (I choose a redirect) and done! It works great:
- no user password required
- can happen automatically on any system
- defaults 15 minutes user inactivity closure
- user may use any browser
---
I hope it helps. Thanks for such a rich API - I'm using python and it's awesome.