Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

NoMethodError when using OAuth2 login #12

Open
aboutaaron opened this issue May 28, 2015 · 2 comments
Open

NoMethodError when using OAuth2 login #12

aboutaaron opened this issue May 28, 2015 · 2 comments

Comments

@aboutaaron
Copy link

Hey all, great project. I was following the Web Application Google Drive instructions here and received the following error after attempting to authenticate with my Google account:

Puma caught this error: undefined method `join' for #<String:0x007f5fc83d2e10> (NoMethodError)

I'm on Ubuntu 14.04 and have Ruby 2.2.1 installed with rbenv.

After searching for this error online, I discovered this discussion in the Sinatra repo: sinatra/sinatra#951. Apparently, Sinatra 1.4.5 (the version driveshaft is built on) has some issues with updated versions of Rack. I bumped Sinatra to 1.4.6 and attempted to authenticate again which gave me a NoMethodError at https://github.com/newsdev/driveshaft/blob/develop/lib/driveshaft/auth.rb#L130

NoMethodError at /auth/callback undefined method `first' for nil:NilClass

I'll keep diagnosing but I'm curious if y'all have any ideas. Any guidance would be great. Thanks! I look forward to using this project regularly!

@abstrctn
Copy link
Contributor

Hey @aboutaaron - sorry for the trouble! I'll test out sinatra 1.4.6 with a few people, and then we can bump the version.

As for the NoMethodError, I wasn't able to replicate what you're seeing, but I have a few debugging suggestions.

Problem overview

  • This is the API request that [Driveshaft is using from Google: people.get
  • This is where the API call happens in Driveshaft
  • The "application_client" that Driveshaft is using should resolve to the web OAuth client that you configured, and gets initialized here.

Basically it's requesting two permissions from Google: Access to your Drive files, and your email address to use as an ID. The people.get endpoint should return something like this: (You can try it yourself, passing me as the userId, here)

{
 "kind": "plus#person",
 "etag": "\".......\"",
 "gender": "male",
 "emails": [
  {
   "value": "[email protected]",
   "type": "account"
  }
 ],
 "objectType": "person",
 "id": ".......",
 "displayName": "Michael Strickland",
 "name": {
  "familyName": "Strickland",
  "givenName": "Michael"
 },
 "url": "https://plus.google.com/116716851622762772517",
 "image": {
  "url": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
  "isDefault": true
 },
 "isPlusUser": true,
 "circledByCount": 2,
 "verified": false,
 "domain": "nytimes.com"
}

Ideally, emails should come back with an array with at least one item. It seems like yours perhaps isn't.

Suggestions

  1. First, I would try logging out what the value of person is getting set to, so we can see whether it's just the email that's missing, or more
  2. Try authenticating with a different gmail account
  3. Try changing the scopes that Driveshaft is requesting from your google account. Here are some additional ones you can try adding (either as a space-separated string as it is now, or you can convert it into an array of strings). Scopes are structured as urls.

For example, if you added all of those as scopes, the line in driveshaft could read:

client.authorization.scope = 'https://www.googleapis.com/auth/drive email https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'

Let me know if you're able to try any of those, otherwise I can try to help out more.

Best,
Michael

@abstrctn
Copy link
Contributor

Looking into another issue it seems like this could be caused by not enabling the Google+ API in your google project's settings. @aboutaaron, if you're still stuck on this, or for others finding this in the future, try enabling that API to fix this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants