Skip to content

Instantly share code, notes, and snippets.

View jboxman's full-sized avatar

Jason Βoxman jboxman

View GitHub Profile
@jboxman
jboxman / projectModel.js
Created December 19, 2017 23:07
bears11Models
const projectSchema = mongoose.Schema({
title: {
type: String,
required: true
},
description: {
type: String,
required: false
},
projectLevel: {
@jboxman
jboxman / App.js
Last active October 1, 2018 05:05
github-sso-auth-code-flow #7
import React from 'react';
import propTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import loginTab from '../../util/openWindow';
import * as userActions from '../redux/userActions';
import { STATE_KEY as USER_STATE_KEY } from '../redux/userReducer';
class AppMenu extends React.Component {
@jboxman
jboxman / openWindow.js
Last active October 1, 2018 04:45
github-sso-auth-code-flow #6
// From https://gist.github.com/gauravtiwari/2ae9f44aee281c759fe5a66d5c2721a2
// By https://gist.github.com/gauravtiwari
/* global window */
const loginTab = (myUrl) => {
const windowArea = {
width: Math.floor(window.outerWidth * 0.8),
height: Math.floor(window.outerHeight * 0.5),
};
@jboxman
jboxman / authentication.js
Created September 18, 2017 23:49
github-sso-auth-code-flow #5
// http://scottksmith.com/blog/2014/09/18/beer-locker-building-a-restful-api-with-node-username-and-password/
const passport = require('koa-passport');
const GitHubStrategy = require('passport-github2').Strategy;
const MockStrategy = require('./mock-strategy').Strategy;
const User = require('../backend/entities/users/userModel');
function onSuccess(accessToken, refreshToken, profile, done) {
// https://stackoverflow.com/questions/20431049/what-is-function-user-findorcreate-doing-and-when-is-it-called-in-passport
User.findOrCreate(
@jboxman
jboxman / success.html
Last active October 1, 2018 04:42
github-sso-auth-code-flow #4
<!doctype html>
<html lang="en">
<head>
<title>Login successful</title>
</head>
<body>
<h1>Success</h1>
<p>You are authenticated...</p>
</body>
<script>
@jboxman
jboxman / userRoutes.js
Last active October 1, 2018 04:52
github-sso-auth-code-flow #3
const Router = require('koa-router');
const passport = require('koa-passport');
const isAuthenticated = (ctx, next) => {
return ctx.isAuthenticated() ? next() : ctx.status = 403;
};
const router = new Router();
router.get('/auth/github',
@jboxman
jboxman / userModel.js
Created September 18, 2017 23:45
github-sso-auth-code-flow #2
const mongoose = require('mongoose');
const findOrCreate = require('mongoose-findorcreate');
const userSchema = mongoose.Schema({
username: {
type: String,
required: true
},
email: {
type: String,
@jboxman
jboxman / userActionTypes.js
Created September 18, 2017 23:41
github-sso-auth-code-flow #1
export const INJECT = 'INJECT_USER';
export const LOGOUT = 'LOGOUT_USER';
@jboxman
jboxman / App.js
Last active January 3, 2021 16:06
Github OAuth 2.0 authorization grant code SPA integration - deprecated
const config = require('../../config/envs');
import React from 'react';
import propTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import {
Input,
Menu,
@jboxman
jboxman / skillSchema.js
Last active August 4, 2017 19:00
deprecated - moved to git repo
const skillSchema = mongoose.Schema(
{
// This can reference another collection, but for our purposes a string is likely acceptable
domain: {
type: String,
trim: true,
required: true
},
name: {
type: String,