auth

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 6 Imported by: 2

README

auth

GitHub Workflow Status Codecov GoDoc Sourcegraph

Package auth is a middleware that provides request authentication for Flamego.

Installation

The minimum requirement of Go is 1.18.

go get github.com/flamego/auth

Getting started

package main

import (
	"github.com/flamego/auth"
	"github.com/flamego/flamego"
)

func main() {
	f := flamego.Classic()
	f.Use(auth.Basic("username", "secretpassword"))
	f.Get("/", func(user auth.User) string {
		return "Welcome, " + string(user)
	})
	f.Run()
}

Getting help

License

This project is under the MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basic

func Basic(username, password string) flamego.Handler

Basic returns a middleware handler that injects auth.User into the request context upon successful basic authentication. The handler responds http.StatusUnauthorized when authentication fails.

func BasicFunc

func BasicFunc(fn func(username, password string) bool) flamego.Handler

BasicFunc returns a middleware handler that injects auth.User into the request context upon successful basic authentication with the given function. The function should return true for a valid username and password combination.

func Bearer

func Bearer(token string) flamego.Handler

Bearer returns a middleware handler that injects auth.User (empty string) into the request context upon successful bearer authentication. The handler responds http.StatusUnauthorized when authentication fails.

func BearerFunc

func BearerFunc(fn func(token string) bool) flamego.Handler

BearerFunc returns a middleware handler that injects auth.User (empty string) into the request context upon successful bearer authentication with the given function. The function should return true for a valid bearer token.

func SecureCompare

func SecureCompare(given, actual string) bool

SecureCompare performs a constant time compare of two strings to prevent timing attacks.

Types

type Token added in v1.1.0

type Token string

Token is the authenticated token that was extracted from the request.

type User

type User string

User is the authenticated username that was extracted from the request.

Jump to

Keyboard shortcuts

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