Not fully redirected after Laravel Passport redirect - local

Viewed 13

I have a React site trying to get access token from my Laravel oAuth portal (using Passport). As I understand from the documentation, I create the state,code challenge and code verifier on my react app. I create a url with the required parameters and make a redirection to /oauth/authorize. The complete code for the redirection is window.location.replace('http://portal.test/oauth/authorize?' + paramsStr). http://portal.test is my oAuth portal (using Valet) and paramsStr contains all my parameters: client_id, redirect_uri, response_type, scope, state, code_verifier, code_challenge, code_challenge_method.

I am redirected to the portal as I should which redirects me to the login form. Once logged in, I have to approve the authorization request. After that step, I am supposed to be redirected to my React app to verify the state parameter and then make a POST request to my oAuth portal to request an access token. (again, from the documentation)

My issue here is that I am not "entirely" redirected. The url in my browser is still http://portal.test/login (the oAuth portal url) where it should be http://auth.localhost:3006 (the React app). I do have kind of a popup that opens, showing the content of the React app but I have a problem with my cookies. In the first step, after creating the state,code challenge and code verifier, I store those (using react-cookie). If I check the cookies right after, I can see them. If I go to another page of my React app, I can see them. If I manually go to another url (like google for example) and then go back to my React app, I can see them. So I know that setting the cookies does work. But in that weird popup I can't access the cookies.

I guess that a redirection issue and I can't access them because the url in the browser in not the url of my React app. How can I fix that ?

Relevant code for the login

    const [cookies,setCookie,removeCookie] = useCookies([]);
    setCookie('code_challenge',code_challenge);
    setCookie('code_verifier',code_verifier);
    setCookie('state',state);
    console.log(cookies); // this shows the 3 values
    window.location.replace('http://portal.test/oauth/authorize?' + paramsStr;

Page I am redirected to within React app

    const [cookies,setCookie,removeCookie] = useCookies(["foo"]);
    console.log(cookies); // empty

In the url to /oauth/authorize the parameter redirect_uri is http://auth.localhost:3006. In the DB in the oauth_clients table, the redirect value is the same.

0 Answers
Related