Class: Vk::Client::OAuth2

Inherits:
OAuth2::Client
  • Object
show all
Includes:
PromptExtension
Defined in:
lib/vk/client/oauth2.rb

Constant Summary collapse

DEFAULT_OAUTH_OPTIONS =
{
  site: 'https://api.vk.com',
  authorize_url: 'https://oauth.vk.com/authorize',
  token_url: 'https://oauth.vk.com/access_token'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app_id = Vk.app_id, app_secret = Vk.app_secret, options = DEFAULT_OAUTH_OPTIONS) ⇒ OAuth2

Returns a new instance of OAuth2.



17
18
19
# File 'lib/vk/client/oauth2.rb', line 17

def initialize(app_id = Vk.app_id, app_secret = Vk.app_secret, options = DEFAULT_OAUTH_OPTIONS)
  super(app_id, app_secret, options)
end

Instance Method Details

#get_access_tokenOAuth2::AccessToken

Returns:

  • (OAuth2::AccessToken)


36
37
38
39
40
41
# File 'lib/vk/client/oauth2.rb', line 36

def get_access_token
  auth_code.get_token(
    get_auth_code,
    redirect_uri: 'https://oauth.vk.com/blank.html'
  )
end

#get_auth_codeString

Returns:

  • (String)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vk/client/oauth2.rb', line 22

def get_auth_code
  url = auth_code.authorize_url(
    redirect_uri: 'https://oauth.vk.com/blank.html',
    display: 'page',
    scope: Vk::Access::SCOPES.values.inject(0, :+)
  )
  prompt.say 'Open a link and allow access:'
  prompt.say
  prompt.say "    #{url}"
  prompt.say
  prompt.ask('Enter the code from the address of the opened page:')
end