mirror of
https://github.com/Luzifer/nginx-sso.git
synced 2024-12-20 21:01:17 +00:00
Pass through the ResponseWriter to allow cookie renewal
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
9af5d1e6d3
commit
c9836b032a
5 changed files with 8 additions and 8 deletions
|
@ -53,7 +53,7 @@ func (a *authSimple) Configure(yamlSource []byte) error {
|
||||||
// a cookie, header or other methods
|
// a cookie, header or other methods
|
||||||
// If no user was detected the errNoValidUserFound needs to be
|
// If no user was detected the errNoValidUserFound needs to be
|
||||||
// returned
|
// returned
|
||||||
func (a authSimple) DetectUser(r *http.Request) (string, []string, error) {
|
func (a authSimple) DetectUser(res http.ResponseWriter, r *http.Request) (string, []string, error) {
|
||||||
var user string
|
var user string
|
||||||
|
|
||||||
if a.EnableBasicAuth {
|
if a.EnableBasicAuth {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (a *authToken) Configure(yamlSource []byte) error {
|
||||||
// a cookie, header or other methods
|
// a cookie, header or other methods
|
||||||
// If no user was detected the errNoValidUserFound needs to be
|
// If no user was detected the errNoValidUserFound needs to be
|
||||||
// returned
|
// returned
|
||||||
func (a authToken) DetectUser(r *http.Request) (string, []string, error) {
|
func (a authToken) DetectUser(res http.ResponseWriter, r *http.Request) (string, []string, error) {
|
||||||
authHeader := r.Header.Get("Authorization")
|
authHeader := r.Header.Get("Authorization")
|
||||||
|
|
||||||
if !strings.HasPrefix(authHeader, "Token ") {
|
if !strings.HasPrefix(authHeader, "Token ") {
|
||||||
|
|
|
@ -55,7 +55,7 @@ func (a *authYubikey) Configure(yamlSource []byte) error {
|
||||||
// a cookie, header or other methods
|
// a cookie, header or other methods
|
||||||
// If no user was detected the errNoValidUserFound needs to be
|
// If no user was detected the errNoValidUserFound needs to be
|
||||||
// returned
|
// returned
|
||||||
func (a authYubikey) DetectUser(r *http.Request) (string, []string, error) {
|
func (a authYubikey) DetectUser(res http.ResponseWriter, r *http.Request) (string, []string, error) {
|
||||||
sess, err := cookieStore.Get(r, strings.Join([]string{mainCfg.Cookie.Prefix, a.AuthenticatorID()}, "-"))
|
sess, err := cookieStore.Get(r, strings.Join([]string{mainCfg.Cookie.Prefix, a.AuthenticatorID()}, "-"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, errNoValidUserFound
|
return "", nil, errNoValidUserFound
|
||||||
|
|
4
main.go
4
main.go
|
@ -106,7 +106,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleAuthRequest(res http.ResponseWriter, r *http.Request) {
|
func handleAuthRequest(res http.ResponseWriter, r *http.Request) {
|
||||||
user, groups, err := detectUser(r)
|
user, groups, err := detectUser(res, r)
|
||||||
|
|
||||||
switch err {
|
switch err {
|
||||||
case errNoValidUserFound:
|
case errNoValidUserFound:
|
||||||
|
@ -128,7 +128,7 @@ func handleAuthRequest(res http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleLoginRequest(res http.ResponseWriter, r *http.Request) {
|
func handleLoginRequest(res http.ResponseWriter, r *http.Request) {
|
||||||
if _, _, err := detectUser(r); err == nil {
|
if _, _, err := detectUser(res, r); err == nil {
|
||||||
// There is already a valid user
|
// There is already a valid user
|
||||||
http.Redirect(res, r, r.URL.Query().Get("go"), http.StatusFound)
|
http.Redirect(res, r, r.URL.Query().Get("go"), http.StatusFound)
|
||||||
return
|
return
|
||||||
|
|
|
@ -24,7 +24,7 @@ type authenticator interface {
|
||||||
// a cookie, header or other methods
|
// a cookie, header or other methods
|
||||||
// If no user was detected the errNoValidUserFound needs to be
|
// If no user was detected the errNoValidUserFound needs to be
|
||||||
// returned
|
// returned
|
||||||
DetectUser(r *http.Request) (user string, groups []string, err error)
|
DetectUser(res http.ResponseWriter, r *http.Request) (user string, groups []string, err error)
|
||||||
|
|
||||||
// Login is called when the user submits the login form and needs
|
// Login is called when the user submits the login form and needs
|
||||||
// to authenticate the user or throw an error. If the user has
|
// to authenticate the user or throw an error. If the user has
|
||||||
|
@ -94,12 +94,12 @@ func initializeAuthenticators(yamlSource []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func detectUser(r *http.Request) (string, []string, error) {
|
func detectUser(res http.ResponseWriter, r *http.Request) (string, []string, error) {
|
||||||
authenticatorRegistryMutex.RLock()
|
authenticatorRegistryMutex.RLock()
|
||||||
defer authenticatorRegistryMutex.RUnlock()
|
defer authenticatorRegistryMutex.RUnlock()
|
||||||
|
|
||||||
for _, a := range activeAuthenticators {
|
for _, a := range activeAuthenticators {
|
||||||
user, groups, err := a.DetectUser(r)
|
user, groups, err := a.DetectUser(res, r)
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
return user, groups, err
|
return user, groups, err
|
||||||
|
|
Loading…
Reference in a new issue