2 * Copyright (C) 2010 Prasanta Paul, http://prasanta-paul.blogspot.com
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.pras.auth;
\r
19 import com.pras.Log;
\r
20 import com.pras.conn.HttpConHandler;
\r
21 import com.pras.conn.Response;
\r
24 * This will provide a basic and LOW Level way of getting Authetication Token
\r
25 * for various Google's services.
\r
26 * This is a generic approach for core Java. User can add Platform specific Autheticator
\r
28 * @author Prasanta Paul
\r
31 public class BasicAuthenticatorImpl implements Authenticator {
\r
33 final String TAG = "BasicAuthenticatorImpl";
\r
34 // Google Authentication URL
\r
35 private final String GOOGLE_CLIENT_LOGIN_URL = "https://www.google.com/accounts/ClientLogin";
\r
38 public BasicAuthenticatorImpl(Account account){
\r
39 this.account = account;
\r
43 * @see com.pras.auth.Authenticator#getAuthToken(java.lang.String)
\r
45 public String getAuthToken(String service) {
\r
46 if(account == null){
\r
47 Log.p(TAG, "No Account Info "+ account);
\r
50 // TODO Auto-generated method stub
\r
51 String postData = "accountType="+ account.getAccountType() +"&Email="+ account.getEmail() +"&Passwd="+ account.getPassword() +"&service="+ service +"&source=test-app-log";
\r
53 HttpConHandler http = new HttpConHandler();
\r
54 Response res = http.doConnect(GOOGLE_CLIENT_LOGIN_URL, HttpConHandler.HTTP_POST, null, postData);
\r
60 String out = res.getOutput();
\r
62 * Format of success response
\r
63 * SID=<>LSID=<>Auth=<>
\r
65 String[] parms = out.split("=");
\r
66 String authToken = null;
\r
67 for(int i=0; i<parms.length; i++){
\r
68 if(parms[i].toLowerCase().endsWith("auth")){
\r
69 authToken = parms[i+1];
\r