Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples for OAuth1 usage? #56

Closed
prusswan opened this issue Jun 10, 2013 · 3 comments
Closed

examples for OAuth1 usage? #56

prusswan opened this issue Jun 10, 2013 · 3 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Milestone

Comments

@prusswan
Copy link

I understand OAuth1 (specifically 2LO) has been deprecated, but it is still in use by apps on the Google Marketplace. Since the current client still happens to work for OAuth1 even though it is unsupported, why not add some examples for it? It took me quite a while to figure out what was missing for the 2LO to work, until I compared the requests with those from the java client which had more documentation available.

@markkanof
Copy link

Any chance you could share how you go 2LO working? I've been struggling for a couple of days now with no luck. I've only been able to locate a few examples of people claiming they got it to work and those were either outdates, incomplete, or some combination of the two.

@prusswan
Copy link
Author

@markkanof

Mainly by checking the ruby source code and examining the older java client as described here, and logging the actual requests. I only checked Calendar v3 so I'm not sure about the other apis. At least for Calendar the xoauth_requestor_id parameter is needed, Calendar API's documentation also makes mention of the API key for domain-wide delegation 2LO, but I realized it is not needed in my specific example:

Working example of accessing Calendar API v3 using OAuth1 in Ruby

# Initialize the client
require 'debugger'
require 'net-http-spy'
require 'google/api_client'


KEY = 'omitted'
SECRET = 'omitted'
API_KEY = "omitted"

client = Google::APIClient.new(
  :key => API_KEY,
  :authorization => :two_legged_oauth
)

# Block 4: Using 2LO (two_legged_oauth) + API key to access Calendar API
client.authorization.client_credential_key = KEY
client.authorization.client_credential_secret = SECRET

cal = client.discovered_api('calendar','v3')

result = client.execute(
  :api_method => cal.events.list,
  :parameters => {
    'calendarId' => 'primary',
    :key => API_KEY,
    :xoauth_requestor_id => "support@dropmyemail.mygbiz.com"
  },
)

puts result.data.to_json

  • Output:
16:09:25 prusswan@prusswan-mint dropmyemail (googleapps-integration)$ bundle exec ruby lib/dropmyemail/google_api_test.rb 
I, [2013-06-10T16:10:49.741938 #22077]  INFO -- : CONNECT: ["www.googleapis.com", 443]
I, [2013-06-10T16:10:49.748663 #22077]  INFO -- : GET /discovery/v1/apis/calendar/v3/rest?key=AIzaSyCDQmNRkB2iwFU62ySo77fGMwl98EdLuAc
I, [2013-06-10T16:10:49.847158 #22077]  INFO -- : PARAMS {} 
I, [2013-06-10T16:10:49.847452 #22077]  INFO -- : BODY: Net::HTTPOK
I, [2013-06-10T16:10:49.950445 #22077]  INFO -- : CONNECT: ["www.googleapis.com", 443]
I, [2013-06-10T16:10:49.957003 #22077]  INFO -- : GET /calendar/v3/calendars/primary/events?key=**omitted**&xoauth_requestor_id=support%40dropmyemail.mygbiz.com
I, [2013-06-10T16:10:50.453468 #22077]  INFO -- : PARAMS {} 
I, [2013-06-10T16:10:50.453918 #22077]  INFO -- : BODY: Net::HTTPOK
{"kind":"calendar#events","etag":"\"3HZc1wy_mzFFhn5FKK0rPMjgApI/u9LbHHebzwV8OsntwpnGp1zzwqU\"","summary":"support@dropmyemail.mygbiz.com","updated":"2013-06-06T08:41:23.420Z","timeZone":"Asia/Singapore","accessRole":"owner","defaultReminders":[{"method":"popup","minutes":10}],"items":[{"kind":"calendar#event","etag":"\"3HZc1wy_mzFFhn5FKK0rPMjgApI/MTM3MDUwNzA3MzM1NjAwMA\"","id":"r1j800h0n32qjjmimfg999aks4","status":"confirmed","htmlLink":"https://www.google.com/calendar/event?eid=cjFqODAwaDBuMzJxamptaW1mZzk5OWFrczQgc3VwcG9ydEBkcm9wbXllbWFpbC5teWdiaXouY29t","created":"2013-06-06T08:24:33.000Z","updated":"2013-06-06T08:24:33.356Z","summary":"Rubber Duck Day","description":"the day when yellow ducks will be liberated all over the country","location":"Tiongland","colorId":"5","creator":{"email":"support@dropmyemail.mygbiz.com","displayName":"DME Support","self":true},"organizer":{"email":"support@dropmyemail.mygbiz.com","displayName":"DME Support","self":true},"start":{"date":"2013-06-04"},"end":{"date":"2013-06-05"},"transparency":"transparent","iCalUID":"r1j800h0n32qjjmimfg999aks4@google.com","sequence":0,"reminders":{"useDefault":true}}]}

@markkanof
Copy link

@prusswan

Thank you so much! This worked perfectly. After a couple days of trying and failing to get the authentication bits working, it's great to have a solution and be able to move forward with actually writing code to deal with calendar events.

@sqrrrl sqrrrl closed this as completed Jan 22, 2014
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants