done
This commit is contained in:
parent
f9932f0362
commit
ea8ed9202a
23
auth/auth.go
23
auth/auth.go
@ -194,13 +194,28 @@ func (con Connection) signIn(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (con Connection) verify(c *gin.Context) {
|
||||
claims, exists := c.Get("claims")
|
||||
if !exists {
|
||||
log.Println("No Claims")
|
||||
c.AbortWithStatus(403)
|
||||
authCookie, err := c.Request.Cookie("auth")
|
||||
if err != nil {
|
||||
c.Redirect(303, fmt.Sprintf("http://%s/", DOMAIN))
|
||||
return
|
||||
}
|
||||
|
||||
token, err := jwt.ParseWithClaims(authCookie.Value, &AuthClaims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
// Don't forget to validate the alg is what you expect:
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
|
||||
// hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key")
|
||||
return secret, nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
c.AbortWithError(403, err)
|
||||
return
|
||||
}
|
||||
claims := token.Claims
|
||||
|
||||
forwarded_host := c.Request.Header.Get("x-forwarded-host")
|
||||
log.Printf("Checking auth of %s", forwarded_host)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user