🔧 Programmierung 🕛 vor 1 Jahr 26 Min Lesezeit
0

How to Set Up Authorization in a Bookstore Management System with Go, HTMX, and Permit.io

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht


This will create two environments: a development environment and a production environment.





Next, navigate to the policy editor section. By default, you should see an admin role already created. You just need to tick the view action we added, as it is not recognized by default. You need another role. This will be for users with only permission to read.



Click Create then Role and give it the name of user. Once created, you should see it in the policy editor and tick view in the user role you just created like so:





Click on Add users and then add, then add user. Fill in the details that will correspond to your users in the database.



Once that is done, navigate back to your project. In the Development For the environment for the bookstore project, click on the 3 dotted icon. You’ll see an option to copy the API key. Copy and save it somewhere, as you’ll be needing it for the project.






Setup the Database



Create a PostgreSQL database called bookstore. You’ll need to set up two tables:





  • users table: Stores user credentials and roles:




CODE

CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL,
password_hash VARCHAR(255) NOT NULL,
role VARCHAR(50) NOT NULL
);






Go ahead and populate this, but make each user have a role of admin and user, respectively, and make sure they match the users added on Permit.io.





  • books table: Stores book details:




CODE

CREATE TABLE books (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
published_at DATE,
created_at TIMESTAMPTZ DEFAULT now()
);






You don’t need to populate this we’ll be doing that in the code.






Install Dependencies



You’ll need to install the following dependencies:




  • github.com/permitio/permit-golang: Provides tools for handling role-based access control (RBAC) and permission management with Permit.io in Go applications.


  • github.com/google/uuid: This provides functions to generate and work with universally unique identifiers (UUIDs).


  • github.com/gorilla/mux: Helps to Implement an HTTP request router and dispatcher for handling routes in a web application.


  • github.com/joho/godotenv: This loads environment variables from a .env. file into the application, making it easier to manage configuration settings.


  • github.com/lib/pq: This is Go’s Postgres driver for communicating with PostgreSQL databases.


  • golang.org/x/crypto: Implements supplementary cryptographic algorithms and libraries that are not included in Go's standard library.




To install these dependencies, you need to initialize initializes a new Go module. This is the starting point for dependency management in Go.



Run this command:




CODE
go mod init bookstore






Next, run this command:




CODE

go get github.com/google/uuid \
github.com/gorilla/mux \
github.com/joho/godotenv \
github.com/lib/pq \
github.com/permitio/permit-golang \
golang.org/x/crypto






This will install all the dependencies listed above.






Setup your PDP (Policy Decision Point) Container



To set up the



You'll see that the standard_user is restricted to viewing books only and cannot add, delete, or update a book.



Let's now log in using the admin_user to see what happens:



.








  • Conclusion



    In this tutorial, we built a simple bookstore management app to implement role-based access control using Go, HTMX, and Permit.io. Authorization is fundamental aspect of application security, as it ensures that users can only access what they’re allowed to.



    Implementing an effective access control model like RBAC or ABAC into your application would not only secure your application but also enhance its scalability and compliance.

    Vollständiger Original-Artikel
    Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
    ↗ Original-Artikel auf dev.to lesen
    Wie bewertest du diesen Beitrag?
    1 Klick Feedback
    Teilen mit Netzwerk & Team:

    Community-Analysen & Experten-Meinungen 0

    Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
    Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
    Community Pulse: Relevanz-Einschätzung
    1 Klick Experten-Votum
    🔴 Akute Relevanz 0%
    🟡 In Evaluierung 0%
    🟢 Keine Auswirkung 0%
    Spannende Innovation 0%
    Verwandte Story-Cluster & Quellen (Vektor-KI)
    Port 8095 Engine
    1 Quelle
    Microsoft confirms first major Windows event in two years, but don’t hold your breath for Windows 12
    1 Quelle
    CVE-2026-14199 | Grafana Enterprise/OSS up to 13.2.0 Auth Proxy privileges management (Nessus ID 342727 / WID-SEC-2026-3190)
    1 Quelle
    CVE-2026-63020 | F5 BIG-IP prior 17.1.3.4/17.5.1.8/21.0.0.3/21.1.0.1 Configuration Utility Page clickjacking
    Ähnliche Beiträge
    🔍 Verwandte News

    Auch interessante Nachrichten How to Set Up Authorization in a Bookstore Management System with Go, HTMX, and Permit.io

    Thematisch verwandte Begriffe: Authorization, Bookstore, Management, System · 6 Treffer

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...

    Laden...

    Beiträge werden geladen ...

    Laden...

    Videos werden geladen ...