-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ru
More file actions
38 lines (29 loc) · 770 Bytes
/
config.ru
File metadata and controls
38 lines (29 loc) · 770 Bytes
1
2
3
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
30
31
32
33
34
35
36
37
require 'sinatra/base'
require 'sinatra/cross_origin'
require 'mechanize'
class SkyeProxy < Sinatra::Base
register Sinatra::CrossOrigin
# enable cross_origin
class Github
def self.token(code)
params = {
:client_id => ENV['CLIENT_ID'],
:client_secret => ENV['CLIENT_SECRET'],
:code => code
}
headers = {"Accept" => 'application/json'}
response = client.post('https://github.com/login/oauth/access_token', params, headers)
response.body
end
private
def self.client
@@client ||= Mechanize.new
end
end
post '/token' do
cross_origin
content_type 'application/json'
Github.token(params[:code])
end
end
run Rack::URLMap.new("/" => SkyeProxy.new)