idk but it did something
This commit is contained in:
parent
95a94bfed5
commit
fbd23fe2cf
2 changed files with 36 additions and 20 deletions
|
@ -30,7 +30,7 @@ func New(redirectUri, clientId, clientSecret string) Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) GetUser(t auth.TokenResponse) (auth.User, error) {
|
func (c Client) GetUser(t auth.TokenResponse) (auth.User, error) {
|
||||||
user := auth.User {
|
user := auth.User{
|
||||||
Blacklisted: false,
|
Blacklisted: false,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -28,20 +29,35 @@ func JwtMiddleware(secret string) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
jwtSplit := strings.Split(c.GetHeader("Authorization"), " ")
|
jwtSplit := strings.Split(c.GetHeader("Authorization"), " ")
|
||||||
|
|
||||||
if jwtSplit[0] != "Bearer" {
|
if len(jwtSplit) < 2 || jwtSplit[0] != "Bearer" {
|
||||||
invalidAuth(c)
|
invalidAuth(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
claims, err := ValidateJWT(jwtSplit[1], secret)
|
claims, err := ValidateJWT(jwtSplit[1], secret)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
invalidAuth(c)
|
invalidAuth(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Set("claims", claims)
|
if userClaims, ok := claims["user"].(map[string]interface{}); ok {
|
||||||
|
userJSON, err := json.Marshal(userClaims) // Convert map to JSON
|
||||||
|
if err != nil {
|
||||||
|
invalidAuth(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var user User
|
||||||
|
err = json.Unmarshal(userJSON, &user)
|
||||||
|
if err != nil {
|
||||||
|
invalidAuth(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
claims["user"] = user
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Set("claims", claims)
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue