This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
demo.rb
73 lines (68 loc) · 1.6 KB
/
demo.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
require 'rubygems'
require 'sinatra'
require 'omniauth'
require 'omniauth-twitter'
require 'json'
enable :sessions
enable :static
set :bind, '0.0.0.0'
set :public_folder, './src'
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :twitter, 'o34XdCrvjvl0Q42yzN6A', 'EqepTHaFugcAPYrc3OJYRWLkQpXJHogmjEMZ8KHgwLE'
end
get '/' do
<<-HTML
<html>
<head>
<title>Twitter OAuth via popup</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="/jquery.oauthpopup.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$('#connect').click(function(){
$.oauthpopup({
path: '/auth/twitter',
callback: function(){
$.get('/user_info', function(data){
$('#user_info').html(JSON.stringify(data));
});
}
});
});
$('#connect2').oauthpopup({
path: '/auth/twitter',
callback: function(){
$.get('/user_info', function(data){
$('#user_info').html(JSON.stringify(data));
});
}
});
});
</script>
<div id="user_info"></div>
<input type="button" value="Connect with Twitter (1)" id="connect" /><br />
<input type="button" value="Connect with Twitter (2)" id="connect2" /><br />
<a href="/signout">Sign Out</a>
</body>
</html>
HTML
end
get '/user_info' do
content_type :json
session[:info].to_json
end
get '/auth/:name/callback' do
session[:info] = request.env['omniauth.auth'][:info]
<<-HTML
<script>
window.close();
</script>
HTML
end
get '/signout' do
session.clear
redirect '/'
end