https://github.com/spurtcms/auth
https://github.com/spurtcms/auth
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/spurtcms/auth
- Owner: spurtcms
- License: mit
- Created: 2024-04-04T05:20:42.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-30T12:00:49.000Z (almost 2 years ago)
- Last Synced: 2024-08-04T09:22:20.800Z (almost 2 years ago)
- Language: Go
- Size: 68.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# Auth Package
This Auth package stands as a versatile, standalone module, tailored for seamless integration into any Golang project, promising flexibility and convenience. It isn't confined solely to any particular platform; it offers full freedom to incorporate it into any Golang platform. We have seamlessly integrated it with the spurtCMS admin system, ensuring a smooth integration process.
## Features
- Smooth admin login
- Generates and returns an authentication token, typically used for user authentication and authorization processes.
- Validates the authenticity and integrity of a given authentication token.
- Check if a user login attempt is valid by verifying credentials against stored user information.
- Parses and decrypts JWT tokens (Json Web Tokens) from the HTTP request's 'authorization' header
- Verifies the validity of tokens using the provided jwtSecret
# Installation
``` bash
go get github.com/spurtcms/auth
```
- Setup the Auth config
``` bash
config := Config{
UserId: 1,
ExpiryTime: 2, // It should be in hours not minutes or seconds
SecretKey: "test@123",
DB: &gorm.DB{},
}
auth := AuthSetup(config)
```
# Usage Example
``` bash
func main (){
config := Config{
UserId: 1,
ExpiryTime: 2, // It should be in hours not minutes or seconds
SecretKey: "test@123",
DB: &gorm.DB{},
}
auth := AuthSetup(config)
//create token - generates new JWtoken
token, _ := auth.CreateToken()
//checklogin - verifies user credentials
token, userid,err :=auth.Checklogin("Username", "Password")
//verifytoken - parses and verifies the token generated
userid, err := auth.VerifyToken("token","secretkey","currenttime")
}
```
# Getting help
If you encounter a problem with the package,please refer [Please refer (https://www.spurtcms.com/documentation/cms-admin) or you can create a new Issue in this repo (https://github.com/spurtcms/auth/issues).