Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
# SimpleGithubAuthentication
Github authentication flow made easy

## Demo

[Click here to view the demo](https://the-brains.github.io/SimpleGithubAuthentication/example/public)

## Description

To perform Github operation, you need an authToken. This can be a personal token from your Github account, or an authToken optained by authenticating with an app.
This repo provides a server code for simplifying the workflow.

## Setup

1. Register a new Github app
2. Take note of the app_id, client_id / client_secret
3. Setup this package on a Node.js server
4. Pre-fill with the appID, client ID and secret from environment variables.
5. Get the callbackUrl and fill it in your Github app.
6. Use the loginUrl to request the login.
7. You will be taken to the Github authentication, where a login window will popup asking to authorize your app.
8. You will be taken to the "callback_url" you chose, with the authToken passed as query parameters.

## Login

Use the login URL. It should be something like:
"https://<your-server>/github/login/<app_id>?callback=<your-callback_url>

## Registering new apps in the server

The server allows registering new apps with client_id / client_secret on the fly. This is mainly for testing purposes, but it can also be useful if you want a Github server responsible for authenticating multiple apps.
3 changes: 3 additions & 0 deletions auto-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bun run build
bun run build:demo
npm run auto-publish
Binary file modified bun.lockb
Binary file not shown.
10 changes: 10 additions & 0 deletions bundler/bundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
async function bundle() {
await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './out',
minify: true,
target: "browser",
});
}

bundle();
4 changes: 4 additions & 0 deletions demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bun run build

cd example
bun start
175 changes: 175 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
!dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
15 changes: 15 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# demo

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.0.26. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file added example/bun.lockb
Binary file not shown.
Empty file added example/favicon.ico
Empty file.
28 changes: 28 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import express from "express";
import path from "path";
import { GithubAuthServer } from "simple-github-authentication";

const app = express();
const port = parseInt(process.env.PORT ?? "3000");


const githubAuthServer = new GithubAuthServer(app, {
rootPath: "/public/",
});

app.get("/public/is-node-server.json", (req, res) => {
res.json(true)
});

app.get("/public/make-serverless.json", (req, res) => {
githubAuthServer.active = req.query.serverless !== "true";
res.json({
serverless: !githubAuthServer.active,
})
});

app.use('/public', express.static(path.join(import.meta.dir, 'public')));

app.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
17 changes: 17 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "demo",
"scripts": {
"start": "bun run build && bun run index.ts --watch",
"build": "bun i && bun build --target=node ./src/index.ts --outfile=public/dist/index.js"
},
"devDependencies": {
"@types/bun": "^1.1.2"
},
"peerDependencies": {
"typescript": "^5.0.0",
"simple-github-authentication": "link:simple-github-authentication"
},
"dependencies": {
"express": "^4.19.2"
}
}
Loading