Integrate with Google+ (OAUTH/OpenID Connect) For Logins?

I’m in the early stages of developing a Xojo web app to manage the call for proposals for our annual IT conference.

We don’t want to manage usernames or passwords so we’re leaning towards leveraging Google+ for Authentication. I’d probably still need to match up the userid to their submitted sessions but I don’t want to handle the management of the passwords.

Has anyone done this in a Xojo based web app (Integrate Logins with Google+ / OAUTH / OpenID Connect)?

If so, any pointers or suggestions on how to get started?


I’ve wrapped most of the google apis for calendars(events), tasks, gmail, drive etc… at least to some extent (not all completely)
I haven’t gotten around to Google+ because we haven’t needed it quite yet.

Here’s two methods i have in my GoogleApi.Google class

action as string, url as string, content as string = “”, timeout as integer = -1
Return Jsonitem

[code] if timeout = -1 then timeout = defaultTimeout
dim hs as new HTTPSecureSocket
dim output as string
hs.SetRequestHeader(“Authorization”, TokenType + " " + Token)
hs.Secure = true
hs.Address = url
hs.SetPostContent(content, “application/json”)

dim response as string
if action = “get” then
response = hs.Get(url, defaultTimeout)
elseif action = “post” then
response = hs.Post(url, defaultTimeout)
response = hs.SendRequest(action, url, timeout)

//Check for an OAuth error - If there is, refresh token and recall query
dim js as new JSONItem(DefineEncoding(response,Encodings.UTF8))
If js.HasName(“error”) then
if js.Child(“error”).HasName(“errors”) then
if js.child(“error”).Child(“errors”).IsArray then
For i as integer = 0 to js.child(“error”).Child(“errors”).Count - 1
if js.child(“error”).Child(“errors”).Child(i).Lookup(“reason”,"") = “authError” then
//OAuth Error exists, refresh token and try again
hs.SetRequestHeader(“Authorization”, TokenType + " " + Token)

        if action = "get" then
          response = hs.Get(url, defaultTimeout)
        elseif action = "post" then
          response = hs.Post(url, defaultTimeout)
          response = hs.SendRequest(action, url, timeout)
        js = new JSONItem(DefineEncoding(response,Encodings.UTF8))

Return js[/code]


  dim timeout as integer = 5
  dim d as new Dictionary
  d.Value("refresh_token") = RefreshToken
  d.Value("client_id") = ClientId
  d.Value("client_secret") = ClientSecret
  d.Value("grant_type") = "refresh_token"
  dim hs as new HTTPSecureSocket
  dim output as string
  hs.Secure = true
  hs.Address = ""
  dim js as new JSONItem(hs.Post(""+"/o/oauth2/token", timeout))
  //Set Values
  Token = js.Lookup("access_token","")

The other classes typically just call post methods to the Action event and then use a serialization class to help convert in and out of Jsonitems and Xojo objects

The code ends up looking pretty nice once its all wrapped:

dim response as GoogleAPI.ListMessagesResponse = g.User.Messages.List dim attachmentCount as integer = response.messages(0).AttachmentCount dim firstAttachment as GoogleAPI.MessageAttachment = response.messages(0).Attachment(0)

I tried to create and use this class, but I could not do it.

  1. Google is a GoogleApi subclass?
  2. defaultTimeout is a Property an integer value? (for example 1000)
  3. TokenType is a Property String? (which value?)
  4. Token is a Property String? (which value?)
  5. RefreshToken is a Method? (which one?)
  6. ClientId is for example my google id : ?
  7. ClientSecret is my password?
    … and finaly
  8. is ti possible to use this class to read/write Google Cal events?

Here is my “not working sample” GoogleCal_001
Could someone help me please? Thanks a lot Rob

I don’t have a ton of time to explain but this might be helpful. I’ve included my Google API library in the project below:

I’ve left the Main Module and Google class un-encrypted.

The library works for Gmail, Calendar Events, and Task Lists fairly well but its not yet a complete library. I’ve mostly implemented the components I’ve needed to use in other projects. I also started on Google Drive.

There’s some examples in the Window Open event. I’ve redacted my key’s and you’ll need to use your own.

Thank you a lot Brock!
I’ll take a look to your sample!
and Merry Christmas Days!

Using it is pretty easy

Dim g as new GoogleAPI.Google g.ApiKey = "AIza<<REDACTED>> g.ClientId = "<<REDACTED>>" g.ClientSecret = "<<REDACTED>>" g.TokenType = "Bearer" //Set User g.refreshToken = "1/kq<<REDACTED>>"

If you then type “g.User.” the autofill will give you the paths you need to do things.
Calendar, Tasks, Messages(gmail) etc…

Here’s a quick example:

dim firstCalendarId as string = g.user.Calendars.ListCalendars.items(0).id dim firstEventDescription = g.User.Calendars.GetCalendar(firstCalendarId).ListEvents.items(0).description