Autologin iframe in website

How to Autologin iframe in website after getting userid and authtoken

Hi! You should direct the user like stated there:

I am calling rest api http://localhost:3000/api/v1/login
in response i get userid and token.

but how to bypass login screen

You should use this API instead:

mind the confi env CREATE_TOKENS_FOR_USERS

after getting the token, you direct the user to a url like:

https://yourown.rocket.chat/home?resumeToken=abcd123456789

curl -H “X-Auth-Token: 9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq”
-H “X-User-Id: aobEdbYhXfu5hkeqG”
-H “Content-type:application/json”
http://localhost:3000/api/v1/users.createToken
-d ‘{ “userId”: “BsNr28znDkG8aeo7W” }’

How to get X Auth token and X User ID to create user token

Those are the information related to the user that will consume the API.

You can create a personal access token (top left, my profile)

But want to integrate it in php website… Not want to redirect to rocket chat server page

Ok, so you can create the iframe with that url and you are good to go.

some time general chanel display more than 1 time and other room user listed left side bar.
how to avoid this

how to create direct message link like http://localhost:3000/direct/ixCpBiXpnH35mTpmX for particular user?

I see “Invalid user” red message after login…
Can you please tell me what is the solution

So you want to both have Rocket.Chat into an iframe and have external links for a direct message, right?

I believe you are seeing this duplication because it is not using the same local storage for some reason.

Consider that the iframe integration will go until certain point. After that, you are better off integrating it using APis.

Can you share a scaffold, like a simple set of htmls and etc of what you are trying to accomplish where we could replicate the issues?

$(document).ready(function()
{
var Main_User_Id = ‘<?=$Main_User_Id?>’;
var Chat_User_Id = ‘<?=$Chat_User_Id?>’;

    var request = $.ajax({
            url: "<?php echo base_url();?>token",
            type: "POST",
            async: false,
            data: 
            {
                Main_User_Id:Main_User_Id, 
                Chat_User_Id:Chat_User_Id,                                   
            },
            dataType: "json"
        });

        request.done(function(Info) 
        {  
                          
            var Auth_Token = Info['Auth_Token'] ;
            var Room_Id = Info['Room_Id'] ;
         
            if(Auth_Token != '' && Room_Id != '')
            {
               
                let direct_chat_container = document.getElementById('direct-chat-box-holder');
                var frame_direct_chat = document.createElement('iframe');
              
                frame_direct_chat.src = 'http://localhost:3000/direct/'+Room_Id;
                frame_direct_chat.title = 'Chat box';
                
                frame_direct_chat.frameBorder = '0';
                frame_direct_chat.width = '900';
                frame_direct_chat.height = '400';
                frame_direct_chat.id = 'direct_chat_id';
                direct_chat_container.appendChild(frame_direct_chat);
                let iframe_direct_chat = document.getElementById('direct_chat_id');
                iframe_direct_chat.contentWindow.location.reload();
               
            }
         
         
            
        });

          
   
    
});

after that in ajax call → i used api call

curl_setopt($ch, CURLOPT_URL, ‘http://localhost:3000/api/v1/login’);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘POST’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		curl_setopt($ch, CURLOPT_HTTPHEADER, [
		  		"Content-Type: application/json",
		 	]
		);
		
		$json_array = [
            'user' => $Get_User->username,
            'password' => $Get_User->password,
		]; 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘http://localhost:3000/api/v1/users.createToken’);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘POST’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
“Content-Type: application/json”,
“X-Auth-Token:” .$Login_Auth_Token,
“X-User-Id:” .$Login_User_Id
]
);
// Create body
$json_array = [
‘username’ => $Get_User->username
];
$body = json_encode($json_array);

and pass room id to iframe

but after that i got right corner in red background invalid user error
after some sec error msg disappear and direct chat open