Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get user profile? #94

Open
franzisk opened this issue Oct 19, 2016 · 2 comments
Open

How to get user profile? #94

franzisk opened this issue Oct 19, 2016 · 2 comments

Comments

@franzisk
Copy link

Hi there,

I am trying to recover user profile but after doing the call and getting the Manager (see below), when I try to get profile by getting the the provider with the manager I always get the exception:

SocialAuthConfig config = SocialAuthConfig.getDefault();
config.load(props);
manager = new SocialAuthManager();
manager.setSocialAuthConfig(config); // this is NOT null
...

/* alter calling facebook and returning the my URL I try */
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
Map<String, String> map = SocialAuthUtil.getRequestParametersMap(request);

if (this.manager != null) {
    //AuthProvider provider = manager.connect(SocialAuthUtil.getRequestParametersMap(request));

    AuthProvider provider = manager.connect(map); // ERROR here
    this.profile = provider.getUserProfile();

    // Do what you want with the data (e.g. persist to the database, etc.)
    System.out.println("User's Social profile: " + profile);

    // Redirect the user back to where they have been before logging in
    FacesContext.getCurrentInstance().getExternalContext().redirect(originalURL);
} else {
    FacesContext.getCurrentInstance().getExternalContext().redirect(externalContext.getRequestContextPath() + "/pages/home.jsf");
}

Exception:
org.brickred.socialauth.exception.SocialAuthException: Verification code is null

What is this "Verification code"?

When Facebook redirects back to my URL it comes with this:
/home.jsf?code=AQC1B1a4QDhkfQVtzCmXarf_fR4ZKbCVczKJ1kdDdcegN8l37C8uJ7afKNKSDWbTd0kupObDVMmJznfBGGhhCntSblzdFlaphIGfBpSEpGAZhbLSbckjQ6EIuBEbaauOb2yHUyUisiCKAwpfdCYt-NBN990HpuSo0UHeeUcIy34TbT_2Yy5H6-mKgc-LD9b0idDEEfCnty6qsU71uklLPKgq7n4FvZe00_-pRY5wOz2Pr-TORdOh62HI7GbjabLvUopl46cv6S2sG4Jw-RZU26w1GC9t7LIIbNXVRfaiiBedFm_Angu_vl-9TcZWBTVen-YDWrQfHos4Mq5RTIYh5DIz#=

What should I do with this code?

Appreciate any help.

Thanks

@Kaiser1989
Copy link

Kaiser1989 commented Dec 14, 2016

Access your parameter map and try to get the value for "code" key and check if it's null. Your error says, that it is null. Otherwise you can access code value manuelly and create a connection like this:

AccessGrant token = manager.createAccessGrant(PROVIDER, code, REDIRECT_URL);
AuthProvider provider = manager.connect(token);

Provider is your used provider, code the the value you ask for, and redirect url, the url back to your webapp

or if manager is already initialized:

Map<String,String> map = new HashMap<String, String>();
map.put("code", code);		
AuthProvider provider = manager.connect(map);

@linxianying
Copy link

Meet the same problem. Is there anyone who solved it? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants