4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/helpers/dropbox_ext/dropbox_helper.rb', line 4
def self.get_access_key(auth_code, redirect)
require 'dropbox'
url = "https://api.dropboxapi.com/1/oauth2/token"
request_params = {
:code => auth_code,
:grant_type => "authorization_code",
:client_id => DropboxExt.db_client_id,
:client_secret => DropboxExt.db_client_secret,
:redirect_uri => "#{redirect}"
}
resp = HTTP.(content_type: 'application/json').post(url, :params => request_params)
if resp.code != 200
@error = "Unable to authenticate. Please try again."
return {:error => @error}
else
data = JSON.parse(resp.to_s)
dropbox_token = data["access_token"]
key = EncryptionHelper.generate_random_key
encrypted_token = EncryptionHelper.encrypt(dropbox_token, key)
return {:token => dropbox_token, :encrypted_token => encrypted_token, :key => key}
end
end
|