Problems with Google API authentication in Ruby

Asked

Viewed 87 times

1

I’m developing a Ruby API that communicates google-api-ruby-client but when trying to authenticate I get some errors. example of my code:

class GoogleService

    require 'googleauth'
    require 'signet/oauth_2/client' 
    require 'google/api_client/client_secrets.rb'
    require 'google/apis/plus_domains_v1'
    require 'googleauth/web_user_authorizer'
    require 'googleauth/stores/redis_token_store'
    require 'redis'

    def initialize()

        token = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: File.open('./path/meu_json.json'), scope: @scope)
        @authorization = token.fetch_access_token!
        @client_id = Google::Auth::ClientId.from_file('./path/client_secret .json')
        @token_store = Google::Auth::Stores::RedisTokenStore.new(redis: Redis.new)

    end

    def plusDomains
        @token = "TOKEN_DE_ACESSO_DO_ME_USUARIO"
        auth_client = Signet::OAuth2::Client.new(access_token: @token)

        @plus = Google::Apis::PlusDomainsV1::PlusDomainsService.new
        @plus.key = 'MINHA_CHAVE_DA_API'
        @plus.authorization = auth_client
        te = @plus.get_person(:user_id => 'me')

    end

as you can see I’m using Gem Signet and google-api-ruby-client but I’m getting an error:

Sending HTTP get https://www.googleapis.com/plusDomains/v1/people/user_id,me?
Caught error Missing token endpoint URI.
Error - #<ArgumentError: Missing token endpoint URI.>

and if I have to inform expires_in (thus auth_client.expires_in = Time.now + 1_000_000) get this error:

Caught error forbidden: Forbidden
Error - #<Google::Apis::ClientError: forbidden: Forbidden>

I cannot understand their reasons because the token I receive is valid. My question would be: Am I sending the information needed to authenticate user access? And if so, would that be a bug? If I’m wrong you could tell me a source for research beyond the official documentation because it makes none of these integrations clear.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.