title: connect/authenticate with google using grails oauth plugin
body: <p>I am trying to connect with Google using the grails oauth plugin. Following is my code</p>
  
  <p><em>Config.groovy</em></p>
  
  <pre><code>oauth {
    providers {
      google {
          api = org.scribe.builder.api.GoogleApi
          key = 'XXX.apps.googleusercontent.com'
          secret = 'XXXXXXX'
  
          scope = 'https://www.googleapis.com/auth/userinfo.profile'
          callback = "${grails.serverURL}/oauth/google/callback"
          successUri = "${grails.serverURL}/oauthCallBack/google"
      }
    }
  }
  
  grails.google.api.url = "https://accounts.google.com/o/oauth2/auth"
  </code></pre>
  
  <p><em>OauthCallBackController.groovy</em></p>
  
  <pre><code>class OauthCallBackController {
  
    def oauthService
  
    def google() {
      Token googleAccessToken = (Token) session[oauthService.findSessionKeyForAccessToken('google')]
      def googleResource = oauthService.getGoogleResource(googleAccessToken, grailsApplication.config.grails.google.api.url)
      def googleResponse = JSON.parse(googleResource?.getBody())
  
      log.info "googleAccessToken = ${googleAccessToken}"
      log.info "googleResponse = ${googleResponse}"
      log.info "accesstoken = ${googleAccessToken.token}"
  
      def googleResourceDetailed = oauthService.getGoogleResource(googleAccessToken, "https://www.googleapis.com/oauth2/v1/userinfo?access_token=${googleAccessToken.token}")
      def googleResponseDetailed = JSON.parse(googleResourceDetailed?.getBody())
  
      log.info "googleResourceDetailed = ${googleResourceDetailed}"
      log.info "googleResponseDetailed = ${googleResponseDetailed}"
  
      render params
    }
  }
  </code></pre>
  
  <p>When I trying to connect, google ask me to allow the application to access my credentials. After allowing my call back action executed(oauthCallBack/google) but I am not getting the data of my account.</p>
  
  <p>Following is my output in my logs</p>
  
  <pre><code>INFO  example.OauthCallBackController  - googleAccessToken = Token[1/xxx , yyy]
  INFO  example.OauthCallBackController  - googleResponse = [:]
  INFO  example.OauthCallBackController  - accesstoken = 1/xxx
  INFO  example.OauthCallBackController  - googleResourceDetailed = org.scribe.model.Response@2a088ca
  INFO  example.OauthCallBackController  - googleResponseDetailed = [error:[message:Invalid Credentials, errors:[[message:Invalid Credentials, location:Authorization, reason:authError, locationType:header, domain:global]], code:401]]
  </code></pre>
  
  <p>I have no idea where I am wrong and why I am getting the error as response.</p>
  
  <p><strong>How can I get data from google?</strong> </p>