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

Introduce app ID management mechanism #270

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ PORT=5000
ROLLBAR_TOKEN=YOUR_ROLLBAR_TOKEN
ROLLBAR_ENV=localhost

# ===================
# Client app settings
# ===================
# HTTP header to identify the client apps
HTTP_HEADER_APP_ID=x-app-id
HTTP_HEADER_APP_SECRET=x-app-secret

# App ID management file.
APP_SETTINGS_PATH=app-settings.sample.yaml

# Official web clients. Use comma to separate all site origins.
RUMORS_SITE_CORS_ORIGIN=http://localhost:3000

Expand All @@ -27,9 +33,12 @@ RUMORS_SITE_REDIRECT_ORIGIN=http://localhost:3000
# Official LINE clients
RUMORS_LINE_BOT_CORS_ORIGIN=http://localhost:5001

# official line bot client
# official line bot client.
# Deprecated; put settings in app settings instead
RUMORS_LINE_BOT_SECRET=secret

# ===================

# Cookie related setup, expire time default to 86400 * 1000 * 14 milliseconds (14 days)
COOKIE_MAXAGE=1209600000
COOKIE_SECRETS=foo,bar
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ For development, copy `.env.sample` to `.env` and make necessary changes.

For production via [rumors-deploy](http://github.com/cofacts/rumors-deploy), do setups in `docker-compose.yml`.

### App settings

The "client apps" of this API includes:
- [cofacts/rumors-site](https://github.com/cofacts/rumors-site), the Cofacts web app for visitors & editors
- [cofacts/rumors-line-bot](https://github.com/cofacts/rumors-line-bot), the Cofacts LINE chatbot
- [cofacts/rumors-ai-bert](https://github.com/cofacts/rumors-ai-bert), the BERT classifier for article categories
- Other third-party applications

Except rumors-site, API will identify each app using the shared secret sent via the HTTP header set in `HTTP_HEADER_APP_SECRET` (`x-app-secret` by default).

The mapping of app secrets to the `appId`s used in the database is documented in the YAML file in `APP_SETTINGS_PATH`. See `app-settings.sample.yaml` for example.

## Development

### Prerequisite
Expand Down
7 changes: 7 additions & 0 deletions app-settings.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- # secret sent in HTTP header.
# Can have multiple secrets, but should not duplicate with other apps.
headerAppSecrets: ["secret"]

# The appId that will be written to each entry (articles, replies, ...) in the database
dbAppId: RUMORS_LINE_BOT
Loading