-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
44 lines (36 loc) · 1.24 KB
/
app.rb
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
41
42
43
44
require "sinatra"
require "omniauth-createsend"
require "createsend"
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :createsend, ENV["CREATESEND_CLIENT_ID"], ENV["CREATESEND_CLIENT_SECRET"],
:scope => "ViewReports,CreateCampaigns,SendCampaigns"
end
get "/" do
redirect "/auth/createsend"
end
get "/auth/:provider/callback" do
access_token = request.env["omniauth.auth"]["credentials"]["token"]
refresh_token = request.env["omniauth.auth"]["credentials"]["refresh_token"]
expires_at = request.env["omniauth.auth"]["credentials"]["expires_at"]
response = "<pre>"
response << "Your user is successfully authenticated. Here are the details you need:<br/><br/>"
response << "access token: #{access_token}<br/>"
response << "refresh token: #{refresh_token}<br/>"
response << "expires at: #{expires_at}<br/>"
response << "<br/><br/>"
auth = {
:access_token => access_token,
:refresh_token => refresh_token
}
cs = CreateSend::CreateSend.new auth
clients = cs.clients
response << "We've made an API call too. Here are your clients:<br/><br/>"
response << MultiJson.encode(clients)
response << "</pre>"
response
end
get "/auth/failure" do
content_type "application/json"
MultiJson.encode(request.env)
end