Documentation ¶
Overview ¶
package jwt implements simple way to create jwt tokens for your web project in golang. This package takes SHA256 algorithm by default for any other algorithm download this source code and change it freely. Authenticate means putting username and password and getting verified and generate key. Authorization means having a key which can be used to open door. Functions implemented and exported in this package: func Authenticate(rw http.ResponseWriter, jsonStringTOSend string, seconds int) (string, error) func Authorize(r *http.Request) (string, error) func SetCookiePath(path string) func IsPrivateKeySet() bool
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authenticate ¶
After Authenticating the user by verifying the username in database you need to create a json string by using json.Marshal() Function and send it via this function which gets converted into encoded hash and send it user via http.ResponseWriter as a token you could specify duration of cookie in seconds argument.
func Authorize ¶
reads jwt cookies in the client http.Request and checks the validity of jwt cookie signature (check whether it is signed with the same privateKey) and returns the json string which was set as a cookie by server before in Authenticate() function.
func SetPrivateKey ¶
sets given string as a privateKey. privateKey can be set only once.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.