I'm trying to do facebook login using spring boot social. To do this I create url from facebook properties. I have url and when I get it from debug mode and put into browser it's working as I wish (so link is ok), but when I send redirect from spring controller nothing happen. In google chrome I can see that request was send and I can also see such errror in chrome console:
Failed to load [url]. Response for preflight is invalid (302 status).
My controller method:
@RequestMapping(value = "/connect/facebook", method = RequestMethod.POST)
public String send(Model model){
String url = socialMediaService.createAuthorizationURL();
return "redirect:" + url;
}
I know that it's some problem with redirecting to this link but I don't know how to do this in proper way.
EDIT:
It was all about CORS „Access-Control-Allow-Origin” attribute. It's enough to send this redirect trough javascript with dataType "jsonp", like this:
$.ajax({
url: data.url,
type: "get",
dataType: "jsonp"
});
The "redirect:" + url
approach is intended for the use case where you might normally return a view. You can set that view's name to "redirect:" + url
and then return it to issue a redirect instead of rendering your view normally. Since your controller operation is always redirecting, try returning a RedirectView
:
@RequestMapping(value = "/connect/facebook", method = RequestMethod.POST)
public RedirectView send(Model model){
String url = socialMediaService.createAuthorizationURL();
return new RedirectView(url);
}
Additionally, you will want to ensure that you use the correct one of https
versus http
and that your url is properly constructed. For example, https://example.url/resource
may not be the same as https://example.url/resource/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.