Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

133 Commits

Repository files navigation

Hyperscale security Last releaseDocumentation

Go Report Card

BranchStatusCoverage
masterBuild StatusCoveralls

A transport-agnostic authentication and authorization toolkit for Go — HTTP, gRPC and ConnectRPC, OAuth2, JWT, sessions, and a composable Voter-based access model. It is shipped as a multi-module workspace so you import only what you need.

Modules

ModulePurpose
github.com/hyperscale-stack/securityCore: Authentication, Engine, Manager, Voter, ADM
…/security/httphttpsecnet/http middleware + authorization
…/security/grpcgrpcsec — unary/stream interceptors
…/security/connectrpcconnectrpcsec — ConnectRPC auth + authorize interceptors
…/security/basicHTTP Basic extractor + authenticator
…/security/bearerBearer extractor + TokenVerifier authenticator
…/security/passwordBCrypt + Argon2id hashers (NeedsRehash)
…/security/jwtjwtsec — JWT signer/verifier, JWKS
…/security/sessionStateless encrypted cookie sessions + CSRF
…/security/oauth2OAuth2 server: profiles, grants, endpoints
…/security/oauth2/store/sqlProduction OAuth2 storage on database/sql
…/security/oauth2/store/redisProduction OAuth2 storage on Redis

Install

go get github.com/hyperscale-stack/security
go get github.com/hyperscale-stack/security/http # and any other module you need

Quick start — HTTP Basic

package main
import (
"net/http""github.com/hyperscale-stack/security""github.com/hyperscale-stack/security/basic"
httpsec "github.com/hyperscale-stack/security/http""github.com/hyperscale-stack/security/password"
)
funcmain() {
// loader is your UserLoader implementation (DB-backed, etc.).authenticator:=basic.NewAuthenticator(loader, password.NewBCryptHasher(12))
engine:=security.NewEngine(
security.NewManager(authenticator),
basic.NewExtractor(),
)
mux:=http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r*http.Request) {
auth, _:=security.FromContext(r.Context())
w.Write([]byte("hello "+auth.Name()))
})
http.ListenAndServe(":8080", httpsec.Middleware(engine)(mux))
}

Add authorization with a Voter and an AccessDecisionManager:

adm:=security.NewAffirmativeDecisionManager(voter.HasRole("ADMIN"))
mux.Handle("/admin", httpsec.Authorize(adm, security.Role("ADMIN"))(adminHandler))

Documentation

Development

make sync # go work sync
make build # build every module
make test# race + coverage
make lint # golangci-lint with the shared config

License

Hyperscale security is licensed under the MIT license.

About

The Hyperscale security is a powerful and highly customizable authentication and access-control framework.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages