forked from nobuf/jQuery-OAuth-Popup
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.rb
More file actions
63 lines (58 loc) · 1.28 KB
/
demo.rb
File metadata and controls
63 lines (58 loc) · 1.28 KB
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
require 'rubygems'
require 'sinatra'
require 'omniauth'
require 'omniauth-twitter'
require 'json'
enable :sessions
enable :static
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.7.0/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));
});
}
});
});
});
</script>
<div id="user_info"></div>
<input type="button" value="Connect with Twitter" id="connect" /><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