Class: Yt::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/yt/auth.rb,
lib/yt/auth/version.rb

Overview

Provides methods to authenticate a user with the Google OAuth flow.

Constant Summary collapse

VERSION =

Returns the SemVer-compatible gem version.

Returns:

  • (String)

    the SemVer-compatible gem version.

See Also:

'0.2.3'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Auth

Returns a new instance of Auth.

Parameters:

  • options (Hash) (defaults to: {})

    the options to initialize an instance of Yt::Auth.

Options Hash (options):

  • :redirect_uri (String)

    The URI to redirect users to after they have completed the Google OAuth flow.

  • :code (String)

    A single-use authorization code provided by Google OAuth to obtain an access token to access Google API.



16
17
18
19
20
# File 'lib/yt/auth.rb', line 16

def initialize(options = {})
  @redirect_uri = options[:redirect_uri]
  @code = options[:code]
  @refresh_token = options[:refresh_token]
end

Instance Method Details

#access_tokenString

Returns the access token of an authenticated Google account.

Returns:

  • (String)

    the access token of an authenticated Google account.



36
37
38
# File 'lib/yt/auth.rb', line 36

def access_token
  tokens['access_token']
end

#emailString

Returns the email of an authenticated Google account.

Returns:

  • (String)

    the email of an authenticated Google account.



31
32
33
# File 'lib/yt/auth.rb', line 31

def email
  profile['email']
end

#urlString

Returns the URL where to authenticate with a Google account.

Returns:

  • (String)

    the URL where to authenticate with a Google account.



23
24
25
26
27
28
# File 'lib/yt/auth.rb', line 23

def url
  host = 'accounts.google.com'
  path = '/o/oauth2/auth'
  query = URI.encode_www_form url_params
  URI::HTTPS.build(host: host, path: path, query: query).to_s
end