Android Question GoogleAuth2 not working

Discussion in 'Android Questions' started by Scantech, Apr 30, 2019.

  1. Scantech

    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.
     
  2. JohnC

    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":

    Code:
    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?

    Code:
    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.
     
  3. Scantech

    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?
     
  4. Scantech

    Scantech Well-Known Member Licensed User

    Im setup like this

    Code:
    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
    Code:
    Sub Activity_Resume
        
    If StateManager.blnDebugCollect = True Then
            oauth2.CallFromResume(
    Activity.GetStartingIntent)
            CheckandSendDebugLog
        
    End If
    End Sub
    Code:
    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
    Code:
    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
     
  5. JohnC

    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?
     
  6. JohnC

    JohnC Well-Known Member Licensed User

    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.
     
  7. Scantech

    Scantech Well-Known Member Licensed User

    Yes. My Client ID is there. But what step is required to enable gmail API?
     
  8. JohnC

    JohnC Well-Known Member Licensed User

    It's kind of tricky to describe, but googling it should give you directions.
     
  9. Scantech

    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?
     
  10. techknight

    techknight Well-Known Member Licensed User

    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.
     
    Scantech likes this.
  11. JohnC

    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.
     
  12. JohnC

    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.
     
  13. Scantech

    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.
     
  14. JohnC

    JohnC Well-Known Member Licensed User

    I just meant that with my two recent suggestions, your app wont have to contain any confidential email passwords.
     
  15. Scantech

    Scantech Well-Known Member Licensed User

    This one is interesting.

    F5Steg v1.2 I am looking into this.
     
  16. techknight

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice