auth

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWTAuthFunc = func(ctx context.Context) (context.Context, error) {
	token, err := authTokenFromMD(ctx, "bearer")
	if err != nil {
		return nil, err
	}

	parsedToken, err := parseToken(token)
	if err != nil {
		return nil, status.Errorf(codes.Unauthenticated, "invalid auth token: %v", err)
	}

	newCtx := context.WithValue(ctx, authTokenCTX{}, parsedToken)

	return newCtx, nil
}

Methode um den Token zu prüfen und bei Erfolg in den context zu legen. Das Abfragen der userdb und erstellen des Tokens passiert in package internal/auth

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

Passwort hash prüfen true => passwort io, false => stimmt nicht

func CreateJWT added in v0.3.1

func CreateJWT(user *Profile) string

create a jwt token based on user profile

func GetSubjectFromContext

func GetSubjectFromContext(ctx context.Context) string

get the subject (user id) from auth context

func GetUsernameFromContext added in v0.5.0

func GetUsernameFromContext(ctx context.Context) string

get the username from auth context

func HashPassword

func HashPassword(password string) (string, error)

Passwort hash erzeugen

Types

type Claims

type Claims map[string]interface{}

func GetClaimsFromContext

func GetClaimsFromContext(ctx context.Context) (token Claims, ok bool)

GetTokenFromContext returns the parsed token in ctx if it exists. The returned Claim should not be modified. Writing to it may cause races. Modification should be made to copies of the returned Claim.

type Profile

type Profile struct {
	Username string   `json:"username,omitempty"`
	Subject  string   `json:"subject,omitempty"`
	Pwhash   string   `json:"pwhash,omitempty"`
	Roles    []string `json:"roles,omitempty"`
}

user profile for internal use only

Jump to

Keyboard shortcuts

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