-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
providers/proxy: add custom signal on logout to logout in provider
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
- Loading branch information
Showing
9 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Proxy provider signals""" | ||
from django.contrib.auth.signals import user_logged_out | ||
from django.db.models.signals import pre_delete | ||
from django.dispatch import receiver | ||
from django.http import HttpRequest | ||
|
||
from authentik.core.models import AuthenticatedSession, User | ||
from authentik.providers.proxy.tasks import proxy_on_logout | ||
|
||
|
||
@receiver(user_logged_out) | ||
def logout_proxy_revoke_direct(sender: type[User], request: HttpRequest, **_): | ||
"""Catch logout by direct logout and forward to proxy providers""" | ||
proxy_on_logout.delay(request.session.session_key) | ||
|
||
|
||
@receiver(pre_delete, sender=AuthenticatedSession) | ||
def logout_proxy_revoke(sender: type[AuthenticatedSession], instance: AuthenticatedSession, **_): | ||
"""Catch logout by expiring sessions being deleted""" | ||
proxy_on_logout.delay(instance.session_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package proxyv2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
"goauthentik.io/internal/outpost/proxyv2/application" | ||
) | ||
|
||
type WSProviderSubType string | ||
|
||
const ( | ||
WSProviderSubTypeLogout WSProviderSubType = "logout" | ||
) | ||
|
||
type WSProviderMsg struct { | ||
SubType WSProviderSubType `mapstructure:"sub_type"` | ||
SessionID string `mapstructure:"session_id"` | ||
} | ||
|
||
func ParseWSProvider(args map[string]interface{}) (*WSProviderMsg, error) { | ||
msg := &WSProviderMsg{} | ||
err := mapstructure.Decode(args, &msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return msg, nil | ||
} | ||
|
||
func (ps *ProxyServer) handleWSMessage(ctx context.Context, args map[string]interface{}) { | ||
msg, err := ParseWSProvider(args) | ||
if err != nil { | ||
ps.log.WithError(err).Warning("invalid provider-specific ws message") | ||
return | ||
} | ||
switch msg.SubType { | ||
case WSProviderSubTypeLogout: | ||
for _, p := range ps.apps { | ||
err := p.Logout(ctx, func(c application.Claims) bool { | ||
return c.Sid == msg.SessionID | ||
}) | ||
if err != nil { | ||
ps.log.WithField("provider", p.Host).WithError(err).Warning("failed to logout") | ||
} | ||
} | ||
default: | ||
ps.log.WithField("sub_type", msg.SubType).Warning("invalid sub_type") | ||
} | ||
} |