GFA is a package of gin middlewares to handle authentification using Google Firebase.
First, you need to initialize your firebase app.
Once you have your app
variable, create a new GFA config object:
config := gfa.Handler{}
config.Init(app) // Pass your firebase app variable.
gfaHandler will automatically declare some firebase objects to use inside middlewares.
Each gfa middlewares use a wrapper, to pass in some parameters. To declare them, use :
router.METHOD(
path,
mid(config, ...opts),
...
)
Each section comes with a how-to-use example, for better clarity.
Option | Type | Description |
---|---|---|
nonRestrictivePolicy | bool | When authentication fails, the request is aborted with an unauthorized status. Set this flag to true to override this behavior. |
Go handles auth with credentials from its own api. Once an user is logged, each secure request will be issued with an Authorization header, containing a token id that handles credentials.
VerifyToken will check and decode this token.
package main
import "github.com/Alvarios/gin-firebase-auth"
func main() {
// Set your gin and gfa apps here.
router.GET(
"/path/to/resource1",
gfa.VerifyToken(config, false),
GetResource1, // Use your own functions here.
Render,
)
}
2020 Kushuh - MIT license