-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
45 lines (36 loc) · 965 Bytes
/
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
45
require "dotenv"
require "sinatra/base"
require "rack-flash"
require "omniauth"
require "omniauth-mondo"
Dotenv.load
class App < Sinatra::Base
enable :sessions
use Rack::Flash
use OmniAuth::Builder do
provider :mondo, ENV["MONDO_KEY"], ENV["MONDO_SECRET"], {
:provider_ignores_state => true # this is needed because we don't use the state param
# and it'll cause a CSRF error
}
end
get "/" do
erb :index
end
get "/auth/mondo/callback" do
auth = env["omniauth.auth"]
session[:account_id] = auth[:uid]
session[:account_name] = auth[:info][:name]
# create a user, and store the oauth tokens for future use and refreshing
flash[:success] = "Signed in!"
redirect "/"
end
get "/auth/failure" do
flash[:error] = "Unable to sign in"
redirect "/"
end
get "/auth/signout" do
session.clear
flash[:success] = "Signed out!"
redirect "/"
end
end