Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.
/ gate Public archive

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

License

Notifications You must be signed in to change notification settings

hiendv/gate

Repository files navigation

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 a given JWT
user, err = auth.Authenticate("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImVtYWlsQGxvY2FsIiwicm9sZXMiOlsicm9sZSJdLCJleHAiOjE2MDUwNTI4MDAsImp0aSI6ImNsYWltcy1pZCIsImlhdCI6MTYwNTA0OTIwMCwic3ViIjoiaWQifQ.wRouDwptboRBSK-bXHugYeorWGy7pfUHstH_jEHKl_4")
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:

About

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages