Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

auth button

  • Loading branch information...
commit ebf3f7e1ae0f7ce3faaa3ea20619d44a142cd23d 1 parent 0185617
Colm Doyle authored
Showing with 416 additions and 7 deletions.
  1. +52 −0 canvas/index.php
  2. +190 −0 index.php
  3. +174 −7 js/main.js
View
52 canvas/index.php
@@ -82,6 +82,44 @@
});
FB.Canvas.setAutoGrow();
+
+ FB.getLoginStatus(function(response) {
+ console.log(response);
+ if (response.status === 'connected') {
+ FB.api('/me?fields=name,picture', function(response) {
+ console.log(response);
+ $('#user-name-nav').html(response.name);
+ $('#user-login-control').prepend('<img src="'+response.picture.data.url+'" width="20" height="20" />');
+ $('#nav-bar-auth').remove();
+ $('#auth-dropdown').append('<li><a href="#" id="nav-bar-deauth">Deauth</a></li>');
+ $('#auth-dropdown').append('<li><a href="#" id="nav-bar-logout">Logout of FB</a></li>');
+
+ $('#nav-bar-logout').on('click', function() {
+ console.log('blah');
+ FB.logout(function(response){
+ console.log(response);
+ });
+ });
+
+ $('#nav-bar-deauth').on('click', function() {
+ FB.api('/me/permissions', 'delete', function(response) {
+ console.log(response);
+ if (response == true) {
+ $('#user-name-nav').html('Logged Out');
+ $('#auth-dropdown').html('<li id="auth-link"><a tabindex="-1" href="https://www.facebook.com/dialog/oauth?client_id=<?php echo $config['AppId']; ?>&redirect_uri=<?php echo $config['CanvasUrl']; ?>" target="_blank">Login</a></li>');
+ }
+ });
+ });
+
+ });
+ } else if (response.status === 'not_authorized') {
+ $('#user-name-nav').html('Logged Out');
+ $('#auth-dropdown').html('<li id="auth-link"><a tabindex="-1" href="https://www.facebook.com/dialog/oauth?client_id=<?php echo $config['AppId']; ?>&redirect_uri=<?php echo $config['CanvasUrl']; ?>" target="_blank">Login</a></li>');
+ } else {
+ $('#user-nav-section').remove();
+ }
+ });
+
};
// Load the SDK's source Asynchronously
@@ -171,6 +209,20 @@
</ul>
</li>
</ul>
+ <ul class="nav pull-right" id="user-nav-section">
+ <li class="divider-vertical"></li>
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown" id="user-login-control">
+ <span id="user-name-nav">Loading</span>
+ <b class="caret"></b>
+ </a>
+ <ul class="dropdown-menu" id="auth-dropdown">
+ <li id="auth-link">
+ <a tabindex="-1" href="https://www.facebook.com/dialog/oauth?client_id=<?php echo $config['AppId']; ?>&redirect_uri=<?php echo $config['CanvasUrl']; ?>" id="nav-bar-auth" target="_blank">Login</a>
+ </li>
+ </ul>
+ </li>
+ </ul>
</div>
</div>
<!-- !/NavBar -->
View
190 index.php
@@ -0,0 +1,190 @@
+<?php
+/*
+Copyright 2012 Colm Doyle
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+include(__DIR__ . '/includes/__init__.php');
+?>
+
+<!DOCTYPE html>
+<html lang="en">
+
+<?php
+echo output_header($config['RootUrl']);
+?>
+<body>
+<div id="fb-root"></div>
+<script>
+ window.fbAsyncInit = function() {
+ // init the FB JS SDK
+ FB.init({
+ appId : '<?php echo $config['AppId'];?>', // App ID from the App Dashboard
+ channelUrl : '<?php echo $config['ChannelUrl']; ?>', // Channel File for x-domain communication
+ status : true, // check the login status upon init?
+ cookie : true, // set sessions cookies to allow your server to access the session?
+ xfbml : true // parse XFBML tags on this page?
+ });
+
+ FB.Canvas.setAutoGrow();
+ };
+
+ // Load the SDK's source Asynchronously
+ // Note that the debug version is being actively developed and might
+ // contain some type checks that are overly strict.
+ // Please report such bugs using the bugs tool.
+ (function(d, debug){
+ 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" + (debug ? "/debug" : "") + ".js";
+ ref.parentNode.insertBefore(js, ref);
+ }(document, /*debug*/ false));
+</script>
+<!-- !NavBar -->
+<div class="navbar navbar-static-top">
+ <div class="navbar-inner">
+ <div class="container">
+
+ <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ </a>
+
+ <!-- Be sure to leave the brand out there if you want it shown -->
+ <a class="brand" href="#"><?php echo $config['AppName']; ?></a>
+
+ <!-- Everything you want hidden at 940px or less, place within here -->
+ <div class="nav-collapse collapse">
+ <ul class="nav">
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+ Dialogs
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu">
+ <li>
+ <a tabindex="-1" href="#" id="add_page_tab">
+ <i class="icon-plus"></i> Add Page Tab
+ </a>
+ </li>
+ <li>
+ <a tabindex="-1" href="#" id="feed_dialog">
+ <i class="icon-comment"></i> Feed
+ </a>
+ </li>
+ <li>
+ <a tabindex="-1" href="#" id="send_dialog">
+ <i class="icon-envelope"></i> Send
+ </a>
+ </li>
+ <li>
+ <a tabindex="-1" href="#oauth-modal" data-toggle="modal" id="oauth_dialog">
+ <i class="icon-lock"></i> OAuth
+ </a>
+ </li>
+ <li>
+ <a tabindex="-1" href="#" id="requests_mfs_dialog">
+ <i class="icon-globe"></i> Requests MultiFriend
+ </a>
+ </li>
+ </ul>
+ </li>
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+ Publishing
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu">
+ <li>
+ <a tabindex="-1" href="#myModal" data-toggle="modal" id="feed_publish">
+ <i class="icon-comment"></i> Post to Wall
+ </a>
+ </li>
+ <li>
+ <a tabindex="-1" href="#" id="publish_action">
+ <i class="icon-plus-sign"></i> Publish an Action
+ </a>
+ </li>
+ </ul>
+ </li>
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+ View On
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu">
+ <li>
+ <a tabindex="-1" href="<?php echo $config['CanvasUrl']; ?>" target="_blank">
+ <i class="icon-th-large"></i> Canvas
+ </a>
+ </li>
+ <li>
+ <a tabindex="-1" href="<?php echo $config['PageTabUrl']; ?>" target="_blank">
+ <i class="icon-flag"></i> Page Tab
+ </a>
+ </li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+ <div class="container-fluid">
+ <div class="row-fluid">
+ <div class="span12" id="explorer">
+ <h3> Graph API Explorer </h3>
+ <div class="row-fluid">
+ <div class="span12 controls controls-row control-group" id="explorer-form">
+ <form class="form-inline">
+ <div class="btn-group span1">
+ <button class="btn dropdown-toggle" data-toggle="dropdown" id="explorer-http-menu">
+ <span id="explorer-http-active">GET</span>
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu" id="explorer-dropdown">
+ <li>
+ <a href="#" id="explorer-dropdown-get">GET</a>
+ </li>
+ <li>
+ <a href="#" id="explorer-dropdown-post">POST</a>
+ </li>
+ <li>
+ <a href="#" id="explorer-dropdown-delete">DELETE</a>
+ </li>
+ </ul>
+ </div>
+ <input class="span10" type="text" placeholder="/" id="explorer-input">
+ <button class="btn btn-primary span1" id="explorer-submit">Submit</button>
+ </form>
+ </div>
+ </div>
+ </div>
+ </div>
+ <hr />
+ <div class="row-fluid" id="explorer-response-row">
+ <div class="span12" id="explorer-response-span">
+ <pre id="explorer-response" class="prettyprint">
+ </pre>
+ </div>
+ </div>
+ </div>
+
+</body>
+</html>
+
+
View
181 js/main.js
@@ -15,10 +15,177 @@ limitations under the License.
*/
-$(document).ready(function(){prettyPrint();var num_of_post_params=0;if($("[rel=popover]").length){$("[rel=popover]").popover();}
-$('#add_page_tab').click(function(){FB.ui({method:'pagetab',redirect_uri:'https://colmd.fbdublin.com/fb-diagnostics/page-tab/'});});$('#send_dialog').click(function(){FB.ui({method:'send',link:'https://www.github.com/colmdoyle/fb-diagnostics'},function(response){$('#alert-container').html('<div class="alert alert-success">'+response.post_id+'<a class="close" data-dismiss="alert" href="#">&times;</a></div>');});});$('#requests_mfs_dialog').click(function(){FB.ui({method:'apprequests',message:'You should see this test app'},function(response){console.log(response);$('#alert-container').html('<div class="alert alert-success"><p><strong>Request ID: </strong>'+response.request+'</p><p><strong>Recipients: </strong>'+response.to+'</p><a class="close" data-dismiss="alert" href="#">&times;</a></div>');});});$('#feed_dialog').click(function(){FB.ui({method:'feed',redirect_uri:'https://colmd.fbdublin.com/fb-diagnostics/page-tab/',link:'https://github.com/colmdoyle/fb-diagnostics',picture:'https://colmd.fbdublin.com/fb-diagnostics/img/320x320.png',name:'Diagnostics App',caption:'It\'s a great app altogether',description:'Source code for a Facebook App that can be used to test various APIs & features of Facebook Apps.'},function(response){$('#alert-container').html('<div class="alert alert-success">'+response.post_id+'<a class="close" data-dismiss="alert" href="#">&times;</a></div>');});});$('#publish_action').click(function(){FB.api('/me/diagnostics-app:test','post',{testing_object:'http://colmd.fbdublin.com/fb-diagnostics/objects/testing.php'},function(response){if(response.error){$('#alert-container').html('<div class="alert alert-error">'+response.error+'<a class="close" data-dismiss="alert" href="#">&times;</a></div>');}else if(response.id){$('#alert-container').html('<div class="alert alert-success">'+response.id+'<a class="close" data-dismiss="alert" href="#">&times;</a></div>');}else{$('#alert-container').html('<div class="alert alert-error"> An unknown error has occurred, check your console. <a class="close" data-dismiss="alert" href="#">&times;</a></div>');console.log(response);}});});$('#publish_submit').click(function(){var message_val=$('#message_box_modal').val();FB.api('/me/feed','post',{message:message_val},function(response){if(response.error){$('#alert-container').html('<div class="alert alert-error">'+response.error+'<a class="close" data-dismiss="alert" href="#">&times;</a></div>');console.log(response);}else if(response.id){$('#alert-container').html('<div class="alert alert-success">'+response.id+'<a class="close" data-dismiss="alert" href="#">&times;</a></div>');$('#message_box_modal').val('');}else{$('#alert-container').html('<div class="alert alert-error"> An unknown error has occurred, check your console. <a class="close" data-dismiss="alert" href="#">&times;</a></div>');console.log(response);}});});$('#oauth_submit').click(function(){var scope='';var perms=$('#oauth_scope_form').find('input:checked');var perms_length=perms.length-1;$(perms).each(function(index){scope+=$(this).val();if(index<perms_length){scope+=',';}});FB.login(function(response){$('#oauth-modal').modal('hide');$('#oauth_scope_form').find('input:checked').removeAttr('checked');var oauth_html_response='<ul class="unstyled">';$.each(response.authResponse,function(key,valueObj){oauth_html_response+='<li class="break-all"><strong>'+key+'</strong> : '+valueObj+'</li>';});oauth_html_response+='</ul>'
-$('#alert-container').html('<div class="alert alert-success"><a class="close" data-dismiss="alert" href="#">&times;</a><h4>Response Object</h4>'+oauth_html_response+'</div>');console.log(response);},{scope:scope});});$('#clear_checkbox').click(function(){$('#oauth_scope_form').find('input:checked').removeAttr('checked');});$('#explorer-dropdown li a').click(function(){if($(this).html()=='POST'){$('#explorer').append('<div class="row-fluid"><div id="post-field-row" class="span11 offset1 controls"><a id="field-add" href="#"> Add a field </a></div></div>');$('#field-add').on('click',function(event){num_of_post_params++;$('#post-field-row').append('<div class="controls-row param-pair" id="param-pair-'+num_of_post_params+'"><input class="span2 post-field" type="text" placeholder="name" name="name"><input class="span2 value post-field" type="text" placeholder="value" name="value"></div>');});}else{$('#post-field-row').remove();}
-$('#explorer-http-active').text($(this).html());});$('#explorer-input').focus(function(){$('#explorer-form').removeClass('error');})
-$('#explorer-submit').on('click',function(e){var http_method=$('#explorer-http-active').html();var path=$('#explorer-input').val();var param_pair_total=$(".param-pair").length;var post_params='{';$(".param-pair").each(function(index){name=$(this).children(":nth-child(1)").val();value=$(this).children(":nth-child(2)").val();post_params+='"'+name+'":"'+value+'"';if(index===param_pair_total-1){post_params+='';}else{post_params+=',';}});post_params+='}';params_object=$.parseJSON(post_params);if(path){if(path.charAt(0)!='/'){path='/'+path;}
-if(post_params.length>3){FB.api(path,http_method,params_object,function(response){console.log(response);$('#explorer-response').text(JSON.stringify(response,null,'\t'));$('#explorer-response').addClass('lang-js');prettyPrint();});}else{FB.api(path,http_method,function(response){console.log(response);$('#explorer-response').text(JSON.stringify(response,null,'\t'));$('#explorer-response').addClass('lang-js');prettyPrint();});}}else{$('#explorer-form').addClass('error');}
-e.preventDefault();});});
+$(document).ready(function () {
+ prettyPrint();
+
+ var num_of_post_params = 0;
+
+ if ($("[rel=popover]").length) {
+ $("[rel=popover]").popover();
+ }
+
+ $('#add_page_tab').click(function(){
+ FB.ui({method: 'pagetab', redirect_uri: 'https://colmd.fbdublin.com/fb-diagnostics/page-tab/'});
+ });
+
+ $('#send_dialog').click(function(){
+ FB.ui({method: 'send', link: 'https://www.github.com/colmdoyle/fb-diagnostics'},
+ function(response) {
+ $('#alert-container').html('<div class="alert alert-success">'+ response.post_id + '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ });
+ });
+
+ $('#requests_mfs_dialog').click(function(){
+ FB.ui({method: 'apprequests', message: 'You should see this test app'},
+ function(response) {
+ console.log(response);
+ $('#alert-container').html('<div class="alert alert-success"><p><strong>Request ID: </strong>'+ response.request +'</p><p><strong>Recipients: </strong>' + response.to + '</p><a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ });
+ });
+
+ $('#feed_dialog').click(function(){
+ FB.ui({
+ method: 'feed',
+ redirect_uri: 'https://colmd.fbdublin.com/fb-diagnostics/page-tab/',
+ link:'https://github.com/colmdoyle/fb-diagnostics',
+ picture: 'https://colmd.fbdublin.com/fb-diagnostics/img/320x320.png',
+ name: 'Diagnostics App',
+ caption: 'It\'s a great app altogether',
+ description: 'Source code for a Facebook App that can be used to test various APIs & features of Facebook Apps.'
+ },
+ function(response) {
+ $('#alert-container').html('<div class="alert alert-success">'+ response.post_id + '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ });
+ });
+
+ $('#publish_action').click(function(){
+ FB.api('/me/diagnostics-app:test', 'post', {testing_object: 'http://colmd.fbdublin.com/fb-diagnostics/objects/testing.php'},
+ function(response){
+ if (response.error) {
+ $('#alert-container').html('<div class="alert alert-error">'+ response.error + '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ } else if (response.id) {
+ $('#alert-container').html('<div class="alert alert-success">'+ response.id + '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ } else {
+ $('#alert-container').html('<div class="alert alert-error"> An unknown error has occurred, check your console. <a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ console.log(response);
+ }
+ });
+ });
+
+ $('#publish_submit').click(function(){
+ var message_val = $('#message_box_modal').val();
+ FB.api('/me/feed', 'post', {message: message_val},
+ function(response){
+ if (response.error) {
+ $('#alert-container').html('<div class="alert alert-error">'+ response.error + '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ console.log(response);
+ } else if (response.id) {
+ $('#alert-container').html('<div class="alert alert-success">'+ response.id + '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ $('#message_box_modal').val('');
+ } else {
+ $('#alert-container').html('<div class="alert alert-error"> An unknown error has occurred, check your console. <a class="close" data-dismiss="alert" href="#">&times;</a></div>');
+ console.log(response);
+ }
+ });
+ });
+
+ $('#oauth_submit').click(function(){
+ var scope = '';
+ var perms = $('#oauth_scope_form').find('input:checked');
+ var perms_length = perms.length - 1;
+ $(perms).each(function(index) {
+ scope += $(this).val();
+ if (index < perms_length) {
+ scope += ',';
+ }
+ });
+ FB.login(function(response){
+ $('#oauth-modal').modal('hide');
+ $('#oauth_scope_form').find('input:checked').removeAttr('checked');
+ var oauth_html_response = '<ul class="unstyled">';
+ $.each(response.authResponse, function(key, valueObj) {
+ oauth_html_response += '<li class="break-all"><strong>'+key+'</strong> : '+valueObj+'</li>';
+ });
+ oauth_html_response += '</ul>'
+ $('#alert-container').html('<div class="alert alert-success"><a class="close" data-dismiss="alert" href="#">&times;</a><h4>Response Object</h4>'+ oauth_html_response + '</div>');
+ console.log(response);
+ }, {scope: scope});
+ });
+
+ $('#clear_checkbox').click(function() {
+ $('#oauth_scope_form').find('input:checked').removeAttr('checked');
+ });
+
+ $('#explorer-dropdown li a').click(function() {
+ if ($(this).html() == 'POST') {
+ $('#explorer').append('<div class="row-fluid"><div id="post-field-row" class="span11 offset1 controls"><a id="field-add" href="#"> Add a field </a></div></div>');
+ $('#field-add').on('click', function(event){
+ num_of_post_params++;
+ $('#post-field-row').append('<div class="controls-row param-pair" id="param-pair-'+num_of_post_params+'"><input class="span2 post-field" type="text" placeholder="name" name="name"><input class="span2 value post-field" type="text" placeholder="value" name="value"></div>');
+ });
+ } else {
+ $('#post-field-row').remove();
+ }
+ $('#explorer-http-active').text($(this).html());
+ });
+
+ $('#explorer-input').focus(function() {
+ $('#explorer-form').removeClass('error');
+ })
+
+ $('#explorer-submit').on('click', function(e) {
+
+ var http_method = $('#explorer-http-active').html();
+ var path = $('#explorer-input').val();
+
+ var param_pair_total = $(".param-pair").length;
+ var post_params = '{';
+
+ $(".param-pair").each(function(index) {
+ name = $(this).children(":nth-child(1)").val();
+ value = $(this).children(":nth-child(2)").val();
+
+ post_params += '"'+name+'":"'+value+'"';
+
+ if (index === param_pair_total - 1) {
+ post_params += '';
+ } else {
+ post_params += ',';
+ }
+
+ });
+ post_params += '}';
+
+ params_object = $.parseJSON(post_params);
+
+ if (path) {
+ if (path.charAt(0) != '/') {
+ path = '/' + path;
+ }
+
+ if (post_params.length > 3) {
+ FB.api(path, http_method, params_object,
+ function(response){
+ console.log(response);
+ $('#explorer-response').text(JSON.stringify(response, null, '\t'));
+ $('#explorer-response').addClass('lang-js');
+ prettyPrint();
+ });
+ } else {
+ FB.api(path, http_method,
+ function(response){
+ console.log(response);
+ $('#explorer-response').text(JSON.stringify(response, null, '\t'));
+ $('#explorer-response').addClass('lang-js');
+ prettyPrint();
+ });
+ }
+ } else {
+ $('#explorer-form').addClass('error');
+ }
+
+ e.preventDefault();
+ });
+
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.