{"id":25278228,"url":"https://github.com/1b4dev/bear1x","last_synced_at":"2025-08-25T01:34:09.082Z","repository":{"id":277190970,"uuid":"931632622","full_name":"1b4dev/bear1x","owner":"1b4dev","description":"Store and access your Bearer token in cookies with your PHP backend","archived":false,"fork":false,"pushed_at":"2025-03-24T15:23:40.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-11T04:08:02.903Z","etag":null,"topics":["backend","bearer-tokens","bff","cookie","middleware","php","php8","saas"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/1b4dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["1b4dev"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2025-02-12T15:52:06.000Z","updated_at":"2025-03-24T15:23:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"1b86f305-b1a4-4b46-8ef7-96333ae1436e","html_url":"https://github.com/1b4dev/bear1x","commit_stats":null,"previous_names":["1b4dev/bear1x"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/1b4dev/bear1x","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1b4dev%2Fbear1x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1b4dev%2Fbear1x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1b4dev%2Fbear1x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1b4dev%2Fbear1x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1b4dev","download_url":"https://codeload.github.com/1b4dev/bear1x/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1b4dev%2Fbear1x/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271991262,"owners_count":24854740,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["backend","bearer-tokens","bff","cookie","middleware","php","php8","saas"],"created_at":"2025-02-12T17:23:07.095Z","updated_at":"2025-08-25T01:34:09.076Z","avatar_url":"https://github.com/1b4dev.png","language":"PHP","funding_links":["https://github.com/sponsors/1b4dev"],"categories":[],"sub_categories":[],"readme":"# Bear1x\nBear1x is a lightweight Backend for Frontend (BFF) middleware designed for PHP backends to seamlessly create and access Bearer tokens as cookies. Acting as a proxy, Bear1x extracts tokens from cookies, forwards them to your backend, and delivers the response back to the frontend—all without requiring modifications to your existing backend.\n\nBear1x features:\n- **Lightweight:** Minimal overhead for optimal performance.\n- **Non-Invasive:** No need to edit or refactor your backend.\n- **OOP PHP:** Built using modern Object-Oriented PHP principles.\n- **cUrl-Free:** Eliminates cUrl-related issues for smoother operations.\n\n## How It Works\n\nBear1x intercepts requests from the frontend.\nExtracts the Bearer token from the cookie.\nProxies the token to your backend.\nReturns the backend response to the frontend.\n\n## Usage\n\nBear1x can be integrated into your project in two ways: **Direct Integration** or **Middleware Mode**. Choose the method that best suits your architecture.\n\n---\n\n### **1. Direct Integration**\n\nThis method involves placing Bear1x at the root of your API and adjusting the `BFF.php` file to match your backend configuration.\n\n#### Steps:\n1. **Place Bear1x at the Root**:  \n   Move the Bear1x files to the root of your API directory (e.g., where your `index.php` or routing file is located).\n\n2. **Configure `BFF.php`**:  \n   Open `BFF.php` and adjust the necessary fields, such as:\n   - **API Endpoint**: Set the root API endpoint for your backend.\n   - **Token Handling**: Configure how Bearer tokens are extracted and validated.\n\n3. **Update Routing**:  \n   If your application uses index-based routing (e.g., `index.php`), add Bear1x's routing logic to handle incoming requests. For example:\n   ```php\n   // index.php\n    else if (isset($uriSegments[0]) \u0026\u0026 $uriSegments[0] === 'bff') {\n    array_shift($uriSegments);\n        $bff = new BFFMiddleware();\n        try {\n            $bff-\u003ehandleRequest($uriSegments);\n        } catch (Exception $e) {\n            http_response_code(500);\n            echo json_encode(['error' =\u003e 'Internal Server Error: ' . $e-\u003egetMessage()]);\n        }\n    } else {\n        http_response_code(404);\n        echo json_encode(['error' =\u003e 'Not Found']);\n    }\n    ```\n4. **Frontend Requests**:  \n   Update your frontend to prefix API calls with `/bff/`. For example:\n   - Original: `/api/login`  \n   - Updated: `/bff/api/login`\n\n   This ensures that all requests are routed through Bear1x.\n\n### **2. Middleware Mode**\n\nIn this mode, Bear1x acts as a standalone middleware layer. This is ideal for developers who want to keep Bear1x separate from their backend.\n\n#### Steps:\n1. **Adjust `BFF.php` Configuration**:  \n   Open `BFF.php` and set the `host` field in the constructor to point to your backend URL. For example:\n   ```php\n   public function __construct() {\n       $this-\u003ehost = 'https://your-backend-url.com';\n   }\n   ```\n2. **Deploy Bear1x as Middleware**:  \n   Place Bear1x in a separate directory or server, ensuring it can act as a proxy between your frontend and backend.\n\n3. **Frontend Requests**:  \n   Similar to Direct Integration, prefix your API calls with `/bff/`. For example:\n   - Original: `/api/login`  \n   - Updated: `/bff/api/login`\n\n   All requests will now be routed through Bear1x, which will forward them to your backend.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1b4dev%2Fbear1x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1b4dev%2Fbear1x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1b4dev%2Fbear1x/lists"}