Home > other >  Instagram Authorization Page Redirect is Endlessly Reloading My Web Page
Instagram Authorization Page Redirect is Endlessly Reloading My Web Page

Time:12-28

So I have the following method from the Instagram Basic Display API:

public function get_authorization_window(): string
    {
        $auth_url = $this->instagram->get_api_oauth_url() . '?' . http_build_query([
            'client_id' => $this->instagram->get_client_id(),
            'redirect_uri' => admin_url('options-general.php?page=instagram_auth'),
            'scope' => 'user_profile,user_media',
            'response_type' => 'code',
            'state' => admin_url('options-general.php?page=instagram_auth'),
        ]);

        return '<a  href="' . $auth_url . '">Please click here to authorize Instagram for this site</a></p>';
    }

Now, when it builds the URL, it returns a code=dsgzdfsgzsfsbfb parameter.

Here is the URL that I get in return: https://test.com.local/wp-admin/options-general.php?code=fsdgsfgfbxf.

Here is where I would like to be redirected: https://test.com.local/wp-admin/options-general.php?page=instagram_auth&code=fsdgsfgfbxf.

The following param need to get added: page=instagram_auth&.

I tried using this piece of code, but I am stuck in a redirect loop:

if (!empty($_GET['code'])) {
     $this->instagram->set_code($_GET['code']);
     header('Location:' . $config['redirect_uri'] . '&code=' . $_GET['code']);
     die();
}

Does anyone know how I can call a redirect but redirect just once and maybe build a link based on the code param?

CodePudding user response:

Here is the URL that I get in return:

https://test.com.local/wp-admin/options-general.php?code=fsdgsfgfbxf.

Here is where I would like to be redirected:

https://test.com.local/wp-admin/options-general.php?page=instagram_auth&code=fsdgsfgfbxf.

The order doesn't really matter. If you only have the first string, the following URL should be just as sufficient:

https://test.com.local/wp-admin/options-general.php?code=fsdgsfgfbxf&page=instagram_auth

Notice, I just add the param on at the end. This only requires that you append the &page=instagram_auth param to the string you already have.

The page should work the same, no matter what order the GET params are in.

It's difficult to say what exactly is going on, but maybe try?

if (!empty($_GET['code']) && $_GET['done'] != "1")) {
     $this->instagram->set_code($_GET['code']);
     header('Location:' . $config['redirect_uri'] . '&done=1&code=' . $_GET['code']);
     die();
}
  • Related