Skip to content

Instantly share code, notes, and snippets.

View vgheri's full-sized avatar

Valerio Gheri vgheri

View GitHub Profile
@vgheri
vgheri / gist:9737178
Created March 24, 2014 09:35
Verify Facebook Access Token
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 March 1, 2014 14:02
FacebookLogin API endpoint
[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 March 1, 2014 13:55
Startup machinery
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 = () =>
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 November 25, 2013 18:08
// Call facebook API to verify the token is valid
// 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,
test:
@./node_modules/.bin/mocha
.PHONY: test
@vgheri
vgheri / test.js
Last active December 16, 2015 11:49
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
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
});
// *******************************************************
// expressjs template
//
// assumes: npm install express
// defaults to jade engine, install others as needed
//
// assumes these subfolders:
// public/
// public/javascripts/
// public/stylesheets/
module.exports = {
"db": {
"mongodb": "mongodb://username:password@dsXXXXX.mongolab.com:45077/databasename"
},
"logger": {
"api": "logs/api.log",
"exception": "logs/exceptions.log"
}
};