auth

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: GPL-3.0 Imports: 12 Imported by: 7

Documentation

Overview

Package auth handles various authentication methods for the metadata server.

Index

Constants

View Source
const DefaultLoginTokenValidity = 24 * time.Hour

Variables

This section is empty.

Functions

func ContextWithUserID added in v0.3.0

func ContextWithUserID(ctx context.Context, userID uint) context.Context

ContextWithUserID returns a context with the given user ID

func CreateMetadataJWT added in v0.3.0

func CreateMetadataJWT(user *db.User, validFor time.Duration) (string, error)

CreateMetadataJWT returns a string login JWT. TODO Maran: Consider setting the jti if we want to increase security.

func CreateStreamingJWT

func CreateStreamingJWT(userID uint, fileLocator string) (string, error)

CreateStreamingJWT creates a new JWT that will give permission to stream certain media for a certain timespan.

func CreateUserHandler

func CreateUserHandler(w http.ResponseWriter, r *http.Request)

CreateUserHandler handles the creation of users, either via invite code or the first admin user.

func MiddleWare

func MiddleWare(h http.Handler) http.Handler

MiddleWare checks for user authentication and prevents unauthorised access to the API.

func ReadyForSetup

func ReadyForSetup(w http.ResponseWriter, r *http.Request)

ReadyForSetup checks whether the metadata has been through it's initial setup If this returns true a user can be created without an invite code.

func UserAdmin

func UserAdmin(ctx context.Context) (bool, bool)

UserAdmin checks whether the JWT is authorised as admin.

func UserHandler

func UserHandler(w http.ResponseWriter, r *http.Request)

UserHandler handles logging in existing users and returning a JWT.

func UserID

func UserID(ctx context.Context) (uint, bool)

UserID extracts user id from context.

Types

type StreamingClaims

type StreamingClaims struct {
	UserID   uint
	FilePath string
	jwt.StandardClaims
}

StreamingClaims is a custom JWT that allows filesystem access to files for a certain timespan.

func ValidateStreamingJWT

func ValidateStreamingJWT(tokenStr string) (*StreamingClaims, error)

ValidateStreamingJWT validates whether a JWT is still valid and allows access to the requested file.

type UserClaims

type UserClaims struct {
	Username string `json:"username"`
	UserID   uint   `json:"user_id"`
	Admin    bool   `json:"admin"`
	jwt.StandardClaims
}

UserClaims defines our custom JWT.

Jump to

Keyboard shortcuts

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