Auth: Set the default org after User login (#83918)

* poc

* add logger, skip hook when user is not assigned to default org

* Add tests, move to hook folder

* docs

* Skip for OrgId < 1

* Address feedback

* Update docs/sources/setup-grafana/configure-grafana/_index.md

* lint

* Move the hook to org_sync.go

* Update pkg/services/authn/authnimpl/sync/org_sync.go

* Handle the case when GetUserOrgList returns error

---------

Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
Co-authored-by: Karl Persson <kalle.persson@grafana.com>
This commit is contained in:
Misi
2024-03-12 09:35:13 +01:00
committed by GitHub
co-authored by Christopher Moyer Karl Persson
parent 8c06c0dea7
commit 63f1c30313
9 changed files with 687 additions and 6 deletions
+3 -1
View File
@@ -147,7 +147,7 @@ func ProvideService(
// FIXME (jguer): move to User package
userSyncService := sync.ProvideUserSync(userService, userProtectionService, authInfoService, quotaService)
orgUserSyncService := sync.ProvideOrgSync(userService, orgService, accessControlService)
orgUserSyncService := sync.ProvideOrgSync(userService, orgService, accessControlService, cfg)
s.RegisterPostAuthHook(userSyncService.SyncUserHook, 10)
s.RegisterPostAuthHook(userSyncService.EnableUserHook, 20)
s.RegisterPostAuthHook(orgUserSyncService.SyncOrgRolesHook, 30)
@@ -162,6 +162,8 @@ func ProvideService(
s.RegisterPostAuthHook(rbacSync.SyncPermissionsHook, 120)
s.RegisterPostAuthHook(orgUserSyncService.SetDefaultOrgHook, 130)
return s
}