auth

package
v0.0.0-...-35ac193 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const Issuer = "codelympics.dev"

Issuer is the issuer of the JWT token

View Source
const Validity = 24 * time.Hour

Validity is how long a key is valid

Variables

View Source
var ErrHeaderStructureIncorrect = errors.New("header structure incorrect")

ErrHeaderStructureIncorrect means an incorrectly formatter error

View Source
var PublicKey *rsa.PublicKey

PublicKey used to verify tokens

Functions

func DoesHashMatch

func DoesHashMatch(hash, password string) bool

DoesHashMatch checks if the hash matches the password

func DoesPasswordMatch

func DoesPasswordMatch(user *database.User, password string) bool

DoesPasswordMatch checks if the hashed stored password and the supplied plain text password match

func GenerateOTP

func GenerateOTP(user *database.User) (*otp.Key, error)

GenerateOTP creates an OTP secret for the user

func HashPassword

func HashPassword(password string) (string, error)

HashPassword takes a password and hashes it

func IsOTPValid

func IsOTPValid(user *database.User, otp string) bool

IsOTPValid checks if OTP is valid

func SigninEmailPassword

func SigninEmailPassword(email string, password string) (*database.User, error)

SigninEmailPassword gets a user with a certain email and checks their password

func Signup

func Signup(name string, email string, password string) (*database.User, error)

Signup a new user

Types

type Token

type Token struct {
	jwt.Payload

	ID        string `json:"id,omitempty"`
	FullName  string `json:"full_name,omitempty"`
	Email     string `json:"email,omitempty"`
	AvatarURL string `json:"avatar_url,omitempty"`

	Scopes []string `json:"scopes"`
}

Token is the structure for the JWT token

func NewToken

func NewToken(user *database.User, client *database.APIClient, requestedScopes []string) *Token

NewToken from user and scopes

func TokenFromHeader

func TokenFromHeader(r *http.Request) (*Token, error)

TokenFromHeader gets a token from the HTTP Authorization header

func Validate

func Validate(token string) (*Token, error)

Validate a token

func (*Token) HasScope

func (t *Token) HasScope(requiredScope string) bool

HasScope checks if a token has this scope

func (*Token) Sign

func (t *Token) Sign() (string, error)

Sign a token and return a JWT

Jump to

Keyboard shortcuts

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