1 /*******************************************************************************
2 * Copyright © Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
4 * This file is part of the work and learning management system Pentila Nero.
6 * Pentila Nero is free software. You can redistribute it and/or modify since
7 * you respect the terms of either (at least one of the both license) :
8 * - under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
12 * License, or any later version
13 * - the GNU Lesser General Public License as published by the
14 * Free Software Foundation, either version 3 of the license,
15 * or (at your option) any later version.
17 * There are special exceptions to the terms and conditions of the
18 * licenses as they are applied to this software. View the full text of
19 * the exception in file LICENSE-PROJECT.txt in the directory of this software
22 * Pentila Nero is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * Licenses for more details.
27 * You should have received a copy of the GNU Affero General Public License
28 * and the CeCILL-C and the GNU Lesser General Public License along with
29 * Pentila Nero. If not, see :
30 * <http://www.gnu.org/licenses/> and
31 * <http://www.cecill.info/licences.fr.html>.
32 ******************************************************************************/
33 package com.pentila.entSavoie.mobileNotification.androidUtils;
34 import java.io.BufferedReader;
35 import java.io.IOException;
36 import java.io.InputStreamReader;
37 import java.util.ArrayList;
38 import java.util.List;
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42 import org.apache.http.HttpResponse;
43 import org.apache.http.NameValuePair;
44 import org.apache.http.client.HttpClient;
45 import org.apache.http.client.entity.UrlEncodedFormEntity;
46 import org.apache.http.client.methods.HttpPost;
47 import org.apache.http.message.BasicNameValuePair;
50 public class AuthenticationUtils {
54 public static String getAuthCode(String email, String psswd) {
57 String AUTH_CODE=null;
59 HttpClient client = HTTPUtils.getNewHttpClient();
60 client = WebClientWrapper.wrapClient(client);
61 HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin");
65 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
66 nameValuePairs.add(new BasicNameValuePair("Email", email));
67 nameValuePairs.add(new BasicNameValuePair("Passwd", psswd));
68 nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE"));
69 nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example"));
70 nameValuePairs.add(new BasicNameValuePair("service", "ac2dm"));
72 post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
73 HttpResponse response = client.execute(post);
74 BufferedReader rd = new BufferedReader(new InputStreamReader(
75 response.getEntity().getContent()));
78 while ((line = rd.readLine()) != null) {
79 if (line.startsWith("Auth=")) {
80 AUTH_CODE = line.substring(5);
84 } catch (IOException e) {
89 System.out.println("In setAuthCode AUTH_CODE generated is "+AUTH_CODE);
94 public static void main(String[] args) {
95 System.out.println(AuthenticationUtils.getAuthCode(args[0], args[1]));