Código de Google OS.
--------------------------------------------------------------------------------------
GOOGLE_ACCOUNTS_URL = 'https://www.google.com/accounts'
LOGIN_SOURCE = 'test_harness'
class CookieCollectorRedirectHandler(urllib2.HTTPRedirectHandler):
def __init__(self):
self.__cookie_headers = []
@property
def cookie_headers(self):
return self.__cookie_headers
def http_error_302(self, req, fp, code, msg, headers):
self.__cookie_headers.extend(fp.info().getallmatchingheaders('Set-Cookie'))
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp,
code, msg, headers)
return result
def Authenticate(email, password):
opener = urllib2.build_opener()
payload = urllib.urlencode({'Email': email,
'Passwd': password,
'PersistentCookie': 'true',
'accountType' : 'HOSTED_OR_GOOGLE',
'source' : LOGIN_SOURCE})
request = urllib2.Request(GOOGLE_ACCOUNTS_URL + '/ClientLogin', payload)
response = opener.open(request)
data = response.read().rstrip()
# Convert the SID=xxx\nLSID=yyy\n response into a dict.
l = [p.split('=') for p in data.split('\n')]
cookies = dict((i[0], i[1]) for i in l)
payload = urllib.urlencode({'SID': cookies['SID'],
'LSID': cookies['LSID'],
'source': LOGIN_SOURCE,
'service': 'gaia'})
request = urllib2.Request(GOOGLE_ACCOUNTS_URL + '/IssueAuthToken', payload)
response = opener.open(request)
--------------------------------------------------------------------------------------
class PamClient {
public:
/*
* Struct representing the username / password. This is assumed to
* be passed to the callback function
*/
struct UserCredentials {
std::string username;
std::string password;
};
/*
* Calls pam_start and initializes the pam environment
*/
explicit PamClient(UserCredentials* user_credentials);
/*
* Calls pam_end and frees memory
*/
virtual ~PamClient();
/*
* Starts the authentication loop. This initiates the call to the
* pam library and back to the conversation callback before returning
* Returns true on success, false on error
*/
bool Authenticate();
/*
* Sets the credentials obtained from authenticate and starts a session
* with the pam library
*/
bool StartSession();
Y sobre todo, ten paciencia.
Relacionado.