Android Question GoogleAuth2 not working

Scantech

Well-Known Member
Licensed User
I was setting up my GoogleAuth2 to send debug txt file but it is not acting properly.

First I get this
Screenshot_20190430-132354.png

Second I Allow
Screenshot_20190430-132405.png

And finally it goes to this
Screenshot_20190430-132418.png

It just cycles back and forth. and most annoying part is when i get back to the app it directs me to the top cycle once again.

I copied all examples from Sending Gmail tutorial.
 

JohnC

Well-Known Member
Licensed User
I actually just added this functionality to my app just last week using the tutorial/lib and it works as exepected.

So, do you have the below line in your "Main" activity's "Activity_Create":

B4X:
oauth2.Initialize(Me, "oauth2", ClientId, "https://www.googleapis.com/auth/gmail.send")
And is the routine that has this line in it also in your "Main" activity?

B4X:
oauth2.GetAccessToken
Try making sure that both the above lines are in your "Main" activity to see if it then works because you issue might be caused if the above lines of code are not in you main activity.
 

Scantech

Well-Known Member
Licensed User
Yes i added both.

oauth2.Initialize is in Main..Create and oauth.GetAccessToken is called only when i need to send a file. Just like the Erel's Gmail example.

I tried oauth.GetAccessToken in Main..Create and still getting similar result. Website is popping up all the time and every time when i resume the app.

What code makes the Website pop up all the time?
 

Scantech

Well-Known Member
Licensed User
Im setup like this

B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        oauth2.Initialize(Me, "oauth2", ClientId, "https://www.googleapis.com/auth/gmail.send")
    End If
End Sub
B4X:
Sub Activity_Resume
    If StateManager.blnDebugCollect = True Then
        oauth2.CallFromResume(Activity.GetStartingIntent)
        CheckandSendDebugLog
    End If
End Sub
B4X:
Sub CheckandSendDebugLog
    Log("CheckandSendDebugLog")
    Try
        'No File then do nothing
        If File.Exists(File.DirRootExternal, Starter.DebugLogDir & "CollectDataDebug.txt") = False Then
            Return
        End If
       
       
        Dim msg As MailCreator
        msg.Initialize
        msg.HtmlBody = True
        msg.ToList.Add("obdscantech@usa.com")
        msg.Subject = "Car Diagnsotic Pro Debug Collecting"
        msg.Body = ""
       
        'add attachment
        Dim fd As MultipartFileData
        fd.ContentType = "image/jpeg"
        fd.Dir = File.DirRootExternal
        fd.FileName = Starter.DebugLogDir & "CollectDataDebug.txt"
        msg.Attachments.Add(fd)
        Send(msg)
    Catch
        Log("Error in CheckandSendDebugLog")
    End Try
End Sub
B4X:
Sub Send (msg As MailCreator)
    Try
        oauth2.GetAccessToken
        Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
        If Success = False Then
            Log("Error accessing account.")
            Return
        End If
        Dim j As HttpJob
        j.Initialize("", Me)
        j.PostString("https://www.googleapis.com/upload/gmail/v1/users/me/messages/send?uploadType=multipart", msg.ToString)
        j.GetRequest.SetHeader("Authorization", "Bearer " & Token)
        j.GetRequest.SetContentType("message/rfc822")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log("Mail sent successfully")
            Log(j.GetString)
            ToastMessageShow("Message sent", True)
        Else
            Log("Failed to send mail.")
        End If
        j.Release
        Log("Done!!!")
    Catch
        Log("Error Sending Debug Log")
    End Try
End Sub
 

JohnC

Well-Known Member
Licensed User
Dumb question, but did you also:

1) Go into your google developer account and create a Client ID for your app and enable the gmail API for it.
2) Place your unique "Private ClientId As String = "#########iufsifhsiufiushfiudfhdfgfdsg.apps.googleusercontent.com" in the Process_Globals of the "Main" activity?
 

JohnC

Well-Known Member
Licensed User
What code makes the Website pop up all the time?
It may appear to be "Popping up all the time", but this may in fact be due to oAuth not being able to properly return control back to your app due to some error, so it stays in a loop.
 

JohnC

Well-Known Member
Licensed User
It's kind of tricky to describe, but googling it should give you directions.
 

Scantech

Well-Known Member
Licensed User
I switched to SMTP. Much easier and works very well with one of the server, not Google.

Probably not secured. I wonder decompiling APK will reveal the Mail Server and Password?
 

techknight

Well-Known Member
Licensed User
I switched to SMTP. Much easier and works very well with one of the server, not Google.

Probably not secured. I wonder decompiling APK will reveal the Mail Server and Password?
YES! and there is no way to hide it perfect either. your mail server will get ransacked by bots this way. But this holds true with the oAuth information or any other "string" variables you use.

You can use steganography to try and obscure the information, but if there is a memory debugger, itll get gotten anyways.
 

JohnC

Well-Known Member
Licensed User
You could also initiate an email intent that will pop-up and ask the user which email app they wish to use (gmail or their pop email app if they configured one) and you can send the debug file that way.

This way the user will be using their email app and no passwords need to be exposed.
 

JohnC

Well-Known Member
Licensed User
Or you could have your app do a "Post" to a hidden page on your website, and that webpage will convert the post into an email and send it to you - again no secret info being disclosed and even if someone discovers the hidden page, its useless because it will only send the email to you.
 

Scantech

Well-Known Member
Licensed User
I would do those options you recommended, but the data is not sensitive or has any personal information. Its just Car Computer data and the file is encrypted. I signed up with some email carrier and will be using their server. I just needed some data for certain amount of time just to make sure the app is functioning properly.
 

JohnC

Well-Known Member
Licensed User
I would do those options you recommended, but the data is not sensitive or has any personal information.
I just meant that with my two recent suggestions, your app wont have to contain any confidential email passwords.
 

techknight

Well-Known Member
Licensed User
I would look into some protections if it were my app. From a business owner, you have IP here, and you need to protect it the best you can. because if you cant/dont, then your IP is worthless which is bad for business.

It doesnt matter how sensitive or non-sensitive the information is. I like JohnC's suggestions too, its pretty smart and would work fine. Also using Steg with a background image of the App would work as well.
 
Top