mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-20 04:55:32 +00:00
bugfix: Crash in OAuth2 userdata, and option to log user data (#631)
This commit is contained in:
@@ -138,6 +138,7 @@ type Config struct {
|
|||||||
CronSupportForSeconds bool
|
CronSupportForSeconds bool
|
||||||
SectionNavigationStyle string
|
SectionNavigationStyle string
|
||||||
DefaultPopupOnStart string
|
DefaultPopupOnStart string
|
||||||
|
InsecureAllowDumpOAuth2UserData bool
|
||||||
InsecureAllowDumpVars bool
|
InsecureAllowDumpVars bool
|
||||||
InsecureAllowDumpSos bool
|
InsecureAllowDumpSos bool
|
||||||
InsecureAllowDumpActionMap bool
|
InsecureAllowDumpActionMap bool
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ func handleOAuthCallback(w http.ResponseWriter, r *http.Request) {
|
|||||||
Timeout: clientSettings.Timeout,
|
Timeout: clientSettings.Timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
userinfo := getUserInfo(userInfoClient, cfg.AuthOAuth2Providers[registeredState.providerName])
|
userinfo := getUserInfo(cfg, userInfoClient, cfg.AuthOAuth2Providers[registeredState.providerName])
|
||||||
|
|
||||||
registeredStates[state].Username = userinfo.Username
|
registeredStates[state].Username = userinfo.Username
|
||||||
registeredStates[state].Usergroup = userinfo.Usergroup
|
registeredStates[state].Usergroup = userinfo.Usergroup
|
||||||
@@ -274,7 +274,7 @@ type UserInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//gocyclo:ignore
|
//gocyclo:ignore
|
||||||
func getUserInfo(client *http.Client, provider *config.OAuth2Provider) *UserInfo {
|
func getUserInfo(cfg *config.Config, client *http.Client, provider *config.OAuth2Provider) *UserInfo {
|
||||||
ret := &UserInfo{}
|
ret := &UserInfo{}
|
||||||
|
|
||||||
res, err := client.Get(provider.WhoamiUrl)
|
res, err := client.Get(provider.WhoamiUrl)
|
||||||
@@ -300,6 +300,10 @@ func getUserInfo(client *http.Client, provider *config.OAuth2Provider) *UserInfo
|
|||||||
|
|
||||||
var userData map[string]any
|
var userData map[string]any
|
||||||
|
|
||||||
|
if cfg.InsecureAllowDumpOAuth2UserData {
|
||||||
|
log.Debugf("OAuth2 User Data: %v+", string(contents))
|
||||||
|
}
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(contents), &userData)
|
err = json.Unmarshal([]byte(contents), &userData)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -327,7 +331,14 @@ func getDataField(data map[string]any, field string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return val.(string)
|
stringVal, ok := val.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
log.Errorf("Field %v is not a string: %v", field, val)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseOAuth2Cookie(r *http.Request) (string, string, string) {
|
func parseOAuth2Cookie(r *http.Request) (string, string, string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user