问题
I am working on a website which deals with Instagram pictures.
I have to direct the user to Instagram login page for verification. This process needs my website to send few parameters in the URL, for authorization. The format is given below.
From instagram docs -
https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code
It works fine when I use GET request to hit the Instagram URL. But now I want to hide these values from the URL and hide it from the user.
So I decided to write a JSF page that will on windows.onload submit the form parameters as hidden and hit the Instagram URL instead. This way I can hide the parameters.
JSF page
<h:body>
<h:form prependId="false">
<h:inputHidden id="client_id" value="#{applicationBean.instagramClientID}" /><br/>
<h:inputHidden id="redirect_uri" value="#{applicationBean.instagramRedirectUrl}" /><br/>
<h:inputHidden id="response_type" value="code" />
</h:form>
<script type="text/javascript">
window.onload = function submitPage() {
document.forms[0].action="#{applicationBean.instagramAuthUrl}";
document.forms[0].submit();
}
</script>
</h:body>
But this fails from the instagram side, giving code error 400.
{"code": 400, "error_type": "OAuthException", "error_message": "You must include a valid client_id, response_type, and redirect_uri parameters"}
I checked the values and they all seem to be fine. The only thing I noticed is a "form-id" also being passed. I assume this is causing the authorization failure, Since I need to send only specific parameters. If true how can I overcome this using POST request?
Or am I doing something wrong in my POST request?
Thanks in advance.
Environment : Java 1.6, JSF 2
回答1:
Try passing those values hardcoded and post results.
来源:https://stackoverflow.com/questions/12454981/redirect-a-user-to-instagram-login-using-post