Skip to content

realcletusola/goAuth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

implementing jwt auth in golang

Dirs

  • Database: It contains the database initialization and migration function
  • Handler:This contains all user auth http handler functions
  • Middleware:The middleware.go file contains TokenBlackList middleware function(this function checks the gets token from header on signout request and check if it's blacklisted or not)
  • Router:All routes
  • Validator: This is where all field validaton takes place
  • Note:

    The JWT secret key is defined on line 24 in the handler.go file, this key can be set to anything(you can make it more secured by generating a long and strong random string).You can generate a secretkey with the below code:

    import (
         "crypto/rand"
         "encoding/base64"
         "fmt"  
        )
    
        func generateSecretKey(length int) (string, error) {
            // Create a byte slice to hold the random bytes
            key := make([]byte, length)
            
            // Read random bytes from the crypto/rand package
            _, err := rand.Read(key)
            if err != nil {
    	        return "", err
            }
    
            // Encode the bytes to a base64 string
            secretKey := base64.URLEncoding.EncodeToString(key)
    
            return secretKey, nil
        }
    

    Next(todo):

    Things that are yet to be done:

  • Unit Test
  • Crud operation on both User and Profile data
  • Dockerization
  • Deployment
  • About

    golang authentication system with jwt

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Languages