flash.error("Mauvaise requète, le provider d'authentification n'est pas indiqué");
index(null);
}
OAuthProvider oauthProvider = OAuthProviderFactory.getProvider(provider);
OAuthService oauthService = oauthProvider.getService();
if (OAuth.isVerifierResponse()) {
// We got the verifier;
// now get the access tokens using the request tokens
final Token requestToken = new Token(flash.get(TOKEN_KEY), flash.get(SECRET_KEY));
final String verifier = params.get("oauth_verifier");
try {
Token accessToken = oauthService.getAccessToken(requestToken, new Verifier(verifier));
// Fetch user oAuthAccount
OAuthAccount oAuthAccount = oauthProvider.getUserAccount(accessToken.getToken(), accessToken.getSecret());
// Retrieve existing oAuthAccount from profile
AuthAccount account = AuthAccount.find(provider, oAuthAccount.getOAuthLogin());
if (account != null) {
onSuccessfulAuthentication(account.member.login);
} else {
// Pas d'account correspondant : new way of authentication
manageNewAuthenticationFrom(oAuthAccount);
}
} catch (OAuthException ex) {
Logger.error("Authentification impossible avec " + provider + " : " + ex.getLocalizedMessage());
flash.error("Authentification impossible");
index(null);
}
}
try {
Token token = oauthService.getRequestToken();
// We received the unauthorized tokens
// we need to store them before continuing
flash.put(TOKEN_KEY, token.getToken());
flash.put(SECRET_KEY, token.getSecret());
// Redirect the user to the authorization page
redirect(oauthService.getAuthorizationUrl(token));
} catch (OAuthException ex) {
Logger.error("Authentification impossible avec " + provider + " : " + ex.getLocalizedMessage());
flash.error("Authentification impossible");
index(null);
}