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'
}

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.



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

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)


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

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)


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

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