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
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(); |
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
[HttpPost] | |
[AllowAnonymous] | |
[Route("FacebookLogin")] | |
public async Task<IHttpActionResult> FacebookLogin([FromBody] string token) | |
{ | |
if (string.IsNullOrEmpty(token)) | |
{ | |
return BadRequest("Invalid OAuth access token"); | |
} |
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
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 = () => |
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
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 { |
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
// 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, |
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
test: | |
@./node_modules/.bin/mocha | |
.PHONY: test |
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
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 |
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
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 | |
}); |
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
// ******************************************************* | |
// expressjs template | |
// | |
// assumes: npm install express | |
// defaults to jade engine, install others as needed | |
// | |
// assumes these subfolders: | |
// public/ | |
// public/javascripts/ | |
// public/stylesheets/ |
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
module.exports = { | |
"db": { | |
"mongodb": "mongodb://username:[email protected]:45077/databasename" | |
}, | |
"logger": { | |
"api": "logs/api.log", | |
"exception": "logs/exceptions.log" | |
} | |
}; |
NewerOlder