mirror of
https://github.com/tinyauthapp/tinyauth.git
synced 2026-08-11 19:43:43 +08:00
feat: experimental option to run tinyauth in oauth bridge mode (#1027)
This commit is contained in:
@@ -40,6 +40,7 @@ var (
|
||||
type ContextMiddleware struct {
|
||||
log *logger.Logger
|
||||
runtime *model.RuntimeConfig
|
||||
config *model.Config
|
||||
auth *service.AuthService
|
||||
broker *service.OAuthBrokerService
|
||||
tailscale *service.TailscaleService
|
||||
@@ -50,6 +51,7 @@ type ContextMiddlewareInput struct {
|
||||
|
||||
Log *logger.Logger
|
||||
RuntimeConfig *model.RuntimeConfig
|
||||
StaticConfig *model.Config
|
||||
AuthService *service.AuthService
|
||||
BrokerService *service.OAuthBrokerService
|
||||
TailscaleService *service.TailscaleService
|
||||
@@ -59,6 +61,7 @@ func NewContextMiddleware(i ContextMiddlewareInput) *ContextMiddleware {
|
||||
return &ContextMiddleware{
|
||||
log: i.Log,
|
||||
runtime: i.RuntimeConfig,
|
||||
config: i.StaticConfig,
|
||||
auth: i.AuthService,
|
||||
broker: i.BrokerService,
|
||||
tailscale: i.TailscaleService,
|
||||
@@ -332,16 +335,19 @@ func (m *ContextMiddleware) tailscaleWhois(ip string) (*model.TailscaleContext,
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
username := strings.Replace(whois.LoginName, "@", "_", 1)
|
||||
|
||||
uctx := model.TailscaleContext{
|
||||
BaseContext: model.BaseContext{
|
||||
Username: username,
|
||||
Email: whois.LoginName,
|
||||
Name: whois.DisplayName,
|
||||
Email: whois.LoginName,
|
||||
Name: whois.DisplayName,
|
||||
},
|
||||
NodeName: whois.NodeName,
|
||||
}
|
||||
|
||||
if m.config.Experimental.OAuthBridgeEnabled {
|
||||
uctx.BaseContext.Username = strings.SplitN(whois.LoginName, "@", 2)[0]
|
||||
} else {
|
||||
uctx.BaseContext.Username = strings.Replace(whois.LoginName, "@", "_", 1)
|
||||
}
|
||||
|
||||
return &uctx, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user