forked from oesmith/puffing-billy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up and a facebook API stubbing example.
- Loading branch information
Showing
9 changed files
with
146 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
log/test.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<div id="fb-root"></div> | ||
<script> | ||
// Load the SDK Asynchronously | ||
(function(d){ | ||
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; | ||
if (d.getElementById(id)) {return;} | ||
js = d.createElement('script'); js.id = id; js.async = true; | ||
js.src = "//connect.facebook.net/en_US/all.js"; | ||
ref.parentNode.insertBefore(js, ref); | ||
}(document)); | ||
|
||
// Init the SDK upon load | ||
window.fbAsyncInit = function() { | ||
FB.init({ | ||
appId : '408416075843608', // App ID | ||
//channelUrl : '//'+window.location.hostname+'/channel', // Path to your Channel File | ||
status : true, // check login status | ||
cookie : true, // enable cookies to allow the server to access the session | ||
xfbml : true // parse XFBML | ||
}); | ||
|
||
// listen for and handle auth.statusChange events | ||
FB.Event.subscribe('auth.statusChange', function(response) { | ||
if (response.authResponse) { | ||
// user has auth'd your app and is logged into Facebook | ||
FB.api('/me', function(me){ | ||
if (me.name) { | ||
document.getElementById('auth-displayname').innerHTML = me.name; | ||
} | ||
}) | ||
document.getElementById('auth-loggedout').style.display = 'none'; | ||
document.getElementById('auth-loggedin').style.display = 'block'; | ||
} else { | ||
// user has not auth'd your app, or is not logged into Facebook | ||
document.getElementById('auth-loggedout').style.display = 'block'; | ||
document.getElementById('auth-loggedin').style.display = 'none'; | ||
} | ||
}); | ||
|
||
// respond to clicks on the login and logout links | ||
document.getElementById('auth-loginlink').addEventListener('click', function(){ | ||
FB.login(); | ||
}); | ||
document.getElementById('auth-logoutlink').addEventListener('click', function(){ | ||
FB.logout(); | ||
}); | ||
} | ||
</script> | ||
|
||
<h1>Facebook Client-side Authentication Example</h1> | ||
<div id="auth-status"> | ||
<div id="auth-loggedout"> | ||
<a href="#" id="auth-loginlink">Login</a> | ||
</div> | ||
<div id="auth-loggedin" style="display:none"> | ||
Hi, <span id="auth-displayname"></span> | ||
(<a href="#" id="auth-logoutlink">logout</a>) | ||
</div> | ||
</div> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
require 'base64' | ||
|
||
describe 'Facebook API example', :type => :request, :js => true do | ||
before do | ||
proxy.stub('https://www.facebook.com:443/dialog/oauth').and_return(Proc.new { |params,_,_| | ||
# mock a signed request from facebook. the JS api never verifies the | ||
# signature, so all it needs is the base64-encoded payload | ||
signed_request = "xxxxxxxxxx.#{Base64.encode64('{"user_id":"1234567"}')}" | ||
# redirect to the 'redirect_uri', with some extra crap in the query | ||
# string | ||
{:redirect_to => "#{params['redirect_uri'][0]}&access_token=foobar&expires_in=600&base_domain=localhost&https=1&signed_request=#{signed_request}"} | ||
}) | ||
|
||
proxy.stub('https://graph.facebook.com:443/me').and_return(:jsonp => {:name => 'Tester 1'}) | ||
end | ||
|
||
it 'should show me as logged-in', :js => true do | ||
visit '/facebook_api.html' | ||
page.should have_content "Hi, Tester 1" | ||
end | ||
end | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters