Improve logging for OAuth2 callback
This commit is contained in:
parent
f06a19814b
commit
dc8668b904
2 changed files with 14 additions and 2 deletions
|
@ -4,9 +4,17 @@
|
||||||
|
|
||||||
package oauth2 // import "miniflux.app/oauth2"
|
package oauth2 // import "miniflux.app/oauth2"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
// Profile is the OAuth2 user profile.
|
// Profile is the OAuth2 user profile.
|
||||||
type Profile struct {
|
type Profile struct {
|
||||||
Key string
|
Key string
|
||||||
ID string
|
ID string
|
||||||
Username string
|
Username string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Profile) String() string {
|
||||||
|
return fmt.Sprintf(`ID=%s ; Username=%s`, p.ID, p.Username)
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
|
|
||||||
// OAuth2Callback receives the authorization code and create a new session.
|
// OAuth2Callback receives the authorization code and create a new session.
|
||||||
func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
||||||
|
clientIP := request.ClientIP(r)
|
||||||
printer := locale.NewPrinter(request.UserLanguage(r))
|
printer := locale.NewPrinter(request.UserLanguage(r))
|
||||||
sess := session.New(c.store, request.SessionID(r))
|
sess := session.New(c.store, request.SessionID(r))
|
||||||
|
|
||||||
|
@ -57,6 +58,8 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Info("[OAuth2] [ClientIP=%s] Successful auth for %s", clientIP, profile)
|
||||||
|
|
||||||
if request.IsAuthenticated(r) {
|
if request.IsAuthenticated(r) {
|
||||||
user, err := c.store.UserByExtraField(profile.Key, profile.ID)
|
user, err := c.store.UserByExtraField(profile.Key, profile.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,13 +107,14 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionToken, _, err := c.store.CreateUserSession(user.Username, r.UserAgent(), request.ClientIP(r))
|
sessionToken, _, err := c.store.CreateUserSession(user.Username, r.UserAgent(), clientIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
html.ServerError(w, r, err)
|
html.ServerError(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("[Controller:OAuth2Callback] username=%s just logged in", user.Username)
|
logger.Info("[OAuth2] [ClientIP=%s] username=%s (%s) just logged in", clientIP, user.Username, profile)
|
||||||
|
|
||||||
c.store.SetLastLogin(user.ID)
|
c.store.SetLastLogin(user.ID)
|
||||||
sess.SetLanguage(user.Language)
|
sess.SetLanguage(user.Language)
|
||||||
sess.SetTheme(user.Theme)
|
sess.SetTheme(user.Theme)
|
||||||
|
|
Loading…
Reference in a new issue