Categorygithub.com/hiendv/gate
repositorypackage
0.1.0
Repository: https://github.com/hiendv/gate.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

Gate

Build Status GoDoc Go Report Card Coverage Status

Golang Gate
An authentication and RBAC authorization library using JWT for Go 1.7+

Features

  • Simple and well-tested API
  • Exported flexible contracts
  • Developer friendly
  • Persistence free

Supported authentication drivers

  • Password-based authentication
  • OAuth2

Installation

go get github.com/hiendv/gate

Usage

Quick example to get a taste of Gate

var auth gate.Auth
var user gate.User
var err error

// some construction codes go here

// Login using password-based authentication
user, err = auth.Login(map[string]string{"email": "email", "password": "password"})
if err != nil {
	log.Fatal("oops")
}

// Login using OAuth
// Redirect users to the authentication code URL
url, err := auth.LoginURL("state")

// Receive the code and exchange it
user, err = auth.Login(map[string]string{"code": "received-code"})
if err != nil {
	log.Fatal("oops")
}

// Issue the JWT for the user
jwt, err := auth.IssueJWT(user)
if err != nil {
	log.Fatal("oops")
}

// Send the JWT to the user and let them use it to authenticate
// Authenticate a user using JWT
user, err = auth.Authenticate("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiaWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwicm9sZXMiOlsicm9sZSJdfSwiZXhwIjoxNjA1MDUyODAwLCJqdGkiOiJjbGFpbXMtaWQiLCJpYXQiOjE2MDUwNDkyMDB9.b0gxC2uZRek-SPwHSqyLOoW_DjSYroSivLqJG96Zxl0")
if err != nil {
	log.Fatal("oops")
}

err = auth.Authorize(user, "action", "object")

You may want to check these examples and tests:

Development & Testing

Please check the Contributing Guidelines.

Contribution

Issues and PRs are welcome !

Credits

The Gate bouncer logo is licensed under the Creative Commons 4.0 Attributions license.
The original gopher.svg was created by Takuya Ueda, licensed under the Creative Commons 3.0 Attributions license.
The Go Gopher was designed by Renee French, licensed under the Creative Commons 3.0 Attributions license.

Big thanks to: