Golang, FiberV2, OAuth2

Fiber is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind.

Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applications.

Unlike other similar packages, Goth, lets you write OAuth, OAuth2, or any other protocol providers, as long as they implement the Provider and Session interfaces.

All together in simple example

package main

import (

	gf "github.com/shareed2k/goth_fiber/v2"

const (
	key = "googlekey"
	sec = "googlesec"

func main() {
		google.New(key, sec, "http://localhost:3000/auth/google/callback"),

	app := fiber.New()

	app.Get("/auth/:provider/callback", func(ctx *fiber.Ctx) error {
		user, err := gf.CompleteUserAuth(ctx)
		if err != nil {
			return err
		return nil

	app.Get("/logout/:provider", func(ctx *fiber.Ctx) error {
		return nil

	app.Get("/auth/:provider", func(ctx *fiber.Ctx) error {
		if gothUser, err := gf.CompleteUserAuth(ctx); err == nil {
		} else {
		return nil

	app.Get("/", func(ctx *fiber.Ctx) error {
		ctx.Format("<p><a href='/auth/google'>google</a></p>")
		return nil


Publikováno v Go