Plain Auth is an authentication library for Go servers. Mount its http.Handler on your router, then use the same instance in your own handlers to read the signed-in user. Your application keeps its listener, middleware, routes, database and screens, and any frontend or HTTP client can call the JSON API. Developer preview. APIs and SQL migrations may change before the first tagged release. The roadmap shows what is finished and what remains, with a test linked to every completed behavior. What it does Sign in with email and password, usernames, magic links, email or SMS codes, passkeys, social providers, Google One Tap, Ethereum wallets or guest accounts. Sessions that are database-backed and revocable, with optional cookie caching, several accounts per browser, device authorization and cross-subdomain cookies. Security: two-factor authentication, rate limits shared through Redis or Valkey, CAPTCHA, breached-password checks and trusted origins. Organizations and teams with roles, permissions, invitations and member limits, plus administrator accounts and API keys. Enterprise: OIDC and SAML single sign-on, and SCIM directory provisioning. OAuth 2.0 and OpenID Connect provider: authorization code with PKCE, refresh tokens, client registration, introspection, revocation and JWKS. Billing with Stripe subscriptions and seats, or Polar checkout. Storage and tools: SQLite, PostgreSQL and MySQL, the authctl schema CLI, an OpenAPI document, error messages in 22 languages and test helpers. Extend with Go plugins and endpoint hooks that reject, rewrite or answer requests and change their results. Every capability has a guide in the documentation index. Quickstart Use a patched Go 1.26 or newer toolchain and a C compiler (for SQLite). Clone the repository, generate a signing secret and start the example app. git clone https://github.com/Plain-Org/plain-auth.git cd plain-auth export "$(go run ./cmd/authctl secret)" export AUTH_URL=http://127.0.0.1:3000 go run ./examples/basic The example listens on http://127.0.0.1:3000 and creates auth.db in the working directory (set AUTH_DB to change it). In another terminal, create an account, call a protected route and sign out: curl -sS -c cookies.txt http://127.0.0.1:3000/api/auth/sign-up/email \ -H 'Content-Type: application/json' \ -d '{"name":"Ada","email":"ada@example.com","password":"example-password"}' curl -sS -b cookies.txt http://127.0.0.1:3000/me curl -sS -b cookies.txt -c cookies.txt http://127.0.0.1:3000/api/auth/sign-out \ -H 'Origin: http://127.0.0.1:3000' -H 'Content-Type: application/json' -d '{}' Add it to your app Install the SQLite adapter, which also brings in the core library, from main: go get github.com/Plain-Org/plain-auth/adapters/sqlite@main Create one instance and mount it under its base path (/api/auth by default): import ( "strings" "github.com/Plain-Org/plain-auth" "github.com/Plain-Org/plain-auth/adapters/sqlite" ) store, err := sqlite.Open("auth.db") if err != nil { return err } defer store.Close() // in the function that owns the application's lifetime auth, err := plainauth.New(plainauth.Options{ Store: store, EmailAndPassword: true, }) if err != nil { return err } mux.Handle(strings.TrimSuffix(auth.BasePath(), "/")+"/", auth) Inside your own handlers, auth.GetSession(r.Context(), r.Header) returns the signed-in user, or nil when the request is anonymous. New reads AUTH_SECRET and AUTH_URL from the environment; see environment configuration for every setting. The module path is github.com/Plain-Org/plain-auth and the package name is plainauth. examples/basic: a complete host app with a protected route and graceful shutdown Router integrations: ServeMux, chi, Gorilla Mux, Gin, Echo and Fiber Databases and the CLI: PostgreSQL, MySQL and schema migrations Go client: call the API from another Go service Documentation: every guide, grouped by task Roadmap: the feature checklist and its test evidence Backlog: wanted work that is not scheduled yet Contributing: local setup, source layout and checks Security: report a vulnerability privately MIT license, maintained by Nabil Abu-Hadba A hosted Plain Auth service is coming soon for teams that would rather not run it themselves.
AI NEWS JOURNAL
Hacker News Show HNAI NEWS / JOURNAL
Show HN: Plain-Auth an open-source authentication library for Go
Hey everyone,I've always loved the simplicity of Go, but the only thing keeping me from switching all of my backends to Go is really one package, and one package only, which is Better-Auth. It's just so easy to use: simple plugin, and start working. It's got everything I need: organizations, teams, billing, social auth, everything.I tried to scour GitHub and the open source community for anything remotely close to it in Go, and I honestly couldn't find anything that was worth it, so I just decided to make it myself. It's an open-source Go package. It is not 100% feature parity with Better-Auth yet, but it's getting there.Would love some feedback. For anyone to try it out, it works with pretty much all of those routers: Chi, Echo, Fiber, Mux and more. Any feedback is greatly appreciated.Oh, and it's also my very first open source repo, so I'm learning as I go. Comments URL: https://news.ycombinator.com/item?id=50673212 Points: 2 # Comments: 0
번역 서비스가 일시 중지되어 원문을 표시합니다.