Files
grafana/pkg/login/social/errors.go
T
Karl Persson 052d1426f9 Oauth: Display friendly error message when role_attribute_strict=true and no valid role found (#57818)
* Oauth: change error type to a struct that unwraps into a social error

* Oauth: Handle empty role in error and fix unwrap

* Oauth: provide more informatio in error

* Oauth: return InvalidBasicRoleError

* Oauth: Fix tests

* Login: Remove casing

* Oath: Change to warning logs
2022-10-31 09:11:31 +01:00

31 lines
676 B
Go

package social
import (
"errors"
"fmt"
)
var (
ErrIDTokenNotFound = errors.New("id_token not found")
ErrEmailNotFound = errors.New("error getting user info: no email found in access token")
)
type InvalidBasicRoleError struct {
idP string
assignedRole string
}
func (e *InvalidBasicRoleError) Error() string {
withFallback := func(v, fallback string) string {
if v == "" {
return fallback
}
return v
}
return fmt.Sprintf("Integration requires a valid org role assigned in %s. Assigned role: %s", withFallback(e.idP, "idP"), withFallback(e.assignedRole, "\" \""))
}
func (e *InvalidBasicRoleError) Unwrap() error {
return &Error{e.Error()}
}