Communicating between a page and a popup oauth page - php

I have an application that has a button which opens a blank page for linkedin oauthentication.
My question is, when the user completes authentication and processing for linkedin, how do I tell the original page that this process is complete?
I was thinking about creating an ajax method that tells the database that the user is in oauth and when they are complete we tell the same database that the process is over and the original page will find out.
Any ideas?

See: How can I do OAuth request by open new window, instead of redirect user from current page?
The trick is the window.opener property, available from the popup. Using that you could do something simple like a reload window.opener.location.reload() or possibly something more complicated using postMessage (in either case the code would live in the page that OAuth redirects to on completion).

Related

Server-Side redirection after a fetch request

Let's say, we work on a project in a web tool and after some period of time the app wants to save the project as backup before the session expire.
For the saving, we use fetch method(it could be AJAX, Axios etc) and we post a request to a controller function, in which we save the project, clear the session and want to redirect to the home page. I've tried this scenario with Laravel but when the time for redirection come, the session data is cleared but the server doesn't redirect to the home page.
Is it because of the fact that the fetch and the other types of asynchronous functions wait always for response?
A redirect means "What you asked for can be found here" not "Load this URL in the main browser window".
If the browser was asking for a URL with the intention of showing it in the main browser window (e.g. a link was clicked) then it would follow the redirect and show it in the main browser window.
If the browser was planning to do something else (e.g. render an <img>) then it would follow the redirect, get the image at the new URL, and render that in the <img>'s spot.
Ditto Ajax. You are making a request with Ajax, so the browser follows the redirect and gives the resource at the new URL to JavaScript to process.
If you want to make a POST request which loads a new document in the main browser window: Submit a form and don't use Ajax.

Getting html page after authentication

I have to download a page to parse some value in it. I would like to use PHP, it download the page, parse the data and return html with results. But i have to login before on the site to get the target page. How can i do it with php?
Best option is to follow the logon process when logging in manually using a browser like Google Chrome. You need to enable the network monitor. Press F12 to enable the developer tools, navigate to tab 'Network' and enable the checkmark at 'Preserve Log'. You can optionally select the disable cache checkmark.
Then clear all history and cookies so you're sure the site doesn't logon automatically.
No you're set to logon manually through the website. Type the site's URL for the login page and watch the items in the developer tools roll by. When your login is complete, head over to the top of the list of items in the network and look for a POST entry in the second column. This usually indicates the browser posting the logon information to the website.
Most sites respond using a 30x response and place a cookie. Now you now how the site operates.
Have a look at my answer to a similar question: PHP curl login couldn't pass login page
and use the CURL library to first logon, receive the cookie and while keeping the connection open get the page after the login you need.

PHP External Oauth : how to displaying a waiting message while waiting for callback (not using AJAX)

We allow external OAuth using PHP APIs to several social networks. When the user choose external authentication, a new window (popup) is opened, where the application asks authorization. Then, still in the popup, the user is redirected using the callback url given to the external application. The callback script performs various tasks (login, checks, synchronization,...) that may requires some time, before the popup is closed, and the mother page updated. While those task are performed, the popup is just blank.
What I would like is to display a "please wait..." message on the popup when the callback url is called. One solution is that the popup just display the message and pass an AJAX, but as I don't know the parameters of the callback (that depends on the external application), I would like to avoid this. Is there any way to do it with only one PHP script ?
You can perform the authorization in an iFrame (will require additional work to sync the iframe with the popup to get to the behaviour you have in mind) and design the window as you desire.
You can also just set the title.
As the service will return you to your server - you can try next:
1. Set transfer encoding to chunked.
2. Echo javascript document.write with loader img.
3. Do your processing.
4. Close the window after processing ends.

How to create a link in a site that will login another site?

There is a simple site, let's call it http://foo.com/ , with a simple user/pass form that sends a post request to http://foo.com/login.php to login the user.
How to create a link in another site, say http://foo_autologin.com/ , that will login with a pre-determined password on http://foo.com/ and open it, logged in, in another tab?
You can have http://foo_autologin.php (doesn't have to be php, can be html) use Javascript to open a new window pointed to a file called proxy_login.php or something. Then use CURL to post the login credentials to http://foo.com. Checkout Curl Documentation and look in the examples.

Logout from google account. Call a URL in the background/in a hidden way

I need to log out the user from google apps account. Now in my application I want that when the user clicks on LOGOUT the following should happen:
1. he should get logged out from Google apps account - For this I need to send a hidden request to the URL - https://mail.google.com/a/aspiringminds.in/?logout&hl=en
I am able to call this url easily. What I need is to call this url in a hidden manner ie the user should not be redirected to this page or see this page. This is the major part where I am stuck. I have tried curl, javascript popup window, iframe, php redirection but nothing seems to work. I think only server side request will help here like 'curl'. Pleaaassseee help !!!!
2. If the user is successfully logged out - I need to take him to this page - sign_in.php?logout=1
I have been trying to do this since the last 2 days but am unable to do so. Please help.
omg just use jquery like this
$('#logoutlink').click(function(){
$.get('http://..............');return false;
};);
that will call the url from client side but will ignore the returned data
Why not just use an iframe of size 1x1 of that url, that way the user won't even realise it.

Categories