auth

package
v0.0.0-...-a807e99 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

auth

-- import "git.ooo.ua/pub/armory/auth"

Usage

const (
	Header    = "Authorization"
	JWTHeader = "jwt"

	KeyUID = iota
)

Header name of the Authorization header.

const (
	HeaderHash        = "X-Auth-Hash"
	HeaderSignature   = "X-Auth-Signature"
	HeaderSigner      = "X-Auth-Signer"
	HeaderService     = "X-Auth-Service"
	HeaderContentType = "Content-Type"
)
func CheckToken
func CheckToken(authtoken string) (int, []byte, error)

CheckToken checks Authorization token if it valid return nil.

func ExtractUserID
func ExtractUserID() func(http.Handler) http.Handler
func Init
func Init(usrApiLink string)
func NewSignedGetRequest
func NewSignedGetRequest(privateKey, path, service string) (*http.Request, error)

NewSignedGetRequest creates a new GET request, sings the request details using the privateKey and adds the auth headers.

func NewSignedPostRequest
func NewSignedPostRequest(privateKey, path string, body []byte, mimeType, service string) (*http.Request, error)

NewSignedPostRequest creates a new POST request, hashes the body, sings the request details using the privateKey and adds the auth headers.

func ValidateAuthHeader
func ValidateAuthHeader(required bool) func(http.Handler) http.Handler

ValidateAuthHeader checks the request Authorization token. If token valid - continue request handling flow, else redirect userapi response to the requester.

func VerifyRequestSignature
func VerifyRequestSignature(r *http.Request, publicKey string) (bool, error)

VerifyRequestSignature checks the request auth headers.

Documentation

Index

Constants

View Source
const (
	// DEPRECATED
	Header = "Authorization"
	// DEPRECATED
	JWTHeader           = "jwt"
	HeaderAuthorization = "Authorization"
	HeaderJWT           = "jwt"
	Header2Password     = "X-2Pass"
)

HeaderAuthorization name of the `Authorization` header.

View Source
const (
	HeaderHash        = "X-Auth-Hash"
	HeaderSignature   = "X-Auth-Signature"
	HeaderSigner      = "X-Auth-Signer"
	HeaderService     = "X-Auth-Service"
	HeaderContentType = "Content-Type"
)

Variables

This section is empty.

Functions

func AuthtokenHeader

func AuthtokenHeader(r *http.Request) string

AuthtokenHeader extracts from the `http.Request` Authorization header.

func CheckToken

func CheckToken(authtoken string) (int, []byte, error)

CheckToken checks `Authorization` token if it valid return nil.

func ExtractUserID

func ExtractUserID(required ...bool) func(http.Handler) http.Handler

Method reads JWT HeaderAuthorization and fill KeyUID and KeyIsAdmin in the context Use ExtractUserID() if jwt required Use ExtractUserID(false) if jwt not required

func GetUID

func GetUID(r *http.Request) int64

GetUID extracts User-ID from the `http.Request` ctx.

func Init

func Init(usrApiLink string)

func Is2PassValid

func Is2PassValid(r *http.Request) bool

Is2PassValid return `true` if user used to 2nd password for request auth.

func IsAdmin

func IsAdmin(r *http.Request) bool

IsAdmin return `true` if request sent by admin.

func NewSignedDataRequest

func NewSignedDataRequest(method, privateKey, path string, model interface{}, service string) (*http.Request, error)

NewSignedPostRequest creates a new POST/PUT/PATCH request, hashes the model json parsed body, sings the request details using the `privateKey` and adds the auth headers.

func NewSignedGetRequest

func NewSignedGetRequest(privateKey, path, service string) (*http.Request, error)

NewSignedGetRequest creates a new GET request, sings the request details using the `privateKey` and adds the auth headers.

func NewSignedPostRequest

func NewSignedPostRequest(privateKey, path string, body []byte, mimeType, service string) (*http.Request, error)

NewSignedPostRequest creates a new POST request, hashes the body, sings the request details using the `privateKey` and adds the auth headers.

func ValidateAuthHeader

func ValidateAuthHeader(required bool) func(http.Handler) http.Handler

ValidateAuthHeader checks the request Authorization token. If token valid - continue request handling flow, else redirect `userapi` response to the requester.

func VerifyRequestSignature

func VerifyRequestSignature(r *http.Request, publicKey string) (bool, error)

VerifyRequestSignature checks the request auth headers.

Types

type CtxKey

type CtxKey string
const (
	KeyUID          CtxKey = "key_uid"
	KeyIsAdmin      CtxKey = "key_isAdmin"
	KeyIs2PassValid CtxKey = "key_is2PassValid"
)

type ReturnAuthStruct

type ReturnAuthStruct struct {
	Jti          int64 `json:"jti,string"`
	IsAdmin      bool  `json:"isAdmin"`
	Is2PassValid bool  `json:"is2PassValid"`
}

func ExtractAuthData

func ExtractAuthData(r *http.Request) (res ReturnAuthStruct, ok bool)

ExtractAuthData extracts `ReturnAuthStruct` from request.

func (ReturnAuthStruct) SetContext

func (a ReturnAuthStruct) SetContext(r *http.Request) *http.Request

Jump to

Keyboard shortcuts

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