VBA-tools / VBA-Web

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
http://vba-tools.github.io/VBA-Web/
MIT License
2.01k stars 494 forks source link

GoogleAuthenticator - Stopped at access token window #431

Closed carlesserra closed 4 years ago

carlesserra commented 4 years ago

I'm trying VBA-tools to use Google Calendar API but after the user gives permission, the process gets stopped at this window, showing the access token:

image

Maybe it's an stupid question, but I don't know else to try.

zgrose commented 4 years ago

Is that a hosted web browser control or a native browser window?

carlesserra commented 4 years ago

It's a native browser IE window.

I'm running the Analytics sheet, included in the VBA-Web-Example.xlsm file, in the Examples folder.

In the Login function, in the GoogleAuthenticator module class, there is a Do While loop (line number 133), which is supposed to wait until the access token is given, but when this happens, I can only close the window. When closed, the loop exits with error.

Set auth_IE = CreateObject("InternetExplorer.Application")
auth_IE.Silent = True
auth_IE.AddressBar = False
auth_IE.Navigate Me.GetLoginUrl
auth_IE.Visible = True

' Wait for login to complete
Do While Not auth_LoginIsComplete(auth_IE)
    DoEvents
Loop
zgrose commented 4 years ago

OK, I recently had some trouble with Google MFA logins using a different project but I don't think it applies to this. Just in case it does, I had to leverage the registry. 32bit HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION 64bit HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION new DWORD (32bit) value of Excel.exe with value (decimal) 11000 This can affect the emulation mode, more info at https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/general-info/ee330730(v=vs.85)?redirectedfrom=MSDN#browser_emulation

For me the Google login pages were acting oddly until I maxed out the emulation mode, but I was bringing up the pages in a different way so no idea if relevant.

carlesserra commented 4 years ago

Same behavior :(

moiselegeek commented 4 years ago

I get the same issue as you For bypass this, you need to update the LoginIsApproval ffunction in GoogleAuthenticator

Original code

` Private Function auth_LoginIsApproval(auth_IE As Object) As Boolean Dim auth_UrlParts As Dictionary Set auth_UrlParts = WebHelpers.GetUrlParts(auth_IE.LocationURL)

auth_LoginIsApproval = auth_UrlParts("Path") =  "/o/oauth2/approval"

End Function `

Correct code

` Private Function auth_LoginIsApproval(auth_IE As Object) As Boolean Dim auth_UrlParts As Dictionary Set auth_UrlParts = WebHelpers.GetUrlParts(auth_IE.LocationURL)

auth_LoginIsApproval = auth_UrlParts("Path") = "/o/oauth2/approval/v2/approvalnativeapp"

End Function `

For my own it's work - just need to have a sample for the next steps :)

carlesserra commented 4 years ago

It works!

After this change, however, the authorization code returned by auth_LoginExtractCode was empty.

After inspecting the elements, I realized that the authorization code was in a TEXTAREA element, instead of an INPUT element.

Therefore, I changed the line

If VBA.UCase(auth_Element.NodeName) = "INPUT" Then

by this one:

If VBA.UCase(auth_Element.NodeName) = "TEXTAREA" Then

After that, success.

Thank you very much for your help!