WHM API 1 'Create a temporary user session' doesn't redirect user to app
Hey everyone, I need some help. I'm using WHM's API to create a temporary user session and redirect the user to an app. When I run the following API: https://[my WHM's hostname]:2087/json-api/create_user_session with the body:
"api.version": "1",
"service": "cpaneld",
"user": "cpaneluser",
"app": "Email_Accounts",
"locale": "en"
The return URL doesn't include the redirect parameter to send the user to the email accounts page on cPanel. Instead, it provides the URL to the cPanel's homepage.
Does anyone know what I'm doing wrong? Any tips would be greatly appreciated.
Thanks in advance!
-
Hey there! I don't believe you're calling the function correctly for email access. For the "user" portion you'll want the exact email address instead of the cPanel username. Can you try that instead? Here is a test form my personal system:
root@host: whmapi1 create_user_session user="cptest@hattmonkey.com" service="cpaneld" app="Email_Accounts"
---
data:
cp_security_token: /cpsess0480728513
expires: '1723478251'
service: cpaneld
session: cptest@domain.com:lDB_rRICPefkUIyK:create_user_session,02c4ec2d11d9a7e83d9fa2bb9c931b09
url: https://host.domain.com:2083/cpsess0480728513/login/?session=cptest%40domain.com%3alDB_rRICPefkUIyK%3acreate_user_session%2c02c4ec0 -
Hi cPRex, thank you for taking the time to reply and to confirm if things are working on your end.
I did try to use the email address instead of the username as you suggested and below is what I was presented with, kindly note that the attached screenshot is of Postman.
Also, can you kindly confirm if you open the URL returned in your response, does it take you to the email account page in cPanel?
0 -
Change "cpaneld" to "webmaild" and that will log you straight into webmail without other steps. But yes, when using webmaild this URl does take me directly to Roundcube:
0 -
Oh, unfortunately, seems like the screenshot in my last reply created a misunderstanding about what I am trying to achieve here. I apologize for that.
So I am trying to create a shortcut button that will take the user to view their email accounts on cPanel, not to access Roundcode. Please find the correct screenshot below:
1. If I use the username for the user:
If I click on the above link, it takes me to the home page on cPanel and not to the email accounts page.
2. If I use the email account associated with the username:0 -
Got it - thanks for the additional details. This takes me to the cPanel >> Email Accounts page:
whmapi1 create_user_session user="hattmonk" service="cpaneld" app="Email_Accounts"
With the following URL:
https://host.domain.com:2083/cpsess5685916830/login/?goto_uri=frontend%2fjupiter%2femail_accounts%2findex.html&session=username%3aISgMpFRNrqEA644i%3acreate_user_session%2c2fcd5b7b7fb0eacf926de3c557e7b2c6
I'm not sure how you'd go about creating that inside a button, but the API function is possible.
0 -
Oh okay. I need help in making this possible with the JSON-API, as in you look at the first screenshot's response, it doesn't include he 'goto_uri=...' which is what is making me go crazy. If it is possible, could you please try to do the above with WHM's JSON API and confirm if the URL return takes the user to the Email Accounts page on cPanel?
Thank you.
0 -
Sure thing! This guy worked for me:
https://x.x.x.x:2087/cpsess#########/json-api/create_user_session?api.version=1&user=username&service=cpaneld&app=Email_Accounts
Is that what you're looking for?
0 -
Thank you for your time, cPRex, but unfortunately, that is not what I am looking for. I want to know why the JSON-API endpoint, when passed an "app" name, doesn't include a redirect parameter (goto_uri) in the returned URL to redirect us to the requested app, similar to how it is included in the URL when trying the same request via whmapi1.
0 -
The short answer is "because it doesn't need to" - when you use the command line API call you're creating a whole new user session, so not only will it need to login to cPanel, it will have to redirect to the correct page.
The JSON call is already being run from a browser from a session that is already authenticated so it knows it's inside cPanel already and doesn't require the go-to portion.
0 -
It looks like you're missing the
goto_uri
parameter in the request body. To redirect directly to the email accounts page, try adding:
"goto_uri": "/cpsess1234567/frontend/paper_lantern/mail/accounts.html"
Replacecpsess1234567
with the appropriate session ID. This should redirect the user to the Email Accounts page instead of the cPanel homepage.0
Please sign in to leave a comment.
Comments
10 comments