{"id":26820398,"url":"https://github.com/zvdy/go-jwe","last_synced_at":"2025-03-30T06:32:10.572Z","repository":{"id":256068872,"uuid":"852316312","full_name":"zvdy/go-JWE","owner":"zvdy","description":"Service for generating and verifying JSON Web Encryption (JWE) and JSON Web Tokens (JWT) using RSA encryption. The service is built using Go, Gin, and MongoDB.","archived":false,"fork":false,"pushed_at":"2024-09-23T14:15:05.000Z","size":776,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-13T09:17:29.605Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zvdy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-04T15:44:57.000Z","updated_at":"2024-10-13T19:18:26.000Z","dependencies_parsed_at":"2024-09-08T20:46:21.344Z","dependency_job_id":"92f128e9-0d79-43bc-b391-d4d049d9a4da","html_url":"https://github.com/zvdy/go-JWE","commit_stats":null,"previous_names":["zvdy/go-jwe"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fgo-JWE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fgo-JWE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fgo-JWE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fgo-JWE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zvdy","download_url":"https://codeload.github.com/zvdy/go-JWE/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246285645,"owners_count":20752947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-30T06:31:50.882Z","updated_at":"2025-03-30T06:32:10.564Z","avatar_url":"https://github.com/zvdy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JWE JWT Service\n![Golang](https://img.shields.io/badge/Go-00ADD8?) ![MongoDB](https://img.shields.io/badge/MongoDB-47A248?style=flat\u0026logo=mongodb\u0026logoColor=white)\n\nThis project provides a service for generating and verifying JSON Web Encryption (JWE) and JSON Web Tokens (JWT) using RSA encryption. The service is built using Go, Gin, and MongoDB.\n\n## Features\n\n- Generate JWE from JWT with custom claims.\n- Verify and decrypt JWE to retrieve the original JWT.\n- Store responses in MongoDB.\n\n## Prerequisites\n\n- Go 1.23 or later\n- MongoDB instance\n- Environment variable `MONGO_URI` set to your MongoDB connection string.\n\n## Installation\n\n1. **Clone the repository:**\n\n   ```sh\n   git clone https://github.com/zvdy/go-JWE.git\n   cd go-JWE\n   ```\n\n2. **Set up environment variables:**\n\n   Ensure you have the `MONGO_URI` environment variable set to your MongoDB connection string.\n\n   ```sh\n   export MONGO_URI=\"your_mongodb_connection_string\"\n   ```\n\n\u003e I suggest using atlas, but you can deploy locally, if you decide to use Atlas, remember to whitelist 0.0.0.0 if you want your github action pipeline to run properly.\n\n3. **Install dependencies:**\n\n   ```sh\n   go mod tidy\n   ```\n\n4. **Run the service:**\n\n   ```sh\n   go run main.go\n   ```\n\n   The server will start at `http://localhost:8080`\n\n\n# Docker-Compose Deployment\n\nThe `docker-compose.yml` file is used to define and run multi-container Docker applications. In this project, it is used to set up the necessary services, including the database (if you want to run it locally).\n\n## Steps to Deploy\n\n1. **Install Docker and Docker-Compose**: Ensure Docker and Docker-Compose are installed on your machine.\n\n2. **Configuration**: The `docker-compose.yml` file includes the configuration for the services required by the application. This typically includes the application service and a database service.\n\n3. **Running the Services**: Use the following command to start the services defined in the `docker-compose.yml` file:\n   ```sh\n   docker-compose up\n\n\n## API Endpoints\n\n### Generate JWE\n\n- **URL:** `/generate-jwe`\n- **Method:** `POST`\n- **Headers:**\n  - `X-Claims`: Base64 encoded JSON string of claims.\n- **Response:**\n  - `200 OK`: Returns the generated JWE and keys.\n  - `400 Bad Request`: If the `X-Claims` header is missing or invalid.\n  - `500 Internal Server Error`: If there is an error during processing.\n\n### Verify JWE\n\n- **URL:** `/verify-jwe`\n- **Method:** `POST`\n- **Headers:**\n  - `X-JWE`: The JWE string to be verified.\n- **Response:**\n  - `200 OK`: Returns the decrypted JWT.\n  - `400 Bad Request`: If the `X-JWE` header is missing.\n  - `500 Internal Server Error`: If there is an error during processing.\n\n## Example Usage\n\n### Generate JWE\n\n```sh\ncurl -X POST http://localhost:8080/generate-jwe \\\n  -H \"X-Claims: eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ==\"\n```\n\n### Verify JWE\n\n```sh\ncurl -X POST http://localhost:8080/verify-jwe \\\n  -H \"X-JWE: your_jwe_string_here\"\n```\n\n### MongoDB Atlas view \n\n![img](img/atlas.png)\n\n\n### Explanation of [`cicd.yml`]\n\nThe [`cicd.yml`](.github/workflows/cicd.yml) file defines a CI/CD pipeline for the project. It includes two main jobs: `build` and `create-pull-request`.\n\n1. **Build and Test Job**:\n   - **Job Name:** [`build`]\n   - **Runs On:** `ubuntu-latest`\n   - **Steps**:\n     - **Checkout Repository:** Uses the `actions/checkout@v4` action to check out the repository.\n     - **Set up Go:** Uses the `actions/setup-go@v4` action to set up Go with version [`1.23`].\n     - **Build:** Runs the `go build -v ./...` command to build the Go project.\n     - **Test:** Runs the `go test -v ./...` command to test the Go project.\n\n2. **Create Pull Request Job**:\n   - **Job Name:** `create-pull-request`\n   - **Needs:** [`build`] (depends on the [`build`] job)\n   - **Runs On:** `ubuntu-latest`\n   - **Condition:** Runs only if the branch is [`development`].\n   - **Steps**:\n     - **Checkout Repository:** Uses the `actions/checkout@v4` action to check out the repository.\n     - **Create Pull Request:** Uses the `peter-evans/create-pull-request@v4` action to create a pull request from [`development`] to [`main`].\n\nThis CI/CD pipeline ensures that the code is continuously integrated and deployed, making it easier to manage and deploy changes to the project.\n\n## Project Structure\n\n- `main.go`: Main application file containing the service logic.\n- `go.mod`: Go module file for dependency management.\n- `claims/claims.go`: Script to automatically base64 encode claims.\n- `.github/workflows/cicd.yml`: GitHub Action workflow.\n- `docker-compose.yml`: Adds the database logic.\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.\n\n## Acknowledgements\n\n- [Gin](https://github.com/gin-gonic/gin) - HTTP web framework for Go.\n- [go-jose](https://github.com/square/go-jose) - An implementation of JOSE standards (JWE, JWS, JWT) in Go.\n- [golang-jwt](https://github.com/golang-jwt/jwt) - A Go implementation of JSON Web Tokens.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzvdy%2Fgo-jwe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzvdy%2Fgo-jwe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzvdy%2Fgo-jwe/lists"}