Skip to content

Instantly share code, notes, and snippets.

Avatar

Valerio Gheri vgheri

View GitHub Profile
@vgheri
vgheri / gist:9737178
Created Mar 24, 2014
Verify Facebook Access Token
View gist:9737178
private async Task<FacebookUserViewModel> VerifyFacebookAccessToken(string accessToken)
{
FacebookUserViewModel fbUser = null;
var path = "https://graph.facebook.com/me?access_token=" + accessToken;
var client = new HttpClient();
var uri = new Uri(path);
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
@vgheri
vgheri / AccountController.cs
Created Mar 1, 2014
FacebookLogin API endpoint
View AccountController.cs
[HttpPost]
[AllowAnonymous]
[Route("FacebookLogin")]
public async Task<IHttpActionResult> FacebookLogin([FromBody] string token)
{
if (string.IsNullOrEmpty(token))
{
return BadRequest("Invalid OAuth access token");
}
@vgheri
vgheri / Startup.cs
Created Mar 1, 2014
Startup machinery
View Startup.cs
public partial class Startup
{
/// <summary>
/// This part has been added to have an API endpoint to authenticate users that accept a Facebook access token
/// </summary>
static Startup()
{
PublicClientId = "self";
UserManagerFactory = () =>
View gist:7645778
function authorise(req, res, next) {
var apiAccessToken = req.body.apiAccessToken || null;
var userId = req.params.userId || req.body.userId || null;
if (apiAccessToken && userId) {
SecurityToken.authorise(apiAccessToken, userId)
.then(function(authorised) {
if (authorised) {
next();
}
else {
@vgheri
vgheri / verifyFacebookUserAccessToken.js
Created Nov 25, 2013
// Call facebook API to verify the token is valid
View verifyFacebookUserAccessToken.js
// Call facebook API to verify the token is valid
// https://graph.facebook.com/me?access_token=$token
function verifyFacebookUserAccessToken(token) {
var deferred = Q.defer();
var path = 'https://graph.facebook.com/me?access_token=' + token;
request(path, function (error, response, body) {
var data = JSON.parse(body);
if (!error && response && response.statusCode && response.statusCode == 200) {
var user = {
facebookUserId: data.id,
View Makefile
test:
@./node_modules/.bin/mocha
.PHONY: test
View test.js
var should = require('should');
var assert = require('assert');
var request = require('supertest');
var mongoose = require('mongoose');
var winston = require('winston');
var config = require('./config-debug');
describe('Routing', function() {
var url = 'http://someurl.com';
// within before() you can run all the operations that are needed to setup your tests. In this case
View index.js
var config = require('./Config-debug');
var winston = require('winston');
var mongoose = require('mongoose');
var server = require('./Server');
// We will log normal api operations into api.log
console.log("starting logger...");
winston.add(winston.transports.File, {
filename: config.logger.api
});
View server.js
// *******************************************************
// expressjs template
//
// assumes: npm install express
// defaults to jade engine, install others as needed
//
// assumes these subfolders:
// public/
// public/javascripts/
// public/stylesheets/
View config.js
module.exports = {
"db": {
"mongodb": "mongodb://username:password@dsXXXXX.mongolab.com:45077/databasename"
},
"logger": {
"api": "logs/api.log",
"exception": "logs/exceptions.log"
}
};
You can’t perform that action at this time.