Documentation ¶
Index ¶
- Constants
- func AuthtokenHeader(r *http.Request) string
- func CheckToken(authtoken string) (int, []byte, error)
- func ExtractUserID(required ...bool) func(http.Handler) http.Handler
- func GetUID(r *http.Request) int64
- func Init(usrApiLink string)
- func Is2PassValid(r *http.Request) bool
- func IsAdmin(r *http.Request) bool
- func NewSignedDataRequest(method, privateKey, path string, model interface{}, service string) (*http.Request, error)
- func NewSignedGetRequest(privateKey, path, service string) (*http.Request, error)
- func NewSignedPostRequest(privateKey, path string, body []byte, mimeType, service string) (*http.Request, error)
- func ValidateAuthHeader(required bool) func(http.Handler) http.Handler
- func VerifyRequestSignature(r *http.Request, publicKey string) (bool, error)
- type CtxKey
- type ReturnAuthStruct
Constants ¶
const ( // DEPRECATED Header = "Authorization" // DEPRECATED JWTHeader = "jwt" HeaderAuthorization = "Authorization" HeaderJWT = "jwt" Header2Password = "X-2Pass" )
HeaderAuthorization 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" )
Variables ¶
This section is empty.
Functions ¶
func AuthtokenHeader ¶
AuthtokenHeader extracts from the `http.Request` Authorization header.
func CheckToken ¶
CheckToken checks `Authorization` token if it valid return nil.
func ExtractUserID ¶
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 Is2PassValid ¶
Is2PassValid return `true` if user used to 2nd password for request auth.
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 ¶
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 ¶
ValidateAuthHeader checks the request Authorization token. If token valid - continue request handling flow, else redirect `userapi` response to the requester.
Types ¶
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