-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: gen staff token #32
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
tools/gen_token_staff.go
Outdated
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dgrijalva/jwt-go" | ||
"github.com/isd-sgcu/oph66-backend/apperror" | ||
"github.com/isd-sgcu/oph66-backend/cfgldr" | ||
) | ||
|
||
func GenTokenStaff(department string, cfg *cfgldr.Config) (string, *apperror.AppError) { | ||
secretKey := cfg.JWTConfig.SecretKey | ||
|
||
claims := jwt.MapClaims{ | ||
"role": "staff", | ||
"department": department, | ||
} | ||
|
||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | ||
|
||
tokenString, err := token.SignedString([]byte(secretKey)) | ||
if err != nil { | ||
return "", apperror.InternalError | ||
} | ||
|
||
return tokenString, nil | ||
} | ||
|
||
func main() { | ||
config, err := cfgldr.LoadConfig() | ||
if err != nil { | ||
fmt.Println("Failed to load configuration:", err) | ||
return | ||
} | ||
|
||
department := "IT" | ||
token, appErr := GenTokenStaff(department, config) | ||
if appErr != nil { | ||
fmt.Println("Failed to generate JWT token:", appErr) | ||
return | ||
} | ||
|
||
fmt.Println("Generated JWT token for staff in department", department, ":", token) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make is bash script or something else. Making new main package will likely interrupt with ./...
syntax which is used across the project.
tools/gen_token_staff.go
Outdated
return | ||
} | ||
|
||
department := "IT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accept input from other source i.e. stdin, argv.
tools/gen_token_staff.go
Outdated
department := "IT" | ||
token, appErr := GenTokenStaff(department, config) | ||
if appErr != nil { | ||
fmt.Println("Failed to generate JWT token:", appErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Println("Failed to generate JWT token:", appErr) | |
fmt.FatalF("Failed to generate JWT token:", appErr) // something I don't remember |
tools/gen_token_staff.go
Outdated
func main() { | ||
config, err := cfgldr.LoadConfig() | ||
if err != nil { | ||
fmt.Println("Failed to load configuration:", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also here
tools/gen_token_staff.go
Outdated
|
||
claims := jwt.MapClaims{ | ||
"role": "staff", | ||
"department": department, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to store to match database format
so it would be
department and faculty. identify using code.
e.g.
department: 0
faculty: 34
เรื่องคนะยังไม่แก้เลยนะ ที่ต้องเกบทั้งคนะและภาค |
ขอ request เพิ่มอีก field คือ faculty-wide เป้น boolean (เปน token คนะที่มี access ทุกภาค) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
No description provided.