Quantcast
Channel: Chilkat Forum - latest questions
Viewing all articles
Browse latest Browse all 1061

Gmail with OAuth and Xojo

$
0
0

Hi,

I'm trying to connect to Google Apps Gmail with OAuth. With the totally clear instructions on the Google websites I hope I have set up everything correctly.

  1. Changed the MX record for one of my domains and verified the domain.
  2. Got a p12 file.
  3. Set up a service email address for the main project.

When I run the following code (basically the example):

  Dim http As New Chilkat.Http
  Dim success As Boolean = http.UnlockComponent("Anything for 30-day trial")
  If (success <> True) Then
    System.DebugLog(http.LastErrorText)
    Return
  End If

//  Begin by loading the downloaded .p12 into a Chilkat certificate object:
  Dim cert As New Chilkat.Cert
  success = cert.LoadPfxFile("/Users/beatrixwillius/Desktop/test-550c6e932e47.p12","notasecret")
  If (success <> True) Then
    msgbox(cert.LastErrorText)
    Return
  End If

Dim iss As String = "mailarchiver@api-project-83766207457.iam.gserviceaccount.com"
  Dim scope As String = "https://mail.google.com/"
  Dim numSec As Int32 = 3600

Dim accessToken As String = http.G_SvcOauthAccessToken(iss,scope,"",numSec,cert)
  If (http.LastMethodSuccess <> True) Then
    System.DebugLog(http.LastErrorText)
    Return
  Else
    System.DebugLog("access token: " + accessToken)
  End If

I get an empty accessToken. But LastErrorText is only:

ChilkatLog:
  get_OAuthVerifier:
    ChilkatVersion: 9.5.0.56
  --get_OAuthVerifier
--ChilkatLog

If I change the iss value to something like "xxxxmailarchiver@api-project-83766207457.iam.gserviceaccount.com" I get the following as response:

31.01.16 11:24:27,670 test.debug[16145]: ChilkatLog:
  G_SvcOauthAccessToken2:
    DllDate: Jan 26 2016
    ChilkatVersion: 9.5.0.56
    UnlockPrefix: Anything for 30-day trial
    Architecture: Little Endian; 32-bit
    Language: MAC OS X C/C++
    VerboseLogging: 0
    iss: xxxxxxmailarchiver@api-project-83766207457.iam.gserviceaccount.com
    scope: https://mail.google.com/
    sub: 
    aud: https://accounts.google.com/o/oauth2/token
    jwtHeader64: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9
    jwtClaimSet: {"iss":"xxxxxxmailarchiver@api-project-83766207457.iam.gserviceaccount.com","scope":"https://mail.google.com/","aud":"https://accounts.google.com/o/oauth2/token","exp":1454239462,"iat":1454235862}
    fullRequest:
      a_synchronousRequest:
        generateRequestHeader:
          httpRequestGenStartLine:
            genStartLine:
              startLine: POST /o/oauth2/token HTTP/1.1
            --genStartLine
          --httpRequestGenStartLine
          addCookies:
            Not auto-adding cookies.
            sendCookies: 1
            cookieDir: 
          --addCookies
        --generateRequestHeader
        fullHttpRequest:
          domain: accounts.google.com
          port: 443
          ssl: 1
          openHttpConnection:
            Opening connection directly to HTTP server.
            httpHostname: accounts.google.com
            httpPort: 443
            ssl: 1
            socket2Connect:
              connect2:
                connectImplicitSsl:
                  clientHandshake:
                    clientHandshake2:
                      buildClientKeyExchange:
                        buildClientKeyExchangeECDHE:
                          Verified server key exchange.
                        --buildClientKeyExchangeECDHE
                      --buildClientKeyExchange
                    --clientHandshake2
                  --clientHandshake
                --connectImplicitSsl
              --connect2
            --socket2Connect
            HTTPS secure channel established.
          --openHttpConnection
          connectTime: Elapsed time: 376 millisec
          sendRequestHeader:
            sendHeaderElapsedMs: 0
          --sendRequestHeader
          sendRequestBody:
            sendBodyElapsedMs: 1
          --sendRequestBody
          statusCode: 400
          statusText: Bad Request
          readResponseBody:
            Response is chunked.
          --readResponseBody
        --fullHttpRequest
        success: 1
      --a_synchronousRequest
      success: 1
    --fullRequest
    charsetFromContentType: utf-8
    charset: utf-8
    access_token not found.
    Failed.
  --G_SvcOauthAccessToken2
--ChilkatLog

What am I doing wrong?

Using latest Chilkat plugin from yesterday. Xojo 2015r4.

PS: is it possible to get a version of LoadPfxFile that has a folderitem as parameter? Using a string instead of a folderitem is very unusual on the Mac.

Mit freundlichen Grüßen/Regards

Trixi Willius

http://www.mothsoftware.com Mail Archiver X: The email archiving solution for professionals


Viewing all articles
Browse latest Browse all 1061

Trending Articles