B4J Question oauth2- Bug ?

Duque

Active Member
Licensed User
Longtime User
Hello colleagues Implement this class:
[class][B4X] Google OAuth2
in a b4j system and I am having problems, the process works but you have to insist many times.
It stays here most of the time and must be repeated until it is achieved
bug-google.png

Help !
 

Duque

Active Member
Licensed User
Longtime User
Ok this is what I do at the beginning, press a button

B4X:
oauth2.Initialize(Me,"oauth2")
oauth2.GetAccessToken
Wait For OAuth2_AccessTokenAvailable(Success As Boolean, Token As TokenInformation)
If (Success = False) Then
fx.Msgbox(frm1,"error","err")
Return
End If


The browser opens and permission is given, but it waits as it looks in the image and never saves the token.
You have to insist several times to achieve it
 
Upvote 0

Duque

Active Member
Licensed User
Longtime User
I followed the trail by console and right on the line:
AStream_NewData:
Wait For AStream_NewData (Buffer() As Byte)
it stops, this does not return anything.
I repeat that for it to work you have to try several times

B4X:
Private Sub PrepareServer
    If server.IsInitialized Then server.Close
    If astream.IsInitialized Then astream.Close
    Do While True
        Try
            server.Initialize(port, "server")
            server.Listen
            Exit
        Catch
            port = port + 1
            Log(LastException)
        End Try
    Loop
    Wait For server_NewConnection (Successful As Boolean, NewSocket As Socket)
    Log("This was executed(server_NewConnection="&Successful&")...")
    If Successful Then
        astream.Initialize(NewSocket.InputStream, NewSocket.OutputStream, "AStream")'<---My only change in this function was to change "astream" to "AStream"
        Dim Response As StringBuilder
        Response.Initialize
        
        Log("Here we go...")
        
        Do While Response.ToString.Contains("Host:") = False
            Log("I'm here...")
            Wait For AStream_NewData (Buffer() As Byte) '<--- From this point does not follow, I have to clarify that there are times that if it works
            Response.Append(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
        Loop
        
        Log("I pass the loop...")
        astream.Write(("HTTP/1.0 200" & Chr(13) & Chr(10)).GetBytes("UTF8"))
        Sleep(50)
        astream.Close
        server.Close
        ParseBrowserUrl(Regex.Split2("$",Regex.MULTILINE, Response.ToString)(0))
    End If
    
End Sub


-Thinking it was a problem with my code, download the one from the examples and the result was the same.

-Thinking it was a problem with my pc, I went to other pcs and the result was the same
 
Upvote 0
Top