Documentation ¶
Overview ¶
Package auth handles various authentication methods for the metadata server.
Index ¶
- Constants
- func ContextWithUserID(ctx context.Context, userID uint) context.Context
- func CreateMetadataJWT(user *db.User, validFor time.Duration) (string, error)
- func CreateStreamingJWT(userID uint, fileLocator string) (string, error)
- func CreateUserHandler(w http.ResponseWriter, r *http.Request)
- func MiddleWare(h http.Handler) http.Handler
- func ReadyForSetup(w http.ResponseWriter, r *http.Request)
- func UserAdmin(ctx context.Context) (bool, bool)
- func UserHandler(w http.ResponseWriter, r *http.Request)
- func UserID(ctx context.Context) (uint, bool)
- type StreamingClaims
- type UserClaims
Constants ¶
const DefaultLoginTokenValidity = 24 * time.Hour
Variables ¶
This section is empty.
Functions ¶
func ContextWithUserID ¶ added in v0.3.0
ContextWithUserID returns a context with the given user ID
func CreateMetadataJWT ¶ added in v0.3.0
CreateMetadataJWT returns a string login JWT. TODO Maran: Consider setting the jti if we want to increase security.
func CreateStreamingJWT ¶
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 ¶
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 UserHandler ¶
func UserHandler(w http.ResponseWriter, r *http.Request)
UserHandler handles logging in existing users and returning a JWT.
Types ¶
type StreamingClaims ¶
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.