-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.rb
More file actions
40 lines (33 loc) · 846 Bytes
/
Copy pathexample.rb
File metadata and controls
40 lines (33 loc) · 846 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
38
39
40
require "rubygems"
require "bundler/setup"
require 'sinatra'
require 'kuaipan'
require 'haml'
enable :sessions
get '/' do
session[:k_session] = nil
haml :index
end
extend Kuaipan::OpenAPI
consumer_token = "xcWcZhCNKFJz1H8p"
consumer_secret = "8RvkM0aGYiQF5kJF"
input_config consumer_token, consumer_secret
get '/connect' do
extend Kuaipan::OpenAPI
k_session = g_session :oauth_callback => "http://#{request.env["HTTP_HOST"]}/callback" # here get rtoken
authorize_url = k_session[:authorize_url]
session[:k_session] = k_session
redirect authorize_url
end
get '/callback' do
oauth_verifier = params[:oauth_verifier]
# parse oauth_verifier client code
session[:k_session].set_atoken oauth_verifier # here set accesstoken
redirect '/user_info'
end
get '/user_info' do
haml :index
end
get '/logout' do
p 'logout'
end