auth

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2020 License: AGPL-3.0 Imports: 5 Imported by: 0

README

auth

Questo package implementa le funzioni per la comunicazione con il server LDAP di autenticazione e per la gestione dei token JWT di accesso.

Funzionamento

Il server LDAP permette di autenticare gli utenti passando nome utente e password. Una volta verificate tali credenziali viene generato un token JWT. Esso viene passato al client, il quale poi lo include in ogni richiesta HTTP successiva.

Server LDAP

Per comunicare con il server LDAP è necessario servirsi di questa libreria. Da internal/config va letto l'indirizzo del server.

Nota: esiste nella configurazione un'opzione dummy_auth la quale fa sì che il server accetti ogni utente senza controllare le credenziali.

Token JWT

I token JWT conservano il nome utente e il livello di privilegi dell'utente (user o admin). Essi sono firmati crittograficamente, e l'algoritmo scelto per questo progetto è HMAC-SHA256. Il secret per la firma dev'essere ottenuto da internal/config. Libreria.

Tipi

type UserInfo

Errori

type AuthenticationError
type LDAPError
type JWTCreationError
type InvalidTokenError

Funzioni

func InitializeSigning()
func AuthenticateUser(username, password string) ([]byte, error) // ritorna il token
func ParseToken(token []byte) (UserInfo, error)

Documentation

Overview

Package per l'autenticazione degli utenti.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticateUser

func AuthenticateUser(username, password string) ([]byte, error)

Verifica le credenziali, ottiene il livello di permessi dell'utente e restituisce il token.

func InitializeSigning

func InitializeSigning()

Inizializza l'algoritmo per la firma HS256

Types

type AuthenticationError

type AuthenticationError struct {
	// contains filtered or unexported fields
}

Errore di autenticazione

func (*AuthenticationError) Error

func (e *AuthenticationError) Error() string

type InvalidTokenError

type InvalidTokenError struct {
	// contains filtered or unexported fields
}

Errore nella verifica del token

func (*InvalidTokenError) Error

func (e *InvalidTokenError) Error() string

type JWTCreationError

type JWTCreationError struct {
	// contains filtered or unexported fields
}

Errore di generazione del token

func (*JWTCreationError) Error

func (e *JWTCreationError) Error() string

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	IsAdmin  bool   `json:"isAdmin"`
}

Valore di ritorno di ParseToken

func ParseToken

func ParseToken(token []byte) (UserInfo, error)

Verifica un token e ne restituisce le informazioni

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL