int authProvider = credential.getAuthProvider();
logger.info("authProvider: " + authProvider);
String authProviderName = ClientUtils.getAuthProviderName(authProvider);
logger.info("Verifying social usr from " + authProviderName);
Token requestToken = null;
InstragramToken instragramToken = null;
String yahooGuid = null;
String protectedResourceUrl = ClientUtils.getProctedResourceUrl(authProvider);
if (authProvider == ClientUtils.FACEBOOK || authProvider == ClientUtils.INSTAGRAM)
{
logger.info("Verifying state: " + credential.getState());
verifyState(credential.getState());
}
// some providers requires request token to get access token
/*
switch(authProvider)
{
case ClientUtils.TWITTER:
case ClientUtils.YAHOO:
case ClientUtils.LINKEDIN:
case ClientUtils.FLICKR:
case ClientUtils.IMGUR:
case ClientUtils.VIMEO:
case ClientUtils.TUMBLR:
{
requestToken = getRequestTokenFromSession();
if (requestToken == null)
{
throw new OurException("Could not retrieve Request Token form HTTP session");
}
break;
}
}
*/
/* if there is any request token in session, get it */
requestToken = getRequestTokenFromSession();
OAuthService service = null;
Verifier verifier = null;
Token accessToken = null;
/* Get Access Token */
if (authProvider != ClientUtils.DEFAULT)
{
service = getOAuthService(authProvider);
verifier = new Verifier(credential.getVerifier());
logger.info("Requesting access token with requestToken: " + requestToken);
logger.info("verifier=" + verifier);
try
{
accessToken = service.getAccessToken(requestToken,verifier);
if (accessToken == null)
{
logger.error("Could not get Access Token for " + authProviderName);
throw new OurException("Could not get Access Token");
}
}
catch (Exception e)
{
logger.info("Exception received gettign Access Token: " + e);
throw new OurException("Exception received getting Access Token: " + e);
}
logger.info("Got the access token: " + accessToken);
logger.info(" Token: " + accessToken.getToken());
logger.info(" Secret: " + accessToken.getSecret());
logger.info(" Raw: " + accessToken.getRawResponse());
}
else
{
/*
** Default provider.
** The info will probably come from database. Password will
** probably some kind of salted hash. We're just hard coding
** "test" and "secret" for the demo.
*/
logger.info("Handing default loign..");
String username = credential.getLoginName();
String password = credential.getPassword();
if (username == null)
{
throw new OurException("Default Username can not be empty");
}
if (password == null)
{
throw new OurException("Default Password not be empty");
}
if (username.equals(getDefaultUsername()) && password.equals(getDefaultPassword()))
{
}
else
{
throw new OurException("Please use " + getDefaultUsername() + " and " + getDefaultPassword() + " as Default Credential!");
}
}
if (authProvider == ClientUtils.INSTAGRAM)
{
try
{
instragramToken = InstragramToken.parse(accessToken.getRawResponse());
} catch (ParseException e)
{
throw new OurException("Could not parse " + authProviderName + " Json AccessToken");
}
logger.info("Getting Instragram Access Token");
logger.info(" access token" + instragramToken.getAcessToken());
logger.info(" userId: " + instragramToken.getUserId());
logger.info(" full name: " + instragramToken.getFullName());
logger.info(" username: " + instragramToken.getFullName());
logger.info(" raw: " + instragramToken.getRawResponse());
// replace userId and access token in protected resource url
protectedResourceUrl = ClientUtils.getProctedResourceUrl(authProvider);
logger.info("Instragram protected resource url: " + protectedResourceUrl);
protectedResourceUrl = String.format(protectedResourceUrl, instragramToken.getUserId(),instragramToken.getAcessToken());
logger.info("Instragram protected resource url: " + protectedResourceUrl);
}
if (authProvider == ClientUtils.GITHUB ||
authProvider == ClientUtils.FOURSQUARE)
{
protectedResourceUrl = String.format(protectedResourceUrl,accessToken.getToken());
}
if (authProvider == ClientUtils.YAHOO)
{
//throw new OurException("Not implemented for yahoo yet!)");
/* we need to replace <GUID> */
yahooGuid = getQueryStringValue(accessToken.getRawResponse(),"xoauth_yahoo_guid");
if (yahooGuid == null)
{
throw new OurException("Could not get Yahoo GUID from Query String");
}
// must save it to session. we'll use to get the user profile