centralize oauth http calls, validate response status (#8470)

This commit is contained in:
Dan Cech
2017-05-26 14:35:32 +02:00
committed by Torkel Ödegaard
parent 60d5d5fb15
commit 8422697199
7 changed files with 100 additions and 101 deletions
+7
View File
@@ -28,6 +28,7 @@ var (
ErrEmailNotAllowed = errors.New("Required email domain not fulfilled")
ErrSignUpNotAllowed = errors.New("Signup is not allowed for this adapter")
ErrUsersQuotaReached = errors.New("Users quota reached")
ErrNoEmail = errors.New("Login provider didn't return an email address")
)
func GenStateString() string {
@@ -134,6 +135,12 @@ func OAuthLogin(ctx *middleware.Context) {
ctx.Logger.Debug("OAuthLogin got user info", "userInfo", userInfo)
// validate that we got at least an email address
if userInfo.Email == "" {
redirectWithError(ctx, ErrNoEmail)
return
}
// validate that the email is allowed to login to grafana
if !connect.IsEmailAllowed(userInfo.Email) {
redirectWithError(ctx, ErrEmailNotAllowed)