class
Google::Auth::OAuth2Client
- Google::Auth::OAuth2Client
- Reference
- Object
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.crgoogle/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
- .from_credentials(path : String, client_id : String, client_secret : String, redirect_uri : String = "urn:ietf:wg:oauth:2.0:oob") : OAuth2Client
- .new(client_id : String, client_secret : String, redirect_uri : String = "urn:ietf:wg:oauth:2.0:oob")
Instance Method Summary
- #access_token : String | Nil
- #access_token=(access_token : String | Nil)
-
#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
-
#authorize(code : String) : String
Exchange authorization code for tokens
- #client_id : String
- #client_id=(client_id : String)
- #client_secret : String
- #client_secret=(client_secret : String)
-
#expired? : Bool
Check if the token is expired
- #expires_at : Time | Nil
- #expires_at=(expires_at : Time | Nil)
- #redirect_uri : String
- #redirect_uri=(redirect_uri : String)
-
#refresh! : String
Refresh the access token using the refresh token
- #refresh_token : String | Nil
- #refresh_token=(refresh_token : String | Nil)
- #save_credentials(path : String) : Nil
-
#valid_token : String
Get a valid access token, refreshing if necessary
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
#
def self.new(client_id : String, client_secret : String, redirect_uri : String = "urn:ietf:wg:oauth:2.0:oob")
#
Instance Method Detail
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