class

Google::Auth::OAuth2Client

Inherits Reference < Object

OAuth2 client for Google API authentication. Supports authorization code flow, token refresh, and credential persistence.

oauth = Google::Auth::OAuth2Client.new(client_id, client_secret)
url = oauth.authorization_url(scope: Google::Auth::Scopes::YOUTUBE)
# User visits URL, gets code
oauth.authorize(code)

Constants

GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth"
GOOGLE_TOKEN_URL = "oauth2.googleapis.com"
TOKEN_PATH = "/token"

Constructors

from_credentials(path : String, client_id : String, client_secret : String, redirect_uri : String = "urn:ietf:wg:oauth:2.0:oob") : OAuth2Client
Source
new(client_id : String, client_secret : String, redirect_uri : String = "urn:ietf:wg:oauth:2.0:oob")
Source

Instance methods

access_token
Source
access_token=(access_token : String | Nil)
Source
authorize(code : String) : String

Exchange authorization code for tokens

Source
client_id
Source
client_id=(client_id : String)
Source
client_secret
Source
client_secret=(client_secret : String)
Source
expired?

Check if the token is expired

Source
expires_at
Source
expires_at=(expires_at : Time | Nil)
Source
redirect_uri
Source
redirect_uri=(redirect_uri : String)
Source
refresh!

Refresh the access token using the refresh token

Source
refresh_token
Source
refresh_token=(refresh_token : String | Nil)
Source
save_credentials(path : String) : Nil
Source
valid_token

Get a valid access token, refreshing if necessary

Source