@@ -21,6 +21,54 @@ import (
2121 "github.com/authorizerdev/authorizer/server/utils"
2222)
2323
24+ // check if login methods have been disabled
25+ // remove the session tokens for those methods
26+ func clearSessionIfRequired (currentData , updatedData map [string ]interface {}) {
27+ isCurrentBasicAuthEnabled := ! currentData [constants .EnvKeyDisableBasicAuthentication ].(bool )
28+ isCurrentMagicLinkLoginEnabled := ! currentData [constants .EnvKeyDisableMagicLinkLogin ].(bool )
29+ isCurrentAppleLoginEnabled := currentData [constants .EnvKeyAppleClientID ] != nil && currentData [constants .EnvKeyAppleClientSecret ] != nil && currentData [constants .EnvKeyAppleClientID ].(string ) != "" && currentData [constants .EnvKeyAppleClientSecret ].(string ) != ""
30+ isCurrentFacebookLoginEnabled := currentData [constants .EnvKeyFacebookClientID ] != nil && currentData [constants .EnvKeyFacebookClientSecret ] != nil && currentData [constants .EnvKeyFacebookClientID ].(string ) != "" && currentData [constants .EnvKeyFacebookClientSecret ].(string ) != ""
31+ isCurrentGoogleLoginEnabled := currentData [constants .EnvKeyGoogleClientID ] != nil && currentData [constants .EnvKeyGoogleClientSecret ] != nil && currentData [constants .EnvKeyGoogleClientID ].(string ) != "" && currentData [constants .EnvKeyGoogleClientSecret ].(string ) != ""
32+ isCurrentGithubLoginEnabled := currentData [constants .EnvKeyGithubClientID ] != nil && currentData [constants .EnvKeyGithubClientSecret ] != nil && currentData [constants .EnvKeyGithubClientID ].(string ) != "" && currentData [constants .EnvKeyGithubClientSecret ].(string ) != ""
33+ isCurrentLinkedInLoginEnabled := currentData [constants .EnvKeyLinkedInClientID ] != nil && currentData [constants .EnvKeyLinkedInClientSecret ] != nil && currentData [constants .EnvKeyLinkedInClientID ].(string ) != "" && currentData [constants .EnvKeyLinkedInClientSecret ].(string ) != ""
34+
35+ isUpdatedBasicAuthEnabled := ! updatedData [constants .EnvKeyDisableBasicAuthentication ].(bool )
36+ isUpdatedMagicLinkLoginEnabled := ! updatedData [constants .EnvKeyDisableMagicLinkLogin ].(bool )
37+ isUpdatedAppleLoginEnabled := updatedData [constants .EnvKeyAppleClientID ] != nil && updatedData [constants .EnvKeyAppleClientSecret ] != nil && updatedData [constants .EnvKeyAppleClientID ].(string ) != "" && updatedData [constants .EnvKeyAppleClientSecret ].(string ) != ""
38+ isUpdatedFacebookLoginEnabled := updatedData [constants .EnvKeyFacebookClientID ] != nil && updatedData [constants .EnvKeyFacebookClientSecret ] != nil && updatedData [constants .EnvKeyFacebookClientID ].(string ) != "" && updatedData [constants .EnvKeyFacebookClientSecret ].(string ) != ""
39+ isUpdatedGoogleLoginEnabled := updatedData [constants .EnvKeyGoogleClientID ] != nil && updatedData [constants .EnvKeyGoogleClientSecret ] != nil && updatedData [constants .EnvKeyGoogleClientID ].(string ) != "" && updatedData [constants .EnvKeyGoogleClientSecret ].(string ) != ""
40+ isUpdatedGithubLoginEnabled := updatedData [constants .EnvKeyGithubClientID ] != nil && updatedData [constants .EnvKeyGithubClientSecret ] != nil && updatedData [constants .EnvKeyGithubClientID ].(string ) != "" && updatedData [constants .EnvKeyGithubClientSecret ].(string ) != ""
41+ isUpdatedLinkedInLoginEnabled := updatedData [constants .EnvKeyLinkedInClientID ] != nil && updatedData [constants .EnvKeyLinkedInClientSecret ] != nil && updatedData [constants .EnvKeyLinkedInClientID ].(string ) != "" && updatedData [constants .EnvKeyLinkedInClientSecret ].(string ) != ""
42+
43+ if isCurrentBasicAuthEnabled && ! isUpdatedBasicAuthEnabled {
44+ memorystore .Provider .DeleteSessionForNamespace (constants .AuthRecipeMethodBasicAuth )
45+ }
46+
47+ if isCurrentMagicLinkLoginEnabled && ! isUpdatedMagicLinkLoginEnabled {
48+ memorystore .Provider .DeleteSessionForNamespace (constants .AuthRecipeMethodMagicLinkLogin )
49+ }
50+
51+ if isCurrentAppleLoginEnabled && ! isUpdatedAppleLoginEnabled {
52+ memorystore .Provider .DeleteSessionForNamespace (constants .AuthRecipeMethodApple )
53+ }
54+
55+ if isCurrentFacebookLoginEnabled && ! isUpdatedFacebookLoginEnabled {
56+ memorystore .Provider .DeleteSessionForNamespace (constants .AuthRecipeMethodFacebook )
57+ }
58+
59+ if isCurrentGoogleLoginEnabled && ! isUpdatedGoogleLoginEnabled {
60+ memorystore .Provider .DeleteSessionForNamespace (constants .AuthRecipeMethodGoogle )
61+ }
62+
63+ if isCurrentGithubLoginEnabled && ! isUpdatedGithubLoginEnabled {
64+ memorystore .Provider .DeleteSessionForNamespace (constants .AuthRecipeMethodGithub )
65+ }
66+
67+ if isCurrentLinkedInLoginEnabled && ! isUpdatedLinkedInLoginEnabled {
68+ memorystore .Provider .DeleteSessionForNamespace (constants .AuthRecipeMethodLinkedIn )
69+ }
70+ }
71+
2472// UpdateEnvResolver is a resolver for update config mutation
2573// This is admin only mutation
2674func UpdateEnvResolver (ctx context.Context , params model.UpdateEnvInput ) (* model.Response , error ) {
@@ -37,12 +85,19 @@ func UpdateEnvResolver(ctx context.Context, params model.UpdateEnvInput) (*model
3785 return res , fmt .Errorf ("unauthorized" )
3886 }
3987
40- updatedData , err := memorystore .Provider .GetEnvStore ()
88+ currentData , err := memorystore .Provider .GetEnvStore ()
4189 if err != nil {
4290 log .Debug ("Failed to get env store: " , err )
4391 return res , err
4492 }
4593
94+ // clone currentData in new var
95+ // that will be updated based on the req
96+ updatedData := make (map [string ]interface {})
97+ for key , val := range currentData {
98+ updatedData [key ] = val
99+ }
100+
46101 isJWTUpdated := false
47102 algo := updatedData [constants .EnvKeyJwtType ].(string )
48103 if params .JwtType != nil {
@@ -210,6 +265,8 @@ func UpdateEnvResolver(ctx context.Context, params model.UpdateEnvInput) (*model
210265 }
211266 }
212267
268+ go clearSessionIfRequired (currentData , updatedData )
269+
213270 // Update local store
214271 memorystore .Provider .UpdateEnvStore (updatedData )
215272 jwk , err := crypto .GenerateJWKBasedOnEnv ()
@@ -224,12 +281,6 @@ func UpdateEnvResolver(ctx context.Context, params model.UpdateEnvInput) (*model
224281 return res , err
225282 }
226283
227- // TODO check how to update session store based on env change.
228- // err = sessionstore.InitSession()
229- // if err != nil {
230- // log.Debug("Failed to init session store: ", err)
231- // return res, err
232- // }
233284 err = oauth .InitOAuth ()
234285 if err != nil {
235286 return res , err
0 commit comments