I am currently building an API, that needs a username and password to work (obviously). There are two ways that I would like this API to be used:
- The "normal" way through REST server-server calls using headers to authorize the user (working fine)
- Or through a "third-party" using iframes.
With the second method I'm having a bit of trouble. To explain further the implementation is as follows:
- The "operator" has a domain called https://example1.com and on this domain the operator would like to integrate my iframe that calls the above API
On https://example1.com I have added the below code
if (session_status() == PHP_SESSION_NONE) { session_start(); } $_SESSION['u'] = 'username_here'; $_SESSION['p'] = 'password_here';
The operator includes
<?=session_id();?>
inside the iframe URL so say for examplesrc="https://iframe.example1.com/?sid=<?=session_id();?>"
If the iframe AND the operator website are on the same server this works fine (obviously) as the session storage can be read from both parties, and then it will read:
$_SESSION['u'];
and$_SESSION['p'];
, calls the API with the given username and password and retrieves the needed information.If the iframe is held on https://example2.com (different server), the session data is then unreadable
What are some secure ways to pass through the username and password, while keeping the API as RESTful as possible?
Thank you in advance