0
votes

So I'm working on developing a Instagram Basic Display call and for some reason it's stripping out a query string.

Here is all the information:
Where the /auth/authenticate/ button lived: ***/wp-admin/options-general.php?page=instagram_auth

$auth_url .= '/?client_id=' . $this->instagram->get_client_id() . '&redirect_uri=' . $this->instagram->get_redirect_uri() . '&scope=user_profile,user_media&response_type=code';

The auth window pops up with the following code and I can then authenticate:

https://www.instagram.com/oauth/authorize/?client_id=28822****&redirect_uri=****/wp-admin/options-general.php?page=instagram_auth&scope=user_profile,user_media&response_type=code

Here is the problem:

When I click "Accept", Instagram redirects to:

/wp-admin/options-general.php?code=AQBWjP-foZA7tkhUCTZygn5CBNbiJJxmY364eLPm0bD9NpetQbzUqJSw4LiueRDg_jiDzW8l_8js2JHFAZcPom8zFR-86x_*-X11H1-kTPCPrQ#_

It strips out the ?page=instagram_auth parameters which is needed inside my code.. My valid OAuth Redirect URI is: ***/wp-admin/options-general.php?page=instagram_auth.

Does anyone know why the parameter gets stripped out?

1
When you introduce one URL into another as a parameter, then you need to properly URL encode the value. - CBroe
@CBroe, what's the best approach for this? - Tripp
Just use php.net/manual/en/function.urlencode.php on the values you are inserting into that auth URL. Or use php.net/manual/en/function.http-build-query.php to begin with. - CBroe
Did you ever solve this @Tripp? I'm having a similar problem. urlencoding the URL doesn't seem to work, I just get told it's invalid by the API. - Joel
encoding the URL does not work. It yields the same result, i.e. redirects to /wp-admin/options-general.php - Amir Asyraf

1 Answers

0
votes

There is a state parameter that can be added to the OAuth Authorize request which will be passed through when it redirects to your redirect URI.

An optional value indicating a server-specific state. For example, you can use this to protect against CSRF issues. We will include this parameter and value when redirecting the user back to you.

(From the Facebook Instagram API docs) https://developers.facebook.com/docs/instagram-basic-display-api/reference/oauth-authorize