A summary of data about the Ruby ecosystem.

https://github.com/googleapis/google-auth-library-ruby

Google Auth Library for Ruby
https://github.com/googleapis/google-auth-library-ruby

Keywords from Contributors

activerecord activejob mvc crash-reporting marshaller feature-flag rubocop ruby-gem rubygem oauth2

Last synced: about 3 hours ago
JSON representation

Repository metadata

Google Auth Library for Ruby

README.md

Google Auth Library for Ruby

Gem Version

Description

This is Google's officially supported ruby client library for using OAuth 2.0
authorization and authentication with Google APIs.

Install

Be sure https://rubygems.org/ is in your gem sources.

For normal client usage, this is sufficient:

$ gem install googleauth

Example Usage

require 'googleauth'

# Get the environment configured authorization
scopes =  ['https://www.googleapis.com/auth/cloud-platform',
           'https://www.googleapis.com/auth/compute']
authorization = Google::Auth.get_application_default(scopes)

# Add the the access token obtained using the authorization to a hash, e.g
# headers.
some_headers = {}
authorization.apply(some_headers)

Application Default Credentials

This library provides an implementation of
application default credentials for Ruby.

The Application Default Credentials provide a simple way to get authorization
credentials for use in calling Google APIs.

They are best suited for cases when the call needs to have the same identity
and authorization level for the application independent of the user. This is
the recommended approach to authorize calls to Cloud APIs, particularly when
you're building an application that uses Google Compute Engine.

User Credentials

The library also provides support for requesting and storing user
credentials (3-Legged OAuth2.) Two implementations are currently available,
a generic authorizer useful for command line apps or custom integrations as
well as a web variant tailored toward Rack-based applications.

The authorizers are intended for authorization use cases. For sign-on,
see Google Identity Platform

Important notes

If you accept a credential configuration (credential JSON/File/Stream) from an
external source for authentication to Google Cloud, you must validate it before
providing it to any Google API or library. Providing an unvalidated credential
configuration to Google APIs can compromise the security of your systems and data.
For more information, refer to Validate credential configurations from external
sources
.

Example (Web)

require 'googleauth'
require 'googleauth/web_user_authorizer'
require 'googleauth/stores/redis_token_store'
require 'redis'

client_id = Google::Auth::ClientId.from_file('/path/to/client_secrets.json')
scope = ['https://www.googleapis.com/auth/drive']
token_store = Google::Auth::Stores::RedisTokenStore.new(redis: Redis.new)
authorizer = Google::Auth::WebUserAuthorizer.new(
  client_id, scope, token_store, '/oauth2callback')


get('/authorize') do
  # NOTE: Assumes the user is already authenticated to the app
  user_id = request.session['user_id']
  credentials = authorizer.get_credentials(user_id, request)
  if credentials.nil?
    redirect authorizer.get_authorization_url(login_hint: user_id, request: request)
  end
  # Credentials are valid, can call APIs
  # ...
end

get('/oauth2callback') do
  target_url = Google::Auth::WebUserAuthorizer.handle_auth_callback_deferred(
    request)
  redirect target_url
end

Example (Web with PKCE)

Proof Key for Code Exchange (PKCE) is an RFC that aims to prevent malicious operating system processes from hijacking an OAUTH 2.0 exchange. PKCE mitigates the above vulnerability by including code_challenge and code_challenge_method parameters in the Authorization Request and a code_verifier parameter in the Access Token Request.

require 'googleauth'
require 'googleauth/web_user_authorizer'
require 'googleauth/stores/redis_token_store'
require 'redis'

client_id = Google::Auth::ClientId.from_file('/path/to/client_secrets.json')
scope = ['https://www.googleapis.com/auth/drive']
token_store = Google::Auth::Stores::RedisTokenStore.new(redis: Redis.new)
authorizer = Google::Auth::WebUserAuthorizer.new(
  client_id, scope, token_store, '/oauth2callback')


get('/authorize') do
  # NOTE: Assumes the user is already authenticated to the app
  user_id = request.session['user_id']
  # User needs to take care of generating the code_verifier and storing it in
  # the session.
  request.session['code_verifier'] ||= Google::Auth::WebUserAuthorizer.generate_code_verifier
  authorizer.code_verifier = request.session['code_verifier']
  credentials = authorizer.get_credentials(user_id, request)
  if credentials.nil?
    redirect authorizer.get_authorization_url(login_hint: user_id, request: request)
  end
  # Credentials are valid, can call APIs
  # ...
end

get('/oauth2callback') do
  target_url = Google::Auth::WebUserAuthorizer.handle_auth_callback_deferred(
    request)
  redirect target_url
end

Example (Command Line) [Deprecated]

The Google Auth OOB flow has been discontiued on January 31, 2023. The OOB flow is a legacy flow that is no longer considered secure. To continue using Google Auth, please migrate your applications to a more secure flow. For more information on how to do this, please refer to this OOB Migration guide.

require 'googleauth'
require 'googleauth/stores/file_token_store'

OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'

scope = 'https://www.googleapis.com/auth/drive'
client_id = Google::Auth::ClientId.from_file('/path/to/client_secrets.json')
token_store = Google::Auth::Stores::FileTokenStore.new(
  :file => '/path/to/tokens.yaml')
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)

user_id = ENV['USER']
credentials = authorizer.get_credentials(user_id)
if credentials.nil?
  url = authorizer.get_authorization_url(base_url: OOB_URI )
  puts "Open #{url} in your browser and enter the resulting code:"
  code = gets
  credentials = authorizer.get_and_store_credentials_from_code(
    user_id: user_id, code: code, base_url: OOB_URI)
end

# OK to use credentials

Example (Service Account)

scope = 'https://www.googleapis.com/auth/androidpublisher'

authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
  json_key_io: File.open('/path/to/service_account_json_key.json'),
  scope: scope)

authorizer.fetch_access_token!

You can also use a JSON keyfile by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable.

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_json_key.json
require 'googleauth'
require 'google/apis/drive_v3'

Drive = ::Google::Apis::DriveV3
drive = Drive::DriveService.new

scope = 'https://www.googleapis.com/auth/drive'

authorizer = Google::Auth::ServiceAccountCredentials.from_env(scope: scope)
drive.authorization = authorizer

list_files = drive.list_files()

3-Legged OAuth with a Service Account

This is similar to regular service account authorization (see this answer for more details on the differences), but you'll need to indicate which user your service account is impersonating by manually updating the sub field.

scope = 'https://www.googleapis.com/auth/androidpublisher'

authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
  json_key_io: File.open('/path/to/service_account_json_key.json'),
  scope: scope
)
authorizer.update!(sub: "email-to-impersonate@your-domain.com")

authorizer.fetch_access_token!

Example (Environment Variables)

export GOOGLE_ACCOUNT_TYPE=service_account
export GOOGLE_CLIENT_ID=000000000000000000000
export GOOGLE_CLIENT_EMAIL=xxxx@xxxx.iam.gserviceaccount.com
export GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
require 'googleauth'
require 'google/apis/drive_v3'

Drive = ::Google::Apis::DriveV3
drive = Drive::DriveService.new

# Auths with ENV vars:
# "GOOGLE_CLIENT_ID",
# "GOOGLE_CLIENT_EMAIL",
# "GOOGLE_ACCOUNT_TYPE", 
# "GOOGLE_PRIVATE_KEY"
auth = ::Google::Auth::ServiceAccountCredentials
  .make_creds(scope: 'https://www.googleapis.com/auth/drive')
drive.authorization = auth

list_files = drive.list_files()

Storage

Authorizers require a storage instance to manage long term persistence of
access and refresh tokens. Two storage implementations are included:

  • Google::Auth::Stores::FileTokenStore
  • Google::Auth::Stores::RedisTokenStore

Custom storage implementations can also be used. See
token_store.rb for additional details.

Supported Ruby Versions

This library is supported on Ruby 3.0+.

Google provides official support for Ruby versions that are actively supported
by Ruby Core—that is, Ruby versions that are either in normal maintenance or
in security maintenance, and not end of life. Older versions of Ruby may
still work, but are unsupported and not recommended. See
https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby
support schedule.

License

This library is licensed under Apache 2.0. Full license text is
available in LICENSE.

Contributing

See [CONTRIBUTING][contributing].

Support

Please
report bugs at the project on Github. Don't
hesitate to
ask questions
about the client or APIs on StackOverflow.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: about 16 hours ago

Total Commits: 379
Total Committers: 73
Avg Commits per committer: 5.192
Development Distribution Score (DDS): 0.77

Commits in past year: 33
Committers in past year: 9
Avg Commits per committer in past year: 3.667
Development Distribution Score (DDS) in past year: 0.697

Name Email Commits
Daniel Azuma d****a@g****m 87
Tim Emiola t****a@g****m 47
Graham Paye g****8@g****m 24
release-please[bot] 5****] 20
yoshi-code-bot 7****t 20
WhiteSource Renovate b****t@r****m 16
Steven Bazyl s****l@g****m 13
Neha Bajaj b****7 13
Kazuhiro Serizawa n****o@g****m 11
Viacheslav Rostovtsev 5****v 10
Heng Xiong h****8@g****m 9
Mike Moore m****e@b****m 7
Todd Derr s****y@g****m 6
Graham Paye p****e@g****m 6
Chris Smith q****o@g****m 5
Jin q****n@g****m 5
Nivedha n****l@g****m 4
murgatroid99 m****h@g****m 4
Trung Lê t****e@r****m 3
Jurriaan Pruis e****l@j****l 3
Justin Beckwith j****h@g****m 3
Vijay Subramani v****i 3
Thea Flowers t****s@g****m 2
Piotr Usewicz p****r@l****m 2
Olle Jonsson o****n@g****m 2
Jacob Geiger j****r@g****m 2
David Supplee d****e@g****m 2
Bouke van der Bijl i@b****e 2
André Andreassa a****a 2
Yuji Yamamoto w****y@g****m 2
and 43 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 13 days ago

Total issues: 61
Total pull requests: 219
Average time to close issues: over 1 year
Average time to close pull requests: about 1 month
Total issue authors: 54
Total pull request authors: 45
Average comments per issue: 2.84
Average comments per pull request: 1.05
Merged pull request: 164
Bot issues: 6
Bot pull requests: 33

Past year issues: 8
Past year pull requests: 56
Past year average time to close issues: 22 days
Past year average time to close pull requests: 8 days
Past year issue authors: 8
Past year pull request authors: 12
Past year average comments per issue: 0.25
Past year average comments per pull request: 0.63
Past year merged pull request: 40
Past year bot issues: 0
Past year bot pull requests: 11

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/googleapis/google-auth-library-ruby

Top Issue Authors

  • TimurSadykov (3)
  • failure-checker[bot] (3)
  • mohamedhafez (2)
  • repo-metadata-lint[bot] (2)
  • quartzmo (2)
  • vb-git14 (1)
  • burkematthew (1)
  • forking-renovate[bot] (1)
  • 10io (1)
  • mr-salty (1)
  • hshar7 (1)
  • bajajneha27 (1)
  • jcavalieri (1)
  • MrPhantomT (1)
  • passt0r (1)

Top Pull Request Authors

  • dazuma (58)
  • release-please[bot] (32)
  • viacheslav-rostovtsev (20)
  • renovate-bot (18)
  • bajajneha27 (16)
  • yoshi-code-bot (9)
  • BigTailWolf (7)
  • blowmage (6)
  • NivedhaSenthil (4)
  • JustinBeckwith (3)
  • mikemackintosh (2)
  • quartzmo (2)
  • johannlejeune (2)
  • aandreassa (2)
  • guillaumewrobel (2)

Top Issue Labels

  • type: feature request (10)
  • type: process (7)
  • type: docs (7)
  • type: question (5)
  • type: bug (3)
  • priority: p2 (3)
  • status: investigating (2)
  • :rotating_light: (2)
  • repo-metadata: lint (2)
  • priority: p1 (2)
  • triage me (1)
  • type: cleanup (1)
  • samples (1)
  • api: drive (1)

Top Pull Request Labels

  • autorelease: published (25)
  • autorelease: pending (14)
  • kokoro:force-run (13)
  • cla: yes (10)
  • samples (5)
  • do not merge (2)
  • autorelease: closed (2)
  • cla: no (1)
  • autorelease: tagged (1)

Package metadata

gem.coop: googleauth

Implements simple authorization for accessing Google APIs, and provides support for Application Default Credentials.

  • Homepage: https://github.com/googleapis/google-auth-library-ruby
  • Documentation: http://www.rubydoc.info/gems/googleauth/
  • Licenses: Apache-2.0
  • Latest release: 1.16.0 (published about 2 months ago)
  • Last Synced: 2026-01-08T18:29:59.583Z (1 day ago)
  • Versions: 64
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 438,819,609 Total
  • Docker Downloads: 572,896,500
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Downloads: 0.054%
    • Average: 0.054%
    • Docker downloads count: 0.161%
  • Maintainers (2)
rubygems.org: googleauth

Implements simple authorization for accessing Google APIs, and provides support for Application Default Credentials.

  • Homepage: https://github.com/googleapis/google-auth-library-ruby
  • Documentation: http://www.rubydoc.info/gems/googleauth/
  • Licenses: Apache-2.0
  • Latest release: 1.16.0 (published about 2 months ago)
  • Last Synced: 2026-01-08T11:51:23.896Z (1 day ago)
  • Versions: 65
  • Dependent Packages: 121
  • Dependent Repositories: 28,906
  • Downloads: 438,719,126 Total
  • Docker Downloads: 572,896,500
  • Rankings:
    • Downloads: 0.057%
    • Dependent repos count: 0.209%
    • Docker downloads count: 0.226%
    • Dependent packages count: 0.285%
    • Average: 0.858%
    • Forks count: 1.628%
    • Stargazers count: 2.741%
  • Maintainers (2)

Dependencies

Gemfile rubygems
  • fakefs ~> 1.0
  • fakeredis ~> 0.5
  • gems ~> 1.2
  • google-style ~> 1.26.0
  • logging ~> 2.0
  • minitest ~> 5.14
  • minitest-focus ~> 1.1
  • rack-test ~> 2.0
  • redcarpet ~> 3.0
  • redis ~> 4.0
  • rspec ~> 3.0
  • sinatra >= 0
  • webmock ~> 3.8
  • yard ~> 0.9
googleauth.gemspec rubygems
  • faraday >= 0.17.3, < 3.a
  • jwt >= 1.4, < 3.0
  • memoist ~> 0.16
  • multi_json ~> 1.11
  • os >= 0.9, < 2.0
  • signet >= 0.16, < 2.a
.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • ruby/setup-ruby v1 composite
.github/workflows/release-please-label.yml actions
  • actions/github-script v6 composite
.github/workflows/release-please.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • ruby/setup-ruby v1 composite
samples/Gemfile rubygems
  • minitest ~> 5.16 development
  • minitest-focus ~> 1.1 development
  • google-cloud-storage >= 0

Score: 31.978067501292333