# Packages
No description provided by the author
No description provided by the author
No description provided by the author
# README
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:
- Password-based authentication examples, unit tests & integration tests
- OAuth2 authentication examples, unit tests & integration 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:
- dgrijalva/jwt-go for the enormous help dealing with JWT works
- satori/go.uuid for the claims ID generator