class

Devise::OmniAuth::GoogleOauth2

Inherits Devise::OmniAuth::Strategy < Reference < Object

google_oauth2 strategy — authorize URL, token exchange and userinfo/AuthHash building, 1:1 with omniauth-google-oauth2 1.1.1. Endpoints are properties so specs (and tests against a stub provider) can redirect them.

Constants

ALLOWED_ISSUERS = {"accounts.google.com", "https://accounts.google.com"}
BASE_SCOPE_URL = "https://www.googleapis.com/auth/"
BASE_SCOPES = ["profile", "email", "openid"] of ::String
DEFAULT_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth"
DEFAULT_SCOPE = "email,profile"
DEFAULT_SITE = "https://oauth2.googleapis.com"
DEFAULT_TOKEN_PATH = "/token"
USER_INFO_URL = "https://www.googleapis.com/oauth2/v3/userinfo"

Constructors

new(client_id : String, client_secret : String)
Source

Class methods

get_scope(scope : String | Nil) : String

get_scope 1:1: split on spaces then commas; keep http(s) URLs and BASE_SCOPES as-is, prefix everything else with BASE_SCOPE_URL. "email,profile" → "email profile", "calendar" → "https://www.googleapis.com/auth/calendar" (oracle: g_scope_*).

Source

Instance methods

auth_hash(token : Token, raw_info : Hash(String, JSON::Any), token_scope : String | Nil = token.scope) : AuthHash

The AuthHash assembled from a token response + raw_info (oracle: g_hash_verified, g_hash_unverified_email, g_hash_no_name, g_hash_uid_sub): uid = sub, email only when email_verified, prune of nil/empty values.

Source
authenticate(code : String, redirect_uri : String) : AuthHash

Full callback phase: code → token → userinfo → AuthHash.

Source
authorize_url(redirect_uri : String, scope : String | Nil = nil, state : String | Nil = nil, access_type : String | Nil = nil, hd : String | Nil = nil, login_hint : String | Nil = nil, prompt : String | Nil = nil) : String

authorize_params + authorize_url. Mirrors the strategy defaults: response_type=code, access_type=offline unless given, 48-hex state (SecureRandom.hex(24)) unless given (oracle: g_access_type_default, g_state_in_session, g_authorize_url_full).

Source
authorize_url
Source
authorize_url=(authorize_url : String)
Source
client_id
Source
client_secret
Source
site
Source
site=(site : String)
Source
token(code : String, redirect_uri : String) : Token

POST /token (authorization_code grant), like OAuth2::Client auth_code.get_token.

Source
token_path
Source
token_path=(token_path : String)
Source
user_info_url
Source
user_info_url=(user_info_url : String)
Source
userinfo(access_token : String) : Hash(String, JSON::Any)

GET userinfo with the bearer token (raw_info).

Source