-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Kenton Vizdos edited this page Oct 8, 2023
·
2 revisions
Welcome to the locksmith wiki! This wiki covers the usage and power of Locksmith in a (hopefully) easy to digest way.
Getting started with Locksmith can be completed by plugging the InitializeLocksmithRoutes() into your HTTP mux. This is a highly customizable structure which powers what is and what is not enabled in your app. After that, you can start securing your endpoints with endpoints.SecureEndpointHTTPMiddleware().
func main() {
ctx, timeout := context.WithTimeout(context.Background(), 20*time.Second)
db := database.MongoDatabase{
Ctx: ctx,
Cancel: timeout,
}
err := db.Initialize("mongodb://localhost:27017", "time-tracker")
if err != nil {
fmt.Println(err)
return
}
mux := http.NewServeMux()
// Initialize Locksmith Handlers
routes.InitializeLocksmithRoutes(mux, db, routes.LocksmithRoutesOptions{
AppName: "Your Amazing App",
Styling: pages.LocksmithPageStyling{
StartGradient: "#4c2ea5",
EndGradient: "#3d2a7c",
SubmitColor: "#eeb604",
},
})
// Define custom app routes
// The `endpoints.SecureEndpointHTTPMiddleware()` will only check
// to see if the user is authorized (logged in)
mux.Handle("/app", endpoints.SecureEndpointHTTPMiddleware(app.AppHTTPHandler{}, db)
listenErr := http.ListenAndServe(":3000", mux)
if listenErr != nil {
fmt.Println(listenErr)
}
}
This basic implementation scratches the surface of what is possible using Locksmith to power your authentication. There is much to learn in these docs, so have fun!
I recommend checking the docs in this order: