Skip to content

Instantly share code, notes, and snippets.

@stoicflame
Created March 25, 2015 19:22
Show Gist options
  • Save stoicflame/34f82d7157f3372854a7 to your computer and use it in GitHub Desktop.
Save stoicflame/34f82d7157f3372854a7 to your computer and use it in GitHub Desktop.
Using the FamilySearch Client For OAuth 2 Authorization Code Flow
package org.familysearch.api.client;
import org.gedcomx.rs.client.PersonState;
/**
* @author Ryan Heaton
*/
public class Main {
public static void main(String[] args) {
//supply the app key.
String appKey = "...";
//supply the URI where the user will be redirected after successfully authenticating to FamilySearch.
String redirect = "http://localhost:8000/myapp/handle-redirect";
//set up the configuration for the client.
Client.Config config = new Client.Config()
.appKey(appKey)
.redirectUri(redirect);
Client client = new Client(config);
String authUri = client.getOAuth2AuthorizationUri();
//now redirect the user to 'authUri'
String authCode = redirectUserAndWaitForAuthCodeResponse(authUri);
//authenticate the client:
client.authenticateWithAuthCode(authCode);
//now you can do work with the Family Tree:
PersonState personState = client.familyTree().readPersonForCurrentUser();
}
private static String redirectUserAndWaitForAuthCodeResponse(String authUri) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment