mirror of
https://github.com/ssep1ol/overleaf-registration-be.git
synced 2026-07-21 12:30:21 +00:00
docs: add comprehensive README and align env template key
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
ALLOWED_DOMAINS=xyz.com,abc.de,fgh.il
|
||||
CAPTCHA_SERVER_KEY=
|
||||
TURNSTILE_SECRET_KEY=
|
||||
OL_INSTANCE=
|
||||
OL_ADMIN_EMAIL=
|
||||
OL_ADMIN_PASSWORD=
|
||||
|
||||
211
README.md
211
README.md
@@ -1,92 +1,191 @@
|
||||
# overleaf-registration-be
|
||||
|
||||
Backend service for controlled Overleaf account registration.
|
||||
|
||||
This service exposes a single endpoint used by a frontend signup form. It validates:
|
||||
|
||||
## Getting started
|
||||
- email domain allowlist
|
||||
- Cloudflare Turnstile token
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
and then performs admin-authenticated user creation on an Overleaf instance.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
## Features
|
||||
|
||||
## Add your files
|
||||
- HTTP API for signup flow
|
||||
- Domain-based admission control
|
||||
- Turnstile CAPTCHA verification
|
||||
- Admin session login against Overleaf
|
||||
- Overleaf user registration through admin endpoint
|
||||
- Configurable runtime via environment variables
|
||||
- Docker image support
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
## How It Works
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin http://git.devops.lnxc.it/uni-projects/overleaf-registration-be.git
|
||||
git branch -M master
|
||||
git push -uf origin master
|
||||
1. Client sends email and CAPTCHA token to `/signup`.
|
||||
2. Service verifies email domain against `ALLOWED_DOMAINS`.
|
||||
3. Service verifies token via Cloudflare Turnstile verify API.
|
||||
4. Service logs in to Overleaf as admin.
|
||||
5. Service posts user email to Overleaf admin registration endpoint.
|
||||
6. Service returns success JSON message.
|
||||
|
||||
## Tech Stack
|
||||
|
||||
- Go (standard library net/http)
|
||||
- Cloudflare Turnstile verification API
|
||||
- goquery for CSRF token extraction
|
||||
- rs/cors for CORS middleware
|
||||
- godotenv for local env loading
|
||||
|
||||
## Project Structure
|
||||
|
||||
- `main.go`: server bootstrap, env validation, route setup
|
||||
- `handlers.go`: request handling and signup flow orchestration
|
||||
- `overleaf.go`: Overleaf client logic (CSRF, login, registration)
|
||||
- `recaptcha.go`: Turnstile token verification
|
||||
- `.env.example`: environment variable template
|
||||
- `Dockerfile`: container image build instructions
|
||||
|
||||
## API
|
||||
|
||||
### POST /signup
|
||||
|
||||
Registers a user on Overleaf after domain and CAPTCHA checks.
|
||||
|
||||
Request body:
|
||||
|
||||
```json
|
||||
{
|
||||
"email": "student@example.edu",
|
||||
"captcha": "turnstile_token_here"
|
||||
}
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
Success response (`200`):
|
||||
|
||||
- [ ] [Set up project integrations](http://gitlab.runpolito.it/uni-projects/overleaf-registration-be/-/settings/integrations)
|
||||
```json
|
||||
{
|
||||
"message": "User registered successfully. Please check your email to set your password."
|
||||
}
|
||||
```
|
||||
|
||||
## Collaborate with your team
|
||||
Typical error responses:
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
- `400`: invalid JSON or disallowed email domain
|
||||
- `401`: invalid CAPTCHA token
|
||||
- `500`: missing config, Turnstile failure, Overleaf login/registration failure
|
||||
|
||||
## Test and Deploy
|
||||
### Example curl
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/signup \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"email": "student@example.edu",
|
||||
"captcha": "TOKEN_FROM_TURNSTILE"
|
||||
}'
|
||||
```
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
## Configuration
|
||||
|
||||
***
|
||||
Set environment variables via system env or `.env` file.
|
||||
|
||||
# Editing this README
|
||||
Required:
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
- `ALLOWED_DOMAINS`: comma-separated domain allowlist
|
||||
- example: `example.edu,department.example.edu`
|
||||
- `TURNSTILE_SECRET_KEY`: Cloudflare Turnstile secret key
|
||||
- `OL_INSTANCE`: Overleaf base URL
|
||||
- example: `https://overleaf.yourdomain.tld`
|
||||
- `OL_ADMIN_EMAIL`: Overleaf admin email
|
||||
- `OL_ADMIN_PASSWORD`: Overleaf admin password
|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
Optional:
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
- `PORT`: server port (default: `3000`)
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
Important note:
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
- The code uses `TURNSTILE_SECRET_KEY`.
|
||||
- `.env.example` currently includes `CAPTCHA_SERVER_KEY`; this should be aligned before production usage.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
## Run Locally
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
### 1) Create env file
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
Edit `.env` and set required variables.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
### 2) Install dependencies and run
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
```bash
|
||||
go mod init main
|
||||
go mod tidy
|
||||
go run .
|
||||
```
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
Service starts on `http://localhost:3000` unless `PORT` is set.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
## Run With Docker
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
Build image:
|
||||
|
||||
```bash
|
||||
docker build -t overleaf-registration-be .
|
||||
```
|
||||
|
||||
Run container:
|
||||
|
||||
```bash
|
||||
docker run --rm -p 3000:3000 --env-file .env overleaf-registration-be
|
||||
```
|
||||
|
||||
## Security Notes
|
||||
|
||||
- Do not commit real credentials or `.env`.
|
||||
- Restrict CORS origins in production. Current code allows all origins (`*`).
|
||||
- Use HTTPS between client and backend.
|
||||
- Use least-privilege admin account where possible.
|
||||
- Rotate admin and Turnstile secrets regularly.
|
||||
- Avoid logging sensitive token values in production.
|
||||
|
||||
## Operational Notes
|
||||
|
||||
- Startup fails fast when required env vars are missing.
|
||||
- Overleaf integration relies on HTML CSRF token extraction from:
|
||||
- `/login`
|
||||
- `/admin/register`
|
||||
- If Overleaf page markup changes, CSRF extraction may need update.
|
||||
|
||||
## CI
|
||||
|
||||
GitLab CI currently includes SAST template in `.gitlab-ci.yml`.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- `environment variable ... is not set`
|
||||
- Ensure required variables are present in `.env` or runtime environment.
|
||||
|
||||
- `Invalid CAPTCHA`
|
||||
- Check Turnstile site/secret key pairing and token freshness.
|
||||
|
||||
- `Admin login failed`
|
||||
- Verify `OL_INSTANCE`, admin email/password, and Overleaf reachability.
|
||||
|
||||
- `CSRF token not found`
|
||||
- Overleaf login/admin page markup may have changed.
|
||||
|
||||
## Suggested Improvements
|
||||
|
||||
- Add structured logging and log levels
|
||||
- Replace broad CORS policy with strict allowed origins
|
||||
- Add health endpoint (`/healthz`)
|
||||
- Add unit/integration tests
|
||||
- Add explicit request timeouts and retry strategy
|
||||
- Create and commit a proper `go.mod` / `go.sum`
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
Add a project license file if this repository is distributed externally.
|
||||
|
||||
Reference in New Issue
Block a user