fix: format logs
This commit is contained in:
@@ -55,7 +55,7 @@ func AppHandler() gin.HandlerFunc {
|
||||
if pusher := c.Writer.Pusher(); pusher != nil {
|
||||
// use pusher.Push() to do server push
|
||||
if err := pusher.Push("/app/build/bundle.js", nil); err != nil {
|
||||
log.Debug("Failed to push file path", err)
|
||||
log.Debug("Failed to push file path: ", err)
|
||||
}
|
||||
}
|
||||
c.HTML(http.StatusOK, "app.tmpl", gin.H{
|
||||
|
@@ -50,7 +50,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
if responseMode != "query" && responseMode != "web_message" {
|
||||
log.Debug("Invalid response_mode")
|
||||
log.Debug("Invalid response_mode: ", responseMode)
|
||||
gc.JSON(400, gin.H{"error": "invalid response mode"})
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
||||
if isQuery {
|
||||
gc.Redirect(http.StatusFound, loginURL)
|
||||
} else {
|
||||
log.Debug("Failed to get client_id")
|
||||
log.Debug("Failed to get client_id: ", clientID)
|
||||
gc.HTML(http.StatusOK, template, gin.H{
|
||||
"target_origin": redirectURI,
|
||||
"authorization_response": map[string]interface{}{
|
||||
@@ -84,7 +84,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
||||
if isQuery {
|
||||
gc.Redirect(http.StatusFound, loginURL)
|
||||
} else {
|
||||
log.Debug("Invalid client_id")
|
||||
log.Debug("Invalid client_id: ", clientID)
|
||||
gc.HTML(http.StatusOK, template, gin.H{
|
||||
"target_origin": redirectURI,
|
||||
"authorization_response": map[string]interface{}{
|
||||
@@ -102,7 +102,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
||||
if isQuery {
|
||||
gc.Redirect(http.StatusFound, loginURL)
|
||||
} else {
|
||||
log.Debug("Failed to get state")
|
||||
log.Debug("Failed to get state: ", state)
|
||||
gc.HTML(http.StatusOK, template, gin.H{
|
||||
"target_origin": redirectURI,
|
||||
"authorization_response": map[string]interface{}{
|
||||
@@ -127,7 +127,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
||||
if isQuery {
|
||||
gc.Redirect(http.StatusFound, loginURL)
|
||||
} else {
|
||||
log.Debug("Invalid response_type")
|
||||
log.Debug("Invalid response_type: ", responseType)
|
||||
gc.HTML(http.StatusOK, template, gin.H{
|
||||
"target_origin": redirectURI,
|
||||
"authorization_response": map[string]interface{}{
|
||||
@@ -146,7 +146,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
||||
if isQuery {
|
||||
gc.Redirect(http.StatusFound, loginURL)
|
||||
} else {
|
||||
log.Debug("Failed to get code_challenge")
|
||||
log.Debug("Failed to get code_challenge: ", codeChallenge)
|
||||
gc.HTML(http.StatusBadRequest, template, gin.H{
|
||||
"target_origin": redirectURI,
|
||||
"authorization_response": map[string]interface{}{
|
||||
|
@@ -16,7 +16,7 @@ func JWKsHandler() gin.HandlerFunc {
|
||||
jwk := envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyJWK)
|
||||
err := json.Unmarshal([]byte(jwk), &data)
|
||||
if err != nil {
|
||||
log.Debug("Failed to parse JWK", err)
|
||||
log.Debug("Failed to parse JWK: ", err)
|
||||
c.JSON(500, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
|
@@ -19,7 +19,7 @@ func LogoutHandler() gin.HandlerFunc {
|
||||
// get fingerprint hash
|
||||
fingerprintHash, err := cookie.GetSession(gc)
|
||||
if err != nil {
|
||||
log.Debug("Failed to get session", err)
|
||||
log.Debug("Failed to get session: ", err)
|
||||
gc.JSON(http.StatusUnauthorized, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
@@ -28,7 +28,7 @@ func LogoutHandler() gin.HandlerFunc {
|
||||
|
||||
decryptedFingerPrint, err := crypto.DecryptAES(fingerprintHash)
|
||||
if err != nil {
|
||||
log.Debug("Failed to decrypt fingerprint", err)
|
||||
log.Debug("Failed to decrypt fingerprint: ", err)
|
||||
gc.JSON(http.StatusUnauthorized, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
|
@@ -34,7 +34,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||
|
||||
sessionState := sessionstore.GetState(state)
|
||||
if sessionState == "" {
|
||||
log.Debug("Invalid oauth state")
|
||||
log.Debug("Invalid oauth state: ", state)
|
||||
c.JSON(400, gin.H{"error": "invalid oauth state"})
|
||||
}
|
||||
sessionstore.GetState(state)
|
||||
@@ -42,7 +42,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||
sessionSplit := strings.Split(state, "___")
|
||||
|
||||
if len(sessionSplit) < 3 {
|
||||
log.Debug("Invalid redirect url")
|
||||
log.Debug("Unable to get redirect url from state: ", state)
|
||||
c.JSON(400, gin.H{"error": "invalid redirect url"})
|
||||
return
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
if hasProtectedRole {
|
||||
log.Debug("Invalid role")
|
||||
log.Debug("Signup is not allowed with protected roles:", inputRoles)
|
||||
c.JSON(400, gin.H{"error": "invalid role"})
|
||||
return
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func OAuthCallbackHandler() gin.HandlerFunc {
|
||||
user, _ = db.Provider.AddUser(user)
|
||||
} else {
|
||||
if user.RevokedTimestamp != nil {
|
||||
log.Debug("User access revoked")
|
||||
log.Debug("User access revoked at: ", user.RevokedTimestamp)
|
||||
c.JSON(400, gin.H{"error": "user access has been revoked"})
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ func processGoogleUserInfo(code string) (models.User, error) {
|
||||
// Extract the ID Token from OAuth2 token.
|
||||
rawIDToken, ok := oauth2Token.Extra("id_token").(string)
|
||||
if !ok {
|
||||
log.Debug("Failed to extract ID Token from OAuth2 token.")
|
||||
log.Debug("Failed to extract ID Token from OAuth2 token")
|
||||
return user, fmt.Errorf("unable to extract id_token")
|
||||
}
|
||||
|
||||
@@ -238,13 +238,13 @@ func processGithubUserInfo(code string) (models.User, error) {
|
||||
user := models.User{}
|
||||
token, err := oauth.OAuthProviders.GithubConfig.Exchange(oauth2.NoContext, code)
|
||||
if err != nil {
|
||||
log.Debug("Failed to exchange code for token:", err)
|
||||
log.Debug("Failed to exchange code for token: ", err)
|
||||
return user, fmt.Errorf("invalid github exchange code: %s", err.Error())
|
||||
}
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest("GET", constants.GithubUserInfoURL, nil)
|
||||
if err != nil {
|
||||
log.Debug("Failed to create github user info request:", err)
|
||||
log.Debug("Failed to create github user info request: ", err)
|
||||
return user, fmt.Errorf("error creating github user info request: %s", err.Error())
|
||||
}
|
||||
req.Header = http.Header{
|
||||
@@ -253,14 +253,14 @@ func processGithubUserInfo(code string) (models.User, error) {
|
||||
|
||||
response, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Debug("Failed to request github user info:", err)
|
||||
log.Debug("Failed to request github user info: ", err)
|
||||
return user, err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
log.Debug("Failed to read github user info response body:", err)
|
||||
log.Debug("Failed to read github user info response body: ", err)
|
||||
return user, fmt.Errorf("failed to read github response body: %s", err.Error())
|
||||
}
|
||||
|
||||
@@ -293,26 +293,26 @@ func processFacebookUserInfo(code string) (models.User, error) {
|
||||
user := models.User{}
|
||||
token, err := oauth.OAuthProviders.FacebookConfig.Exchange(oauth2.NoContext, code)
|
||||
if err != nil {
|
||||
log.Debug("Invalid facebook exchange code:", err)
|
||||
log.Debug("Invalid facebook exchange code: ", err)
|
||||
return user, fmt.Errorf("invalid facebook exchange code: %s", err.Error())
|
||||
}
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest("GET", constants.FacebookUserInfoURL+token.AccessToken, nil)
|
||||
if err != nil {
|
||||
log.Debug("Error creating facebook user info request:", err)
|
||||
log.Debug("Error creating facebook user info request: ", err)
|
||||
return user, fmt.Errorf("error creating facebook user info request: %s", err.Error())
|
||||
}
|
||||
|
||||
response, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Debug("Failed to process facebook user:", err)
|
||||
log.Debug("Failed to process facebook user: ", err)
|
||||
return user, err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
log.Debug("Failed to read facebook response:", err)
|
||||
log.Debug("Failed to read facebook response: ", err)
|
||||
return user, fmt.Errorf("failed to read facebook response body: %s", err.Error())
|
||||
}
|
||||
|
||||
|
@@ -57,6 +57,7 @@ func OAuthLoginHandler() gin.HandlerFunc {
|
||||
// use protected roles verification for admin login only.
|
||||
// though if not associated with user, it will be rejected from oauth_callback
|
||||
if !utils.IsValidRoles(rolesSplit, append([]string{}, append(envstore.EnvStoreObj.GetSliceStoreEnvVariable(constants.EnvKeyRoles), envstore.EnvStoreObj.GetSliceStoreEnvVariable(constants.EnvKeyProtectedRoles)...)...)) {
|
||||
log.Debug("Invalid roles: ", roles)
|
||||
c.JSON(400, gin.H{
|
||||
"error": "invalid role",
|
||||
})
|
||||
|
@@ -38,7 +38,7 @@ func RevokeHandler() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
if clientID != envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyClientID) {
|
||||
log.Debug("Client ID is invalid")
|
||||
log.Debug("Client ID is invalid: ", clientID)
|
||||
gc.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "invalid_client_id",
|
||||
"error_description": "The client id is invalid",
|
||||
|
@@ -46,7 +46,7 @@ func TokenHandler() gin.HandlerFunc {
|
||||
isAuthorizationCodeGrant := grantType == "authorization_code"
|
||||
|
||||
if !isRefreshTokenGrant && !isAuthorizationCodeGrant {
|
||||
log.Debug("Invalid grant type")
|
||||
log.Debug("Invalid grant type: ", grantType)
|
||||
gc.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "invalid_grant_type",
|
||||
"error_description": "grant_type is invalid",
|
||||
@@ -63,7 +63,7 @@ func TokenHandler() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
if clientID != envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyClientID) {
|
||||
log.Debug("Client ID is invalid")
|
||||
log.Debug("Client ID is invalid: ", clientID)
|
||||
gc.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "invalid_client_id",
|
||||
"error_description": "The client id is invalid",
|
||||
@@ -100,7 +100,7 @@ func TokenHandler() gin.HandlerFunc {
|
||||
encryptedCode = strings.ReplaceAll(encryptedCode, "=", "")
|
||||
sessionData := sessionstore.GetState(encryptedCode)
|
||||
if sessionData == "" {
|
||||
log.Debug("Invalid code verifier")
|
||||
log.Debug("Session data is empty")
|
||||
gc.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "invalid_code_verifier",
|
||||
"error_description": "The code verifier is invalid",
|
||||
@@ -113,7 +113,7 @@ func TokenHandler() gin.HandlerFunc {
|
||||
sessionDataSplit := strings.Split(sessionData, "@")
|
||||
|
||||
if sessionDataSplit[0] != code {
|
||||
log.Debug("Invalid code verifier.Unable to split session data")
|
||||
log.Debug("Invalid code verifier. Unable to split session data")
|
||||
gc.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "invalid_code_verifier",
|
||||
"error_description": "The code verifier is invalid",
|
||||
|
Reference in New Issue
Block a user