snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
109
server/auth/request/session.go
Normal file
109
server/auth/request/session.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"github.com/gorilla/sessions"
|
||||
)
|
||||
|
||||
const (
|
||||
keyRememberMe = "remember-me"
|
||||
keyOriginalSession = "originalSession"
|
||||
keyAuthUser = "authUser"
|
||||
keyRoles = "roles"
|
||||
keyOAuth2AuthParams = "oauth2AuthParams"
|
||||
keyOAuth2Client = "oauth2ClientID"
|
||||
keyOAuth2ClientAuthorized = "oauth2ClientAuthorized"
|
||||
)
|
||||
|
||||
// GetUser is wrapper to get value from session
|
||||
func GetAuthUser(ses *sessions.Session) *authUser {
|
||||
val, has := ses.Values[keyAuthUser]
|
||||
if !has {
|
||||
return nil
|
||||
}
|
||||
|
||||
au := val.(*authUser)
|
||||
if au.User != nil {
|
||||
au.User.SetRoles(getRoleMemberships(ses)...)
|
||||
}
|
||||
|
||||
return au
|
||||
}
|
||||
|
||||
// GetRoleMemberships is wrapper to get value from session
|
||||
func getRoleMemberships(ses *sessions.Session) []uint64 {
|
||||
val, has := ses.Values[keyRoles]
|
||||
if !has {
|
||||
return nil
|
||||
}
|
||||
|
||||
return val.([]uint64)
|
||||
}
|
||||
|
||||
// GetOAuth2AuthParams is wrapper to get value from session
|
||||
func GetOAuth2AuthParams(ses *sessions.Session) url.Values {
|
||||
val, has := ses.Values[keyOAuth2AuthParams]
|
||||
if !has {
|
||||
return nil
|
||||
}
|
||||
|
||||
return val.(url.Values)
|
||||
}
|
||||
|
||||
// SetOauth2AuthParams is a session value setting wrapper for Oauth2AuthParams
|
||||
func SetOauth2AuthParams(ses *sessions.Session, val url.Values) {
|
||||
if val != nil {
|
||||
ses.Values[keyOAuth2AuthParams] = val
|
||||
} else {
|
||||
delete(ses.Values, keyOAuth2AuthParams)
|
||||
}
|
||||
}
|
||||
|
||||
// GetOauth2Client is wrapper to get value from session
|
||||
func GetOauth2Client(ses *sessions.Session) *types.AuthClient {
|
||||
val, has := ses.Values[keyOAuth2Client]
|
||||
if !has {
|
||||
return nil
|
||||
}
|
||||
|
||||
return val.(*types.AuthClient)
|
||||
}
|
||||
|
||||
// SetOauth2Client is a session value setting wrapper for Oauth2Client
|
||||
func SetOauth2Client(ses *sessions.Session, val *types.AuthClient) {
|
||||
if val != nil {
|
||||
ses.Values[keyOAuth2Client] = val
|
||||
} else {
|
||||
delete(ses.Values, keyOAuth2Client)
|
||||
}
|
||||
}
|
||||
|
||||
// IsOauth2ClientAuthorized is wrapper to get value from session
|
||||
func IsOauth2ClientAuthorized(ses *sessions.Session) bool {
|
||||
val, has := ses.Values[keyOAuth2ClientAuthorized]
|
||||
if !has {
|
||||
return false
|
||||
}
|
||||
|
||||
return val.(bool)
|
||||
}
|
||||
|
||||
// SetOauth2ClientAuthorized is a session value setting wrapper for Oauth2ClientAuthorized
|
||||
func SetOauth2ClientAuthorized(ses *sessions.Session, val bool) {
|
||||
if val {
|
||||
ses.Values[keyOAuth2ClientAuthorized] = true
|
||||
} else {
|
||||
delete(ses.Values, keyOAuth2ClientAuthorized)
|
||||
}
|
||||
}
|
||||
|
||||
// IsPermLogin decodes remember-me flag from the session and returns true if set
|
||||
func IsPermLogin(ses *sessions.Session) (p bool) {
|
||||
if aux, has := ses.Values[keyRememberMe]; has {
|
||||
p, _ = aux.(bool)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user