├── .dockerignore ├── .env.example ├── .gitignore ├── Dockerfile ├── README.md ├── demo ├── hod-auth.js ├── hod-button.js ├── hod-create-container.js ├── hod-toolbar.js ├── index.html ├── package-lock.json ├── package.json ├── scripts.js ├── store.js └── web_modules │ ├── @adobe │ └── lit-mobx.js │ ├── @lrnwebcomponents │ ├── hax-logo.js │ └── simple-login.js │ ├── @vaadin │ └── router.js │ ├── import-map.json │ ├── lit-element.js │ ├── mobx.js │ └── shader-doodle.js ├── docker-compose-traefik-v1.yml ├── docker-compose.yml ├── package.json ├── prisma ├── migrations │ ├── 20191002140626-initial │ │ ├── README.md │ │ ├── schema.prisma │ │ └── steps.json │ └── lift.lock └── schema.prisma ├── seed.ts ├── server └── index.js ├── tsconfig.json └── yarn.lock /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | GITHUB_CLIENT_ID=xxxxxxxxxxxxxxxxxxxx 2 | GITHUB_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 3 | GITHUB_SCOPE=user:email,read:user,public_rep 4 | PRISMA_DB_PROVIDER=postgresql 5 | PRISMA_DB_URL=postgresql://prisma:prisma@postgres/ 6 | HAXCMS_OAUTH_JWT_SECRET=abc123 #shared secret with other microservices that need to decode the jwt 7 | HAXCMS_OAUTH_JWT_REFRESH_SECRET=zyx456 8 | FQDN=http://auth.haxcms.localhost 9 | SCOPE=haxcms.localhost -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:12 2 | 3 | WORKDIR /home/node/app 4 | 5 | COPY package.json yarn.lock ./ 6 | RUN yarn --pure-lockfile --no-cache 7 | 8 | RUN chown -R node:node node_modules 9 | RUN chown -R node:node /tmp 10 | COPY --chown=node:node . . 11 | 12 | USER node 13 | 14 | CMD [ "yarn", "start" ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HAXcms Github Oauth Microservice 2 | 3 | This is a standalone microservice that will login a user via Github OAuth, 4 | store create a user in this auth service db, issue a jwt, store it in a Cookie, 5 | and redirect the user back to the requesting page. 6 | 7 | ## Development 8 | 9 | Create a Github Oauth App 10 | 11 | ```bash 12 | cp .env.example .env 13 | ``` 14 | 15 | Add your credentials to the .env file 16 | 17 | ```bash 18 | docker-compose up --build 19 | ``` 20 | 21 | Visit `http://haxcms.localhost/login` 22 | -------------------------------------------------------------------------------- /demo/hod-auth.js: -------------------------------------------------------------------------------- 1 | import { html } from "../../web_modules/lit-element.js"; 2 | import { MobxLitElement } from "../../web_modules/@adobe/lit-mobx.js"; 3 | import { store } from './store.js' 4 | 5 | class HodAuth extends MobxLitElement { 6 | constructor() { 7 | super(); 8 | this.store = store 9 | } 10 | async connectedCallback() { 11 | super.connectedCallback(); 12 | 13 | await this.getAccessToken(); 14 | await this.getUser(); 15 | } 16 | 17 | async getAccessToken() { 18 | try { 19 | const access_token = await fetch( 20 | "http://auth.haxcms.localhost/access_token", 21 | { 22 | credentials: "include" 23 | } 24 | ); 25 | if (access_token.status === 200) { 26 | window.localStorage.setItem("access_token", await access_token.json()); 27 | return await access_token.json(); 28 | } 29 | } catch (error) {} 30 | } 31 | 32 | async getUser() { 33 | if (typeof window.localStorage.access_token !== "undefined") { 34 | const access_token = window.localStorage.access_token 35 | const user = await fetch("http://auth.haxcms.localhost/graphql", { 36 | method: "POST", 37 | headers: { 38 | Accept: "application/json", 39 | "Content-Type": "application/json", 40 | Authorization: `Bearer ${access_token}` 41 | }, 42 | body: ' \ 43 | { \ 44 | "query": "query { user { name }}" \ 45 | }' 46 | }).then(res => res.json()); 47 | 48 | this.store.name = user.data.user.name 49 | } 50 | } 51 | 52 | } 53 | customElements.define("hod-auth", HodAuth); 54 | -------------------------------------------------------------------------------- /demo/hod-button.js: -------------------------------------------------------------------------------- 1 | import { LitElement, html } from "../../web_modules/lit-element.js"; 2 | import { MobxLitElement } from "../../web_modules/@adobe/lit-mobx.js"; 3 | 4 | class HodButton extends MobxLitElement { 5 | static get properties() { 6 | } 7 | 8 | constructor() { 9 | super(); 10 | } 11 | 12 | render() { 13 | return html` 14 | `; 15 | } 16 | } 17 | customElements.define("hod-button", HodButton); 18 | -------------------------------------------------------------------------------- /demo/hod-create-container.js: -------------------------------------------------------------------------------- 1 | import { LitElement, html } from "../../web_modules/lit-element.js"; 2 | import { MobxLitElement } from "../../web_modules/@adobe/lit-mobx.js"; 3 | import { store } from "./store.js"; 4 | 5 | class HodCreateContainer extends MobxLitElement { 6 | constructor() { 7 | super(); 8 | this.store = store; 9 | } 10 | 11 | render() { 12 | return html` 13 | 40 | ${this.store.name 41 | ? this.store.createContainer.state === "default" 42 | ? html` 43 |
46 | ` 47 | : this.store.createContainer.state === "initialized" 48 | ? html` 49 | 52 | ` 53 | : "" 54 | : ""} 55 | `; 56 | } 57 | 58 | __clicked(e) { 59 | this.store.createContainer.state = "initialized"; 60 | } 61 | } 62 | customElements.define("hod-create-container", HodCreateContainer); 63 | -------------------------------------------------------------------------------- /demo/hod-toolbar.js: -------------------------------------------------------------------------------- 1 | import { LitElement, html } from "../../web_modules/lit-element.js"; 2 | import { MobxLitElement } from "../../web_modules/@adobe/lit-mobx.js"; 3 | import { store } from "./store.js" 4 | import "../../web_modules/@lrnwebcomponents/hax-logo.js"; 5 | 6 | class HodToolbar extends MobxLitElement { 7 | constructor() { 8 | super(); 9 | this.store = store 10 | } 11 | 12 | connectedCallback() { 13 | super.connectedCallback() 14 | } 15 | 16 | render() { 17 | return html` 18 | 53 |