-
Notifications
You must be signed in to change notification settings - Fork 1
/
memento.rb
77 lines (61 loc) · 1.67 KB
/
memento.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'rubygems'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'sinatra', require: 'sinatra/base'
gem 'omniauth'
gem 'omniauth-oauth2'
# gem 'omniauth-alfred', git: 'https://github.com/cybergizer-hq/omniauth-alfred'
gem 'dotenv'
gem 'pry'
end
Dotenv.load('.env.memento')
require 'omniauth-oauth2'
require 'json'
module OmniAuth
module Strategies
class Alfred < OmniAuth::Strategies::OAuth2
begin
require 'dotenv' unless defined?(ENV)
ALFRED_APP_URL = ENV.fetch('ALFRED_APP_URL', 'https://alfred-cg.herokuapp.com')
rescue LoadError
ALFRED_APP_URL = 'https://alfred-cg.herokuapp.com'.freeze
end
option :name, :alfred
option :client_options,
site: ALFRED_APP_URL,
authorize_path: '/oauth/authorize'
uid do
raw_info['uid']
end
info do
{
email: raw_info['email'],
alfred_id: raw_info['id'],
first_name: raw_info['first_name'],
last_name: raw_info['last_name'],
name: "#{raw_info['first_name']} #{raw_info['last_name']}",
avatar_url: raw_info['avatar'],
dob: raw_info['dob']
}
end
def raw_info
@raw_info ||= access_token.get('/api/v1/users/me.json').parsed
end
end
end
end
class Memento < Sinatra::Base
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :alfred, ENV['ALFRED_KEY'], ENV['ALFRED_SECRET'], scope: 'User'
end
get '/' do
"<a href='/auth/alfred'>Sign in Alfred</a>"
end
get '/auth/:name/callback' do
auth = request.env['omniauth.auth']
auth.inspect.to_s
end
end
Memento.run!