{"id":13806504,"url":"https://github.com/sacsand/gofiber-firebaseauth","last_synced_at":"2025-05-13T22:30:23.235Z","repository":{"id":43746513,"uuid":"320023712","full_name":"sacsand/gofiber-firebaseauth","owner":"sacsand","description":"Firebase Authentication Middleware for Go Fiber framework.","archived":false,"fork":false,"pushed_at":"2022-02-20T12:21:29.000Z","size":123,"stargazers_count":23,"open_issues_count":2,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-04T01:06:33.638Z","etag":null,"topics":["authentication","authentication-middleware","fiber","fiber-framework","firebase","firebase-authentication","firebase-console","go","gofiber","ignore-urls","middleware"],"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/sacsand.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-09T17:02:25.000Z","updated_at":"2024-05-27T22:32:19.000Z","dependencies_parsed_at":"2022-07-20T19:02:10.966Z","dependency_job_id":null,"html_url":"https://github.com/sacsand/gofiber-firebaseauth","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacsand%2Fgofiber-firebaseauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacsand%2Fgofiber-firebaseauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacsand%2Fgofiber-firebaseauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sacsand%2Fgofiber-firebaseauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sacsand","download_url":"https://codeload.github.com/sacsand/gofiber-firebaseauth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225130378,"owners_count":17425506,"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":["authentication","authentication-middleware","fiber","fiber-framework","firebase","firebase-authentication","firebase-console","go","gofiber","ignore-urls","middleware"],"created_at":"2024-08-04T01:01:12.555Z","updated_at":"2024-11-18T22:32:15.826Z","avatar_url":"https://github.com/sacsand.png","language":"Go","funding_links":[],"categories":["⚙️ Middlewares"],"sub_categories":["🌱 Third Party"],"readme":"# Go Fiber Firebase Auth Middleware \n[![CircleCI](https://circleci.com/gh/sacsand/gofiber-firebaseauth.svg?style=shield)](https://circleci.com/gh/sacsand/gofiber-firebaseauth)\n\nAuthenticate your endpoints with [Firebase Authentication ](https://github.com/LeafyCode/express-firebase-auth/).\n\ngofiber-firebaseauth is inspired by npm package [express-firebase-auth](https://github.com/LeafyCode/express-firebase-auth/) .\n#### Note1\n This package is designed to work with [Go Fiber Framework](https://github.com/gofiber/fiber) (Express inspired go framework)\n# Features\n  - Authenticate the user using Firebase before running the function.\n  - Ability to skip authentication on public API endpoints.\n  \n# Installing / Getting started\n\nIn your gofiber app\n```sh\n$ go get -u github.com/gofiber/fiber/v2\n$ go get github.com/sacsand/gofiber-firebaseauth\n```\n\n# Configure \nIn your app import the middleware\n\n```go\nimport (\n  \"github.com/gofiber/fiber/v2\"\n  \"github.com/sacsand/gofiber-firebaseauth\"\n)\n```\nProvide a minimal config\n```go\n    // Provide a minimal config\n    app.Use(gofiberfirebaseauth.New(Config{\n    \tFirebaseApp: FirebaseApp,\n    }))\n```\nOr extend your config for customization\n```go\n\n    // Or extend your config for customization\n\tapp.Use(gofiberfirebaseauth.New(Config{\n\t\n\t// New firebase authentication object\n\t// Mandatory. Default: nil\n\tFirebaseApp:  FirebaseApp\n\n\t// Ignore urls array - Format = \"{METHOD} follwed by :: then /{route}\"\n\t// Optional. Default: nil\n\tIgnoreUrls : []string{\"GET::/login\",\"POST::/create-user\"}\n\n\t// Skip Email Check.\n\t// Optional. Default: nil\n\tCheckEmailVerified : true\n\n\t// Ignore email verification for these routes\n\t// Optional. Default: nil\n\tCheckEmailVerifiedIgnoredUrls :  []string{\"GET::/login\",\"POST::/create-user\"}\n\n\t// Authorizer defines a function which authenticates the Authorization token and returns \n\t// the authenticated token\n\t// Optional. Default: nil\n\tAuthorizer: func(IDToken string, CurrentURL string) (*auth.Token, error){\n        // create your own authentication here \n\t// this returns the firebase id token\n\t\treturn token, nil\n\t},\n\t// Context key to store user information from the token into context.\n\t// Optional. Default: \"user\".\n\tContextKey : \"authUser\"\n    }))\n```\nUse user in your fiber app\n```go\nfunc Handler(ctx *fiber.Ctx) error {\n\t// Get user stored in context\n\t// Default: user\n\tcurrentUser := ctx.Locals(\"user\").(gofiberfirebaseauth.User)\n\tfmt.Println(currentUser)\n\tfmt.Println(currentUser.Email)\n\n}\n```\n\nAll available configuration\n\n| Option                          |                                                                                                                                                                                            Value | Config type                                          |\n| ------------------------------- | -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------- |\n| `FirebaseApp`                   |                                                                       ([**Note1**](#note2)) An initialized firebase app. [Refer to Firebase setup](https://firebase.google.com/docs/admin/setup) | FirebaseApp *firebase.App                            |\n| `IgnoredUrls`                   |                                                                                                    ([**Note1**](#note3))(*Optional*) An array of URLs where you need to skip the authentication. | IgnoreUrls []string                                  |\n| `CheckEmailVerified`            |                                                                                   (*Optional*) (Default: **false**) If set to **true**, only users with a verified email will be allowed access. | CheckEmailVerified bool                              |\n| `CheckEmailVerifiedIgnoredUrls` |                                                                                                                   (*Optional*) An array of URLs where you need to skip the email verified check. | CheckEmailVerifiedIgnoredUrls []string               |\n| `Authorizer`                    | (*Optional*), Default: nil , Authorizer defines a function which authenticates the Authorization token and returns the authenticated token. Use this if you want to override token authorization | Authorizer func(string, string) (*auth.Token, error) |\n| `ContextKey`                    |                                                                                               (*Optional*), Default: \"user\" , Context key to store user information from the token into context. | ContextKey string                                    |\n| `SuccessHandler`                |                                                                                                (*Optional*), Default:nil, SuccessHandler defines a function which is executed for a valid token. | SuccessHandler fiber.Handler                         |\n| `ErrorHandler`                  |                                                                                                (*Optional*), Default:nil, ErrorHandler defines a function which is executed for a invalid token. | ErrorHandler fiber.ErrorHandler                      |\n                            \n\n\n #### Note2\nYou **must** provide already initialized `FirebaseApp` app.\nYou cannot initialize two firebase apps.\n\n #### Note3\n  Ignore url accept array of string. URl format should follow below format\\\n  `{METHOD}::/{url}`\\\n  Example: \\\n  GET::/login\\\n  POST::/login\n  \n  IgnoreUrl only supports routes without params or query . (PR are welcome).To ignore urls with param or query,  declare the routes before the middleware declaration. \n\n## Developing , TESTING and environment setup\n\n### Prerequisites\n- Go 1.14 +\n- Configured Firebase app and Google Service Account Credential (JSON containing admin credentials). Refer to [Firebase setup](https://firebase.google.com/docs/admin/setup) \n- Web API Key\n- Sample user email and password from firebase. You can manually create a user from the firebase console.\n\nYou can get all the configurations from Firebase Console.\n \n### Setting up Development Environment for testing\n\nClone the repo and set your firebase credentials in your .env file\n\n```\n\nSERVICE_ACCOUNT_JSON = \"path to service account credential json\"\nWEB_API_KEY = \nTEST_USER_EMAIL = \"\"\nTEST_USER_PASSWORD = \"\"\n  \t\n```\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [link to tags on this repository](/releases).\n\n## Style guide\n\n [Uber](https://github.com/uber-go/guide/blob/master/style.md ) style guide\n\n\n## License\n\n[MIT licensed](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacsand%2Fgofiber-firebaseauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsacsand%2Fgofiber-firebaseauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsacsand%2Fgofiber-firebaseauth/lists"}