Announcement Announcement Module
Collapse
No announcement yet.
Incorrect return url after Facebook authentication Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Incorrect return url after Facebook authentication

    Hi All,
    I am following the spring social show case example and I am having issues relating to Facebook.
    My application will connect to Facebook and authorise the app but the return url is not correct.

    The "signup" process is initiated from a /login.jsp page and the return url redirects to the same.

    I am using Spring social 1.0.0RC1 and Spring 3.0.5RELEASE.
    Any help in resolving this is much appreciated.

    Thanks in advance.

  • #2
    A few of the details of your problem are unclear to me. To start, what callback URL were you expecting and what callback URL did you get? Was it Facebook complaining about the bad callback URL...or was the problem upon return from authorization with Facebook? Any details you can provide will be helpful in figuring this out.

    Comment


    • #3
      Thank you for the quick reply. I am referring to the callback url to the application after authentication from Facebook. Basically I have a "Login with Facebook" button on my login.jsp page. When invoked the Facebook login and permission authorisation dialog is presented. Once the user logs in and grants permission to the app, the app is seen to have successfully granted permission. This was verified by visiting the "Privacy Settings" settings on Facebook. However once the app is authorised I would like my application be be redirected to /signup where I can pull the necessary information from the graph api and pre-populate the fields.
      My issue is that after authorisation the application comes back to login.jsp, which was the starting point.

      Thanks.

      Comment


      • #4
        How are you initiating the sign-in? I assume you have a form that is submitting a POST request to /signin/facebook backed by a ProviderSignInController instance, as in the show case example? If so, the controller should handle the form POST and generate the callbackUrl in a way where it will process the callback. Upon receiving the callback, it will redirect the user to /signup if no local user is associated with the authorizing Facebook user. If you are not submitting your form to this controller, it's likely you'll need to handle this responsibility yourself. If you can provide a little more background there, that would be helpful. I sense you might be doing things a bit differently than the Showcase example.

        Keith
        Last edited by Keith Donald; Jun 27th, 2011, 08:15 PM.

        Comment


        • #5
          Hi Keith,

          Yes, I am sending a POST request to /signin/facebook backed by the ProviderSignInController. One thing I had done differently than the showcase example was that I used <fb:login-button> instead of a standard submit button. Once this was changed to a standard submit button the authorisation process happens as before but now I am being redirect to /signin/facebook. Ideally this should be /signup. Maybe I am missing a configuration somewhere. Given below are my configurations.

          Code:
          <form id="fb_signin" action="<c:url value="/signin/facebook"/>" method="POST">
              <button type="submit"><img src="<c:url value="images/social/facebook/sign-in-with-facebook.png"/>"/></button>
          </form>
          Code:
          @Configuration
          public class SocialConfig {
          
              //@Inject
              //private Environment environment;
          
              @Inject
              private DataSource dataSource;
          
              @Bean
              @Scope(value = "singleton", proxyMode = ScopedProxyMode.INTERFACES)
              public ConnectionFactoryLocator connectionFactoryLocator() {
                  ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
                  registry.addConnectionFactory(new FacebookConnectionFactory(
                          "<appID>",
                          "<appSecret>"));
                  return registry;
              }
          
              @Bean
              @Scope(value = "singleton", proxyMode = ScopedProxyMode.INTERFACES)
              public UsersConnectionRepository usersConnectionRepository() {
                  return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator(), Encryptors.noOpText());
              }
          
              @Bean
              @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
              public ConnectionRepository connectionRepository() {
                  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                  if (authentication == null) {
                      throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in");
                  }
                  return usersConnectionRepository().createConnectionRepository(authentication.getName());
              }
          
              @Bean
              @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
              public Facebook facebook() {
                  Connection<Facebook> facebook = connectionRepository().findPrimaryConnection(Facebook.class);
                  return facebook != null ? facebook.getApi() : new FacebookTemplate();
              }
          
              @Bean
              @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
              public Twitter twitter() {
                  Connection<Twitter> twitter = connectionRepository().findPrimaryConnection(Twitter.class);
                  return twitter != null ? twitter.getApi() : new TwitterTemplate();
              }
          
          //    @Bean
          //    public ConnectController connectController() {
          //        ConnectController connectController = new ConnectController(connectionFactoryLocator(), connectionRepository());
          //        connectController.addInterceptor(new PostToWallAfterConnectInterceptor());
          //        connectController.addInterceptor(new TweetAfterConnectInterceptor());
          //        return connectController;
          //    }
          
              @Bean
              public ProviderSignInController providerSignInController() {
                  ProviderSignInController controller = new ProviderSignInController(connectionFactoryLocator(),
                          usersConnectionRepository(), new SimpleSignInAdapter());
                  URL appUrl = null;
                  try {
          
                      appUrl= new URL("<my-app-url>");
                  }
                  catch (Exception e) {
          
                  }
                  controller.setApplicationUrl(appUrl);
                  return controller;
              }
          
          }

          Comment


          • #6
            Yeah, that's most likely the issue. If you use the fb:login-button tag, it will handle the OAuth redirect for you in JavaScript. You'd be bypassing ProviderSignInController then, and dealing with Facebook's JavaScript API. Craig can likely provide more insight on exactly how fb:login-button works, and how it could be used in conjunction with Spring Social--you can also get more info from Facebook's developer reference.

            After you changed things to a regular form posting to /signin/facebook, which doesn't require any special JavaScript and also can be used to support sign-in with multiple providers in the same way, you're getting what I expect. The authorization callback will come back to /signin/facebook, and then a redirect will happen to /signup if no local user could be mapped from the Facebook user (otherwise the user will be signed-in). You can see this in the showcase sample as well as the Greenhouse reference app when you try to sign-in with your Facebook account there. This should give you what you want, unless I'm missing something. You might also want to review the sign-in chapter of the Spring Social reference manual.

            We should make it clear in our reference documentation how our Facebook sign-in support relates to what Facebook already provides developers via fb:login-button, etc.

            Keith
            Last edited by Keith Donald; Jun 28th, 2011, 08:41 AM.

            Comment


            • #7
              Hi Keith,

              Thank you for the explanation provided. I am still concerned as to why I am not redirected /signup when there is no use account associated with the Facebook user. I am using the JdbcUsersConnectionRepository.sql to create my connections table.

              Comment


              • #8
                Not sure what to tell you. I would confirm you see the behavior you expect reflected in our samples and reference apps first. Assuming you do, and you don't see any relevant differences between the samples and your app, you might want to consider setting a breakpoint in your application for the oauth1 and 2 callback handler methods in ProviderSignInController, trigger them, and step into the handleSignIn method. Within that method you'll see the /signup redirect branch, perhaps using the debugger you can determine why it's not being triggered? Do you have a ConnectionSignUp command configured against your UsersConnectionRepository and aren't aware of that? You don't want that if you wish to require users that cannot be mapped to sign up explicitly.
                Last edited by Keith Donald; Jun 28th, 2011, 12:16 PM.

                Comment


                • #9
                  Found the issue. There was a url rewrite rule in my application that was causing an additional /app that was being added to the oauth response url. Thanks again for the clarifications provided.

                  Comment


                  • #10
                    Hi,
                    I have the same issue which says "Error Message: redirect_uri URL is not properly formatted", i registered the application in facebook with site url as"http://localhost:8080/spring-social-showcase/signin" , when i try to access i get the error message, please let me know as whether am registering the application right?
                    and could be the problem.
                    I am trying to run the spring-social-showcase example.

                    Comment


                    • #11
                      The correct URL to use when registering the app is http://localhost:8080/spring-social-showcase/. You don't need the "signin" part.

                      Comment


                      • #12
                        API Error Code: 100
                        API Error Description: Invalid parameter
                        Error Message: redirect_uri URL is not properly formatted

                        this is what i get when i am logged into Facebook, my site url is http://localhost:8080/spring-social-showcase/
                        i have not specified the site domain.

                        Comment


                        • #13
                          A couple of things you might try:

                          1. Run the showcase as-is from GitHub with no changes. It's already configured to use the app that I registered...and it should work. If it doesn't, I'd be interested in knowing that.
                          2. Capture the redirect_uri parameter that is sent to FB. This is tricky because FB immediately redirects, but if you have Safari's Web Inspector or Firebug for Firefox, you should be able to see the URL that ConnectController redirected to and it should have the redirect_uri parameter. If your site URL is http://localhost:8080/spring-social-showcase, then I'd expect redirect_uri to be http%3A%2F%2Flocalhost%3A8080%2Fspring-social-showcase%2Fconnect%2Ffacebook. If it's something different, let me know what it is and I'll see if I can help you figure it out.

                          Comment


                          • #14
                            Thanks for the reply...

                            It works for me now... its because i was mentioning localhost with my machine name.
                            Which is not working if i mention my machine name instead of localHost.

                            Thanks

                            Comment

                            Working...
                            X