/GO-JSON-Web-Tokens

This is demo program to show the working of the go-jwt tool, so we can use this library for authorization in out project.

Primary LanguageGoApache License 2.0Apache-2.0

GO-JSON-Web-Tokens

This is demo program to show the working of the go-jwt tool, so we can use this library for authorization in out project.
I used "github.com/dgrijalva/jwt-go" library for this project.
This library jwt-go used for json web token methods.
As we know that now a days for each user request, instead of validate the user from database side,
we validate the user from cache and by using token in that case json web token is pretty good for solving those problem and its very secure to use and very fast.

Steps for Using the Library

  1. Import the "github.com/dgrijalva/jwt-go
  2. Create public key and private key using command : ssh-keygen -t rsa
  3. Read this files and store in different PrivateKey and PublicKey Using the ioutill library
  4. Use Jwt.New function for create the token
  5. by using the help of jwt.MapClaims, store the metadata inside the jwt token file
  6. Use the files using "jwt.ParseRSAPrivateKeyFromPEM", most of the peopele do wrong here they try to use []byte("string") which most of time throw error
  7. By using (*token).SignedString(interface{}) generate the token response
  8. By using jwt.Parse function, parse the function the code and get the metadata from the db

Thanks if any changes required please let me know.