Thursday, June 1, 2017

OAuth with GWT against Strava API

I am trying to create a GWT application against the Strava API. The first thing to do is authentication.

On http://strava.github.io/api/v3/oauth/ they say that for the token exchange you have to do something like :

curl -X POST https://www.strava.com/oauth/token \ -F client_id=5 \ -F client_secret=7b2946535949ae70f015d696d8ac602830ece412 \ -F code=75e251e3ff8fff


As far as I know those -F things represent fields in a multiform post ? 
So I created something like : 

final FormPanel form = new FormPanel(); 
container.add(form); 
form.setAction("https://www.strava.com/oauth/token"); 
form.setEncoding(FormPanel.ENCODING_MULTIPART); 
form.setMethod(FormPanel.METHOD_POST); 
VerticalPanel panel = new VerticalPanel(); 
form.setWidget(panel);
panel.add(new Hidden("client_id", CLIENT_ID)); 
panel.add(new Hidden("client_secret", CLIENT_SECRET)); 
panel.add(new Hidden("code", code)); 
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() 
   @Override 
   public void onSubmitComplete(SubmitCompleteEvent event) 
   { 
      GWT.log("complete " + event.getResults()); 
   } 
}); 
container.addAttachHandler(new AttachEvent.Handler() 
   @Override 
   public void onAttachOrDetach(AttachEvent event) 
   { 
      form.submit(); 
   } 
}); 


Now when I do this I see the following error in Chrome dev tools :

Refused to display 'https://www.strava.com/oauth/token' in a frame because it set 'X-Frame-Options' to 'deny'. 
FormPanelImpl.java:117 POST https://www.strava.com/oauth/token net::ERR_BLOCKED_BY_RESPONSE


Now the questions are. 
Am I correct by creating a form to mimic that curl example ? 
Has that frame error something to do with GWT using IFRAME stuff ? How do I fix this ?

thanks

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment