class Google::Auth::OAuth2Client

Overview

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)

Defined in:

google/auth/oauth2.cr
google/auth/token_store.cr

Constant Summary

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

Constructors

Instance Method Summary

Constructor Detail

def self.from_credentials(path : String, client_id : String, client_secret : String, redirect_uri : String = "urn:ietf:wg:oauth:2.0:oob") : OAuth2Client #

[View source]
def self.new(client_id : String, client_secret : String, redirect_uri : String = "urn:ietf:wg:oauth:2.0:oob") #

[View source]

Instance Method Detail

def access_token : String | Nil #

[View source]
def access_token=(access_token : String | Nil) #

[View source]
def authorization_url(scope : String | Array(String), state : String | Nil = nil, access_type : String = "offline", prompt : String = "consent") : String #

Generate the authorization URL for the user to visit


[View source]
def authorize(code : String) : String #

Exchange authorization code for tokens


[View source]
def client_id : String #

[View source]
def client_id=(client_id : String) #

[View source]
def client_secret : String #

[View source]
def client_secret=(client_secret : String) #

[View source]
def expired? : Bool #

Check if the token is expired


[View source]
def expires_at : Time | Nil #

[View source]
def expires_at=(expires_at : Time | Nil) #

[View source]
def redirect_uri : String #

[View source]
def redirect_uri=(redirect_uri : String) #

[View source]
def refresh! : String #

Refresh the access token using the refresh token


[View source]
def refresh_token : String | Nil #

[View source]
def refresh_token=(refresh_token : String | Nil) #

[View source]
def save_credentials(path : String) : Nil #

[View source]
def valid_token : String #

Get a valid access token, refreshing if necessary


[View source]