Sign in to follow this  
Followers 0
Decipher

WinHttp authenticate to Google using ClientLogin

2 posts in this topic

I keep getting the Error=BadAuthentication response.

#include-once
 #include "WinHTTP.au3"

;Reference = https://developers.google.com/accounts/docs/AuthForInstalledApps#AuthProcess
; GrandCentral or Google Voice as most know it isn't listed as a service VIA 0Auth2.0

$sReply = _GoogleClientLogin("anon@gmail.com", "password", "grandcentral", "autoIt")
MsgBox(0, "", $sReply) ; Error=BadAuthentication


Func _GoogleClientLogin($sUsername, $sPassword, $sService, $sSource)

    Local Const $sUSER_AGENT = 'Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20130419 Firefox/23.0'
    Local Const $sSERVER_NAME = 'www.google.com'
    Local Const $sOBJECT_NAME = '/accounts/ClientLogin'
    Local Const $sREFERRER = 'https://www.google.com'
    Local Const $sCONTENT_TYPE = 'Content-Type: application/x-www-form-urlencoded'

    $sLoginData = '' & _
        'Email=' & __WinHttpURLEncode($sUsername) & _
        '&Passwd=' & __WinHttpURLEncode($sPassword) & _
        '&service=' & __WinHttpURLEncode($sService) & _
        '&source=' & __WinHttpURLEncode($sSource)

    ConsoleWrite('!>(AuthString)' & @TAB & $sLoginData & @CRLF)

    $hOpen = _WinHttpOpen($sUSER_AGENT)
    $hConnect = _WinHttpConnect($hOpen, $sSERVER_NAME, $INTERNET_DEFAULT_HTTPS_PORT)
    $hRequest=_WinHttpOpenRequest($hConnect, Default, $sOBJECT_NAME, Default, $sREFERRER, '', $WINHTTP_FLAG_SECURE)
    _WinHttpAddRequestHeaders($hRequest, $sCONTENT_TYPE)
    ;_WinHttpAddRequestHeaders($hRequest, 'Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5')
    ;_WinHttpAddRequestHeaders($hRequest, 'Accept-Charset: utf-8;q=0.7')
    _WinHttpAddRequestHeaders($hRequest, $sLoginData) ; <-- Append Login Data to Request Header
    _WinHttpSendRequest($hRequest)
    _WinHttpReceiveResponse($hRequest)
    $sResponse = _WinHttpQueryHeaders($hRequest)
    $sResponse &= @CRLF & _WinHttpReadData($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Return $sResponse

EndFunc

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites



I tried using the WinHTTP object but it returns the same as the original function.

Func _AlternativeMethod($sUsername, $sPassword, $sService, $sSource)
    $sLoginData = '' & _
        'accountType=HOSTED_OR_GOOGLE' & _
        '&Email=' & __WinHttpURLEncode($sUsername) & _
        '&Passwd=' & __WinHttpURLEncode($sPassword) & _
        '&service=' & __WinHttpURLEncode($sService) & _
        '&source=' & __WinHttpURLEncode($sSource)
    $oWinHttpReq = ObjCreate('WinHttp.WinHttpRequest.5.1')
    $oWinHttpReq.Open('POST', 'https://www.google.com/accounts/ClientLogin', false)
    $oWinHttpReq.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    $oWinHttpReq.Send($sLoginData)
    $sResponse = $oWinHttpReq.ResponseText
    Return $sResponse
EndFunc

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0