diff --git a/app/oauth.go b/app/oauth.go index e1e02f929b..85e6769fd5 100644 --- a/app/oauth.go +++ b/app/oauth.go @@ -18,6 +18,7 @@ import ( "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" ) @@ -558,6 +559,27 @@ func (a *App) LoginByOAuth(service string, userData io.Reader, teamId string) (* return nil, err } + if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil { + var rejectionReason string + pluginContext := a.PluginContext() + pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + rejectionReason = hooks.UserWillLogIn(pluginContext, user) + return rejectionReason == "" + }, plugin.UserWillLogInId) + + if rejectionReason != "" { + return nil, model.NewAppError("LoginByOAuth", "Login rejected by plugin: "+rejectionReason, nil, "", http.StatusBadRequest) + } + + a.Srv.Go(func() { + pluginContext := a.PluginContext() + pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + hooks.UserHasLoggedIn(pluginContext, user) + return true + }, plugin.UserHasLoggedInId) + }) + } + return user, nil }