jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.56k stars 4.02k forks source link

Social Login Facebook #2349

Closed nickbar86 closed 9 years ago

nickbar86 commented 9 years ago

Hello, i am experimenting with Facebook login. I have created an App on Facebook with v2.5Api which i have inserted it in application.yml file. However when i try to login, after inserting the login creds on fb page i get an Exception on this line UserProfile userProfile = connection.fetchUserProfile(); Welcome any idea or hint:)

DEBUG] org.eventer.aop.logging.LoggingAspect - Enter: org.eventer.service.SocialService.createSocialUser() with argument[s] = [org.springframework.social.connect.support.OAuth2Connection@b215c6b2, en] org.springframework.social.UncategorizedApiException: (#100) Tried accessing nonexisting field (address) on node type (User) at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleFacebookError(FacebookErrorHandler.java:91) at org.springframework.social.facebook.api.impl.FacebookErrorHandler.handleError(FacebookErrorHandler.java:59)

moifort commented 9 years ago

Facebook has upgraded their api and the spring-social-facebook is not compatible, there is a PR on the project pending: https://github.com/spring-projects/spring-social-facebook/pull/178. You have a solution to fix it on stack: http://stackoverflow.com/questions/33053185/spring-social-facebook-uncategorizedapiexception-3-application-does-not-have/33180915#33180915

emanuelbatista commented 8 years ago

Solution:

    @PostConstruct
    private void init() {
        try {
            String[] fieldsToMap = {
                "id", "about", "age_range", "bio", "birthday", "context", "cover", "currency", "devices", "education", "email", "favorite_athletes", "favorite_teams", "first_name", "gender", "hometown", "inspirational_people", "installed", "install_type","is_verified", "languages", "last_name", "link", "locale", "location", "meeting_for", "middle_name", "name", "name_format","political", "quotes", "payment_pricepoints", "relationship_status", "religion", "security_settings", "significant_other","sports", "test_group", "timezone", "third_party_id", "updated_time", "verified", "viewer_can_send_gift","website", "work"
            };

            Field field = Class.forName("org.springframework.social.facebook.api.UserOperations").
                    getDeclaredField("PROFILE_FIELDS");
            field.setAccessible(true);

            Field modifiers = field.getClass().getDeclaredField("modifiers");
            modifiers.setAccessible(true);
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
            field.set(null, fieldsToMap);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
MichalFoksa commented 8 years ago

There is a similar issue with spring-social-facebook now:

org.springframework.social.UncategorizedApiException: (#12) bio field is deprecated for versions v2.8 and higher

Above workaround by @emanuelbatista works just fine, just drop bio from fieldsToMap array.