Skip to content

Instantly share code, notes, and snippets.

View Spyna's full-sized avatar
💭
🚀

Lorenzo Spinelli Spyna

💭
🚀
View GitHub Profile
import React from 'react';
import LoadingOverlay from './Loader'
export default (loader, props) => (
class AsyncComponent extends React.Component {
constructor(props) {
super(props);
this.Component = null;
this.state = { Component: AsyncComponent.Component };
}
var jwt = require('./jwt');
const checkToken = ( req ) => {
//get the http header 'authorization'
let authorization = req.get( 'authorization' );
if ( !authorization ) {
throw new Error( 401 )
}
//check the token signature with 'jwt.js' library
let token = authorization.replace( 'Bearer ', '' );
const credentials = require( './credentials.json' ).facebook
const { client_id, client_secret } = credentials;
var fetch = require( 'node-fetch' );
module.exports.getUser = ( code ) => {
let appToken;
let url = 'https://graph.facebook.com/oauth/access_token?client_id=' + client_id + '&client_secret=' + client_secret + '&grant_type=client_credentials';
var jwt = require( 'jsonwebtoken' );
const secret = require( './credentials.json' ).jwt.secret
var createToken = ( user ) => {
return "thisisthetokenof:" + user.id
}
module.exports.verify = ( token ) => {
try {
var express = require( 'express' );
var bodyParser = require( 'body-parser' );
var googleAuth = require( './googleAuth.js' );
var app = express();
var jwt = require('./jwt.js')
app.use( bodyParser.json() );
app.use( bodyParser.urlencoded( { extended: false } ) );
@Spyna
Spyna / googleAuth.js
Last active February 1, 2018 11:30
google-auth-library token_id check
const credentials = require( './credentials.json' )
const GOOGLE_CLIENT_ID = credentials.google.client_id;
const { OAuth2Client } = require( 'google-auth-library' );
var client = new OAuth2Client( GOOGLE_CLIENT_ID, '', '' );
//return a promise with user informations
module.exports.getGoogleUser = ( code ) => {
//verify the token using google client
return client.verifyIdToken( { idToken: code, audience: GOOGLE_CLIENT_ID } )
.then( login => {