Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new auth with magic.link #61

Merged
merged 22 commits into from
Apr 26, 2021
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
16 changes: 16 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: API
on:
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@master
- name: Publish app
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
workingDirectory: 'site'
114 changes: 57 additions & 57 deletions .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,60 +67,60 @@ jobs:
- name: Coverage
run: yarn --cwd client coverage

publish:
name: Publish client
needs:
- check
- test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
- name: Cache node_modules
id: cache-modules
uses: actions/cache@v1
with:
path: node_modules
key: 12.x-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
- name: Install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install
- name: Build client
run: yarn --cwd client build

- name: Publish client
uses: mikeal/merge-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
SRC_PACKAGE_DIR: client
DEPLOY_DIR: client

docs:
name: Generate documentation
needs:
- publish
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2

- name: Cache node_modules
id: cache-modules
uses: actions/cache@v1
with:
path: node_modules
key: 12.x-${{ runner.OS }}-build-${{ hashFiles('package.json') }}

- name: Install
run: yarn install

- name: Generate
run: yarn build:client:docs

- name: Commit
uses: EndBug/add-and-commit@v7
with:
author_name: documentation-generator
add: docs/client
message: 'chore: generate client docs'
# publish:
# name: Publish client
# needs:
# - check
# - test
# runs-on: ubuntu-latest
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# steps:
# - uses: actions/checkout@v2
# - name: Cache node_modules
# id: cache-modules
# uses: actions/cache@v1
# with:
# path: node_modules
# key: 12.x-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
# - name: Install
# if: steps.cache-modules.outputs.cache-hit != 'true'
# run: yarn install
# - name: Build client
# run: yarn --cwd client build

# - name: Publish client
# uses: mikeal/merge-release@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
# SRC_PACKAGE_DIR: client
# DEPLOY_DIR: client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create an issue to re-instate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#66


# docs:
# name: Generate documentation
# needs:
# - publish
# runs-on: ubuntu-latest
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# steps:
# - uses: actions/checkout@v2

# - name: Cache node_modules
# id: cache-modules
# uses: actions/cache@v1
# with:
# path: node_modules
# key: 12.x-${{ runner.OS }}-build-${{ hashFiles('package.json') }}

# - name: Install
# run: yarn install

# - name: Generate
# run: yarn build:client:docs

# - name: Commit
# uses: EndBug/add-and-commit@v7
# with:
# author_name: documentation-generator
# add: docs/client
# message: 'chore: generate client docs'
20 changes: 20 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Manual Deploy
on:
workflow_dispatch:
inputs:
environment:
description: 'Choose an environment to deploy to: <staging|production>'
required: true
default: ''
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@master
- name: Publish app
uses: cloudflare/wrangler-action@1.3.0
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
workingDirectory: 'site'
environment: ${{ github.event.inputs.environment }}
21 changes: 21 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Website
on:
push:
branches:
- main
paths:
- 'website/**'
pull_request:
branches:
- main
paths:
- 'website/**'

jobs:
check:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: yarn install
- run: yarn test:website
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ worker
yarn.lock
package-lock.json
site/public
.cluster
93 changes: 55 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,40 @@ Free decentralized storage and bandwidth for NFTs on IPFS and Filecoin BETA.

- [JS client library](#js-client-library)
- [HTTP API](#http-api)
- [`site` Setup](#site-setup)
- [Cloudflare Workers CLI](#cloudflare-workers-cli)
- [Auth0 account](#auth0-account)
- [Cloudflare Workers initial setup:](#cloudflare-workers-initial-setup)
- [Development Setup](#development-setup)
- [Production Setup `[env.production]`](#production-setup-envproduction)
- [`site` Usage](#site-usage)
- [Local development](#local-development)
- [Deploy](#deploy)

## JS client library
- [Development](#development)
- [`site` Setup](#site-setup)
- [Cloudflare Workers CLI](#cloudflare-workers-cli)
- [Magic.link account](#magiclink-account)
- [IPFS Cluster](#ipfs-cluster)
- [Cloudflare Workers initial setup:](#cloudflare-workers-initial-setup)
- [Development Setup](#development-setup)
- [Production Setup `[env.production]`](#production-setup-envproduction)
- [`site` Usage](#site-usage)
- [Local development](#local-development)
- [Deploy](#deploy)
- [`website` Setup](#website-setup)
- [`website` Usage](#website-usage)
- [Local development](#local-development-1)
- [Contributing](#contributing)
- [License](#license)

# JS client library

Check out the [JS client library documentation](https://github.com/ipfs-shipyard/nft.storage/tree/main/client).

## HTTP API
# HTTP API

[Documentation for the HTTP API](https://nft.storage/api-docs).
Check out the [HTTP API documentation](https://nft.storage/api-docs).

# Development

```bash
# install all dependencies in the mono-repo
yarn

# setup git hooks
npx simple-git-hooks
```

## `site` Setup

Expand All @@ -36,16 +53,9 @@ wrangler login
# when using personal accounts you may need to manually change the `account_id` inside `wrangler.toml`
```

### Auth0 account

Go to [auth0.com](https://auth0.com) and create an account. Create two "REGULAR WEB APPLICATION" applications one for dev and another for production. In the "settings" of each application you will find the secrets needed to complete the initial setup.
### Magic.link account

Go to "settings" for your dev application and add the following URLs:

- "Allowed Callback URLs": `http://127.0.0.1:8787/auth`
- "Allowed Web Origins": `http://127.0.0.1:8787`

Do the same for your production application, with the appropriate URLs.
Go to [magic.link](https://magic.link) and create an account. Create two applications one for dev and another for production. In the "settings" of each application you will find the secrets needed to complete the initial setup.

### IPFS Cluster

Expand Down Expand Up @@ -100,7 +110,7 @@ account_id = "CF_ACCOUNT"
workers_dev = true
route = ""
zone_id = ""
vars = { AUTH0_CALLBACK_URL = "http://127.0.0.1:8787/auth", DEBUG = true, CLUSTER_API_URL = "", CLUSTER_IPFS_PROXY_API_URL = "" }
vars = { ENV = "dev", DEBUG = "*", CLUSTER_API_URL = "", CLUSTER_IPFS_PROXY_API_URL = "" }
kv_namespaces = []
```

Expand All @@ -113,10 +123,6 @@ yarn install
wrangler kv:namespace create USERS --preview --env USER
# cli output something like: `{ binding = "USERS", preview_id = "7e441603d1bc4d5a87f6cecb959018e4" }`
# but you need to put `{ binding = "USERS", preview_id = "7e441603d1bc4d5a87f6cecb959018e4", id = "7e441603d1bc4d5a87f6cecb959018e4" }` inside the `kv_namespaces`.
wrangler kv:namespace create SESSION --preview --env USER
# same as above
wrangler kv:namespace create CSRF --preview --env USER
# same as above
wrangler kv:namespace create NFTS --preview --env USER
# same as above
wrangler kv:namespace create DEALS --preview --env USER
Expand All @@ -129,9 +135,7 @@ Go to `/site/src/constants.js` _uncomment_ the first line and run `wrangler publ

```bash
# dev and preview secrets
wrangler secret put AUTH0_DOMAIN --env USER # Get from auth0 account
wrangler secret put AUTH0_CLIENT_ID --env USER # Get from auth0 account
wrangler secret put AUTH0_CLIENT_SECRET --env USER # Get from auth0 account
wrangler secret put MAGIC_SECRET_KEY --env USER # Get from magic.link account
wrangler secret put SALT --env USER # open `https://csprng.xyz/v1/api` in the browser and use the value of `Data`
wrangler secret put PINATA_JWT --env USER # Get from Pinata
```
Expand All @@ -144,19 +148,13 @@ Go to `/site/src/constants.js` _comment_ the first line and run `wrangler publis
# production KVs
wrangler kv:namespace create USERS --env production
# Follow the instructions from the cli output
wrangler kv:namespace create SESSION --env production
# Follow the instructions from the cli output
wrangler kv:namespace create CSRF --env production
# Follow the instructions from the cli output
wrangler kv:namespace create NFTS --env production
# Follow the instructions from the cli output
wrangler kv:namespace create DEALS --env production
# Follow the instructions from the cli output
wrangler kv:namespace create METRICS --env production
# Follow the instructions from the cli output
wrangler secret put AUTH0_DOMAIN --env production # Get from auth0 account
wrangler secret put AUTH0_CLIENT_ID --env production # Get from auth0 account
wrangler secret put AUTH0_CLIENT_SECRET --env production # Get from auth0 account
wrangler secret put MAGIC_SECRET_KEY --env production # Get from magic.link account
wrangler secret put SALT --env production # open `https://csprng.xyz/v1/api` in the browser and use the value of `Data`
wrangler secret put PINATA_JWT --env production # Get from Pinata
wrangler secret put CLUSTER_BASIC_AUTH_TOKEN --env production # Get from nft.storage vault in 1password
Expand All @@ -176,8 +174,27 @@ yarn dev

### Deploy

Deployment should be done with github actions but in the case you need to manually test something you can run `yarn deploy` inside the `site` folder.

## `website` Setup

Inside the `website` folder create a file called `.env.local` with the following content.

```ini
NEXT_PUBLIC_API=http://127.0.0.1:8787
NEXT_PUBLIC_MAGIC=<magic test mode publishable key>
```

Production vars should set in Cloudflare Pages settings.

## `website` Usage

### Local development

```bash
yarn deploy
cd site
yarn install
yarn dev
```

## Contributing
Expand Down
8 changes: 4 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nft.storage",
"version": "0.0.0-dev",
"version": "0.4.1",
"description": "nft.storage client",
"license": "(Apache-2.0 AND MIT)",
"type": "module",
Expand Down Expand Up @@ -41,11 +41,11 @@
},
"devDependencies": {
"@ssttevee/multipart-parser": "0.1.8",
"@types/mocha": "8.2.1",
"@types/mocha": "8.2.2",
"hundreds": "0.0.9",
"ipfs-unixfs-importer": "6.0.1",
"ipld": "0.29.0",
"ipld-dag-pb": "0.22.0",
"ipld-dag-pb": "0.22.2",
"ipld-in-memory": "8.0.0",
"mocha": "8.3.2",
"multicodec": "3.0.1",
Expand All @@ -55,7 +55,7 @@
"playwright-test": "2.1.0",
"rollup": "2.22.1",
"rollup-plugin-multi-input": "1.1.1",
"typedoc": "0.20.32",
"typedoc": "0.20.36",
"uvu": "0.5.1"
},
"homepage": "https://github.com/ipfs-shipyard/nft.storage/tree/main/client",
Expand Down
Loading