Module: VkontakteApi::Authorization
- Included in:
- VkontakteApi
- Defined in:
- lib/vkontakte_api/authorization.rb
Overview
Note:
VkontakteApi::Authorization
extends VkontakteApi
so these methods should be called from the latter.
A module containing the methods for authorization.
Constant Summary collapse
- OPTIONS =
Authorization options.
{ client: { site: 'https://oauth.vk.com', authorize_url: '/authorize', token_url: '/access_token' }, client_credentials: { 'auth_scheme' => 'request_body' } }
Instance Method Summary collapse
-
#authorization_url(options = {}) ⇒ String
URL for redirecting the user to VK where he gives the application all the requested access rights.
-
#authorize(options = {}) ⇒ VkontakteApi::Client
Authorization (getting the access token and building a
VkontakteApi::Client
with it).
Instance Method Details
#authorization_url(options = {}) ⇒ String
URL for redirecting the user to VK where he gives the application all the requested access rights.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vkontakte_api/authorization.rb', line 24 def ( = {}) type = .delete(:type) || :site # redirect_uri passed in options overrides the global setting [:redirect_uri] ||= VkontakteApi.redirect_uri [:scope] = VkontakteApi::Utils.flatten_argument([:scope]) if [:scope] case type when :site client.auth_code.() when :client client.implicit.() else raise ArgumentError, "Unknown authorization type #{type.inspect}" end end |
#authorize(options = {}) ⇒ VkontakteApi::Client
Authorization (getting the access token and building a VkontakteApi::Client
with it).
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vkontakte_api/authorization.rb', line 45 def ( = {}) type = .delete(:type) || :site [:redirect_uri] ||= VkontakteApi.redirect_uri case type when :site code = .delete(:code) token = client.auth_code.get_token(code, ) when :app_server token = client.client_credentials.get_token(, OPTIONS[:client_credentials].dup) else raise ArgumentError, "Unknown authorization type #{type.inspect}" end Client.new(token) end |