2023-07-10 13:27:00 +00:00
|
|
|
package domain
|
|
|
|
|
2024-05-16 05:07:56 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
|
|
)
|
|
|
|
|
2023-07-10 13:27:00 +00:00
|
|
|
type OIDCErrorReason int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
OIDCErrorReasonUnspecified OIDCErrorReason = iota
|
|
|
|
OIDCErrorReasonInvalidRequest
|
|
|
|
OIDCErrorReasonUnauthorizedClient
|
|
|
|
OIDCErrorReasonAccessDenied
|
|
|
|
OIDCErrorReasonUnsupportedResponseType
|
|
|
|
OIDCErrorReasonInvalidScope
|
|
|
|
OIDCErrorReasonServerError
|
|
|
|
OIDCErrorReasonTemporaryUnavailable
|
|
|
|
OIDCErrorReasonInteractionRequired
|
|
|
|
OIDCErrorReasonLoginRequired
|
|
|
|
OIDCErrorReasonAccountSelectionRequired
|
|
|
|
OIDCErrorReasonConsentRequired
|
|
|
|
OIDCErrorReasonInvalidRequestURI
|
|
|
|
OIDCErrorReasonInvalidRequestObject
|
|
|
|
OIDCErrorReasonRequestNotSupported
|
|
|
|
OIDCErrorReasonRequestURINotSupported
|
|
|
|
OIDCErrorReasonRegistrationNotSupported
|
2024-05-16 05:07:56 +00:00
|
|
|
OIDCErrorReasonInvalidGrant
|
2023-07-10 13:27:00 +00:00
|
|
|
)
|
2024-05-16 05:07:56 +00:00
|
|
|
|
|
|
|
func OIDCErrorReasonFromError(err error) OIDCErrorReason {
|
|
|
|
if errors.Is(err, oidc.ErrInvalidRequest()) {
|
|
|
|
return OIDCErrorReasonInvalidRequest
|
|
|
|
}
|
|
|
|
if errors.Is(err, oidc.ErrInvalidGrant()) {
|
|
|
|
return OIDCErrorReasonInvalidGrant
|
|
|
|
}
|
|
|
|
if zerrors.IsPreconditionFailed(err) {
|
|
|
|
return OIDCErrorReasonAccessDenied
|
|
|
|
}
|
|
|
|
if zerrors.IsInternal(err) {
|
|
|
|
return OIDCErrorReasonServerError
|
|
|
|
}
|
|
|
|
return OIDCErrorReasonUnspecified
|
|
|
|
}
|