Class: Dronetrack::OAuthHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/dronetrack/oauthhelper.rb

Instance Method Summary collapse

Constructor Details

#initialize(baseUrl, clientId, clientSecret, redirectUrl) ⇒ OAuthHelper

Returns a new instance of OAuthHelper.



3
4
5
6
# File 'lib/dronetrack/oauthhelper.rb', line 3

def initialize (baseUrl, clientId, clientSecret, redirectUrl)
    @client = OAuth2::Client.new(clientId, clientSecret, {:site => baseUrl, :authorize_url => "#{@baseUrl}/auth/dialog", :token_url => "#{@baseUrl}/auth/token"})
    @redirectUrl = redirectUrl
end

Instance Method Details

#getAccessToken(getCode, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dronetrack/oauthhelper.rb', line 8

def getAccessToken (getCode, &block)
    url = @client.auth_code.authorize_url(:redirect_uri => @redirectUrl)
    b = if block_given? then block else Proc.new() end
    complete = Proc.new do |code| 
        token = @client.auth_code.get_token(code, :redirect_uri => @redirectUrl)
        b.call token.token
    end
    
    getCode.call url, complete
end