1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-02 16:38:37 +00:00

Google Reader: Cosmetic improvements

This commit is contained in:
Frédéric Guillot 2022-01-02 20:12:29 -08:00
parent 4b6e46d9ab
commit 0b3c3a1f28
7 changed files with 98 additions and 83 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2018 Frédéric Guillot. All rights reserved.
// Copyright 2022 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
@ -34,7 +34,7 @@ func (m *middleware) clientLogin(w http.ResponseWriter, r *http.Request) {
var integration *model.Integration
err := r.ParseForm()
if err != nil {
logger.Error("[Reader][Login] [ClientIP=%s] Could not parse form", clientIP)
logger.Error("[GoogleReader][Login] [ClientIP=%s] Could not parse form", clientIP)
json.Unauthorized(w, r)
return
}
@ -43,21 +43,21 @@ func (m *middleware) clientLogin(w http.ResponseWriter, r *http.Request) {
output = r.Form.Get("output")
if username == "" || password == "" {
logger.Error("[Reader][Login] [ClientIP=%s] Empty username or password", clientIP)
logger.Error("[GoogleReader][Login] [ClientIP=%s] Empty username or password", clientIP)
json.Unauthorized(w, r)
return
}
if err = m.store.GoogleReaderUserCheckPassword(username, password); err != nil {
logger.Error("[Reader][Login] [ClientIP=%s] Invalid username or password: %s", clientIP, username)
logger.Error("[GoogleReader][Login] [ClientIP=%s] Invalid username or password: %s", clientIP, username)
json.Unauthorized(w, r)
return
}
logger.Info("[Reader][Login] [ClientIP=%s] User authenticated: %s", clientIP, username)
logger.Info("[GoogleReader][Login] [ClientIP=%s] User authenticated: %s", clientIP, username)
if integration, err = m.store.GoogleReaderUserGetIntegration(username); err != nil {
logger.Error("[Reader][Login] [ClientIP=%s] Could not load integration: %s", clientIP, username)
logger.Error("[GoogleReader][Login] [ClientIP=%s] Could not load integration: %s", clientIP, username)
json.Unauthorized(w, r)
return
}
@ -65,7 +65,7 @@ func (m *middleware) clientLogin(w http.ResponseWriter, r *http.Request) {
m.store.SetLastLogin(integration.UserID)
token := getAuthToken(integration.GoogleReaderUsername, integration.GoogleReaderPassword)
logger.Info("[Reader][Login] [ClientIP=%s] Created token: %s", clientIP, token)
logger.Info("[GoogleReader][Login] [ClientIP=%s] Created token: %s", clientIP, token)
result := login{SID: token, LSID: token, Auth: token}
if output == "json" {
json.OK(w, r, result)
@ -81,17 +81,17 @@ func (m *middleware) token(w http.ResponseWriter, r *http.Request) {
clientIP := request.ClientIP(r)
if !request.IsAuthenticated(r) {
logger.Error("[Reader][Token] [ClientIP=%s] User is not authenticated", clientIP)
logger.Error("[GoogleReader][Token] [ClientIP=%s] User is not authenticated", clientIP)
json.Unauthorized(w, r)
return
}
token := request.GoolgeReaderToken(r)
if token == "" {
logger.Error("[Reader][Token] [ClientIP=%s] User does not have token: %s", clientIP, request.UserID(r))
logger.Error("[GoogleReader][Token] [ClientIP=%s] User does not have token: %s", clientIP, request.UserID(r))
json.Unauthorized(w, r)
return
}
logger.Info("[Reader][Token] [ClientIP=%s] token: %s", clientIP, token)
logger.Info("[GoogleReader][Token] [ClientIP=%s] token: %s", clientIP, token)
w.Header().Add("Content-Type", "text/plain; charset=UTF-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(token))
@ -118,13 +118,13 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
if r.Method == http.MethodPost {
err := r.ParseForm()
if err != nil {
logger.Error("[Reader][Login] [ClientIP=%s] Could not parse form", clientIP)
logger.Error("[GoogleReader][Login] [ClientIP=%s] Could not parse form", clientIP)
Unauthorized(w, r)
return
}
token = r.Form.Get("T")
if token == "" {
logger.Error("[Reader][Auth] [ClientIP=%s] Post-Form T field is empty", clientIP)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Post-Form T field is empty", clientIP)
Unauthorized(w, r)
return
}
@ -132,29 +132,29 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
authorization := r.Header.Get("Authorization")
if authorization == "" {
logger.Error("[Reader][Auth] [ClientIP=%s] No token provided", clientIP)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] No token provided", clientIP)
Unauthorized(w, r)
return
}
fields := strings.Fields(authorization)
if len(fields) != 2 {
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
Unauthorized(w, r)
return
}
if fields[0] != "GoogleLogin" {
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not begin with GoogleLogin - '%s'", clientIP, authorization)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not begin with GoogleLogin - '%s'", clientIP, authorization)
Unauthorized(w, r)
return
}
auths := strings.Split(fields[1], "=")
if len(auths) != 2 {
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
Unauthorized(w, r)
return
}
if auths[0] != "auth" {
logger.Error("[Reader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Authorization header does not have the expected structure GoogleLogin auth=xxxxxx - '%s'", clientIP, authorization)
Unauthorized(w, r)
return
}
@ -163,7 +163,7 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
parts := strings.Split(token, "/")
if len(parts) != 2 {
logger.Error("[Reader][Auth] [ClientIP=%s] Auth token does not have the expected structure username/hash - '%s'", clientIP, token)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Auth token does not have the expected structure username/hash - '%s'", clientIP, token)
Unauthorized(w, r)
return
}
@ -171,19 +171,19 @@ func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
var user *model.User
var err error
if integration, err = m.store.GoogleReaderUserGetIntegration(parts[0]); err != nil {
logger.Error("[Reader][Auth] [ClientIP=%s] token: %s", clientIP, token)
logger.Error("[Reader][Auth] [ClientIP=%s] No user found with the given google reader username: %s", clientIP, parts[0])
logger.Error("[GoogleReader][Auth] [ClientIP=%s] token: %s", clientIP, token)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] No user found with the given google reader username: %s", clientIP, parts[0])
Unauthorized(w, r)
return
}
expectedToken := getAuthToken(integration.GoogleReaderUsername, integration.GoogleReaderPassword)
if expectedToken != token {
logger.Error("[Reader][Auth] [ClientIP=%s] Token does not match: %s", clientIP, token)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] Token does not match: %s", clientIP, token)
Unauthorized(w, r)
return
}
if user, err = m.store.UserByID(integration.UserID); err != nil {
logger.Error("[Reader][Auth] [ClientIP=%s] No user found with the userID: %d", clientIP, integration.UserID)
logger.Error("[GoogleReader][Auth] [ClientIP=%s] No user found with the userID: %d", clientIP, integration.UserID)
Unauthorized(w, r)
return
}