2020-11-26 02:25:57 +00:00
// Vikunja is a to-do list application to facilitate your life.
2021-05-18 03:09:32 +00:00
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
2020-11-26 02:25:57 +00:00
//
// This program is free software: you can redistribute it and/or modify
2021-05-18 03:09:32 +00:00
// it under the terms of the GNU Affero General Public Licensee as published by
2020-11-26 02:25:57 +00:00
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2021-05-18 03:09:32 +00:00
// GNU Affero General Public Licensee for more details.
2020-11-26 02:25:57 +00:00
//
2021-05-18 03:09:32 +00:00
// You should have received a copy of the GNU Affero General Public Licensee
2020-11-26 02:25:57 +00:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package identityawareproxy
import (
"fmt"
"net/http"
"code.vikunja.io/web"
)
// ErrIAPTokenMissing represents a "IAPTokenMissing" kind of error.
type ErrIAPTokenMissing struct {
Header string
}
// IsErrIAPTokenMissing checks if an error is a ErrIAPTokenMissing.
func IsErrIAPTokenMissing ( err error ) bool {
_ , ok := err . ( ErrIAPTokenMissing )
return ok
}
func ( err ErrIAPTokenMissing ) Error ( ) string {
return fmt . Sprintf ( "No JWT provided by the identity-aware proxy at the header %v" , err . Header )
}
// ErrorCodeIAPTokenMissing holds the unique world-error code of this error
const ErrorCodeIAPTokenMissing = 12001
// HTTPError holds the http error description
func ( err ErrIAPTokenMissing ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusServiceUnavailable , Code : ErrorCodeIAPTokenMissing , Message : "No authentication provided by the identity-aware proxy." }
}
// ErrIAPPublicKeysetMissing represents a "IAPPublicKeysetMissing" kind of error.
type ErrIAPPublicKeysetMissing struct {
2020-12-28 21:30:00 +00:00
URL string
2020-11-26 02:25:57 +00:00
}
// IsErrIAPPublicKeysetMissing checks if an error is a ErrIAPPublicKeysetMissing.
func IsErrIAPPublicKeysetMissing ( err error ) bool {
_ , ok := err . ( ErrIAPPublicKeysetMissing )
return ok
}
func ( err ErrIAPPublicKeysetMissing ) Error ( ) string {
2020-12-28 21:30:00 +00:00
return fmt . Sprintf ( "Failed to retrieve the identity-aware proxy's signing public key at URL: %s" , err . URL )
2020-11-26 02:25:57 +00:00
}
// ErrorCodeIAPPublicKeysetMissing holds the unique world-error code of this error
const ErrorCodeIAPPublicKeysetMissing = 12002
// HTTPError holds the http error description
func ( err ErrIAPPublicKeysetMissing ) HTTPError ( ) web . HTTPError {
2020-12-28 21:30:00 +00:00
return web . HTTPError { HTTPCode : http . StatusServiceUnavailable , Code : ErrorCodeIAPPublicKeysetMissing , Message : "Failed to retrieve the identity-aware proxy's signing public keys." }
2020-11-26 02:25:57 +00:00
}
// ErrIAPUserFrontendMismatch represents a "IAPUserDoesNotMatchFrontendUser" kind of error.
2020-12-28 20:05:28 +00:00
type ErrIAPUserFrontendMismatch struct { }
2020-11-26 02:25:57 +00:00
// IsErrIAPPublicKeysetMissing checks if an error is a ErrIAPUserFrontendMismatch.
func IsErrIAPUserFrontendMismatch ( err error ) bool {
_ , ok := err . ( ErrIAPUserFrontendMismatch )
return ok
}
func ( err ErrIAPUserFrontendMismatch ) Error ( ) string {
return "Frontend provided user does not match IAP provided user"
}
// ErrorCodeIAPPublicKeysetMissing holds the unique world-error code of this error
const ErrorCodeIAPUserFrontendMismatch = 12003
// HTTPError holds the http error description
func ( err ErrIAPUserFrontendMismatch ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusBadRequest , Code : ErrorCodeIAPUserFrontendMismatch , Message : "Invalid provided jwt." }
}
// ErrIAPUnsupportedJWTSigningMethod represents a "IAPUnsupportedJWTSigningMethod" kind of error.
type ErrIAPUnsupportedJWTSigningMethod struct {
Method string
}
// IsErrIAPUnsupportedJWTSigningMethod checks if an error is a ErrIAPUnsupportedJWTSigningMethod.
func IsErrIAPUnsupportedJWTSigningMethod ( err error ) bool {
_ , ok := err . ( ErrIAPUnsupportedJWTSigningMethod )
return ok
}
func ( err ErrIAPUnsupportedJWTSigningMethod ) Error ( ) string {
return fmt . Sprintf ( "Unsupported JWT signing method: %s" , err . Method )
}
// ErrorCodeIAPUnsupportedJWTSigningMethod holds the unique world-error code of this error
const ErrorCodeIAPUnsupportedJWTSigningMethod = 12004
// HTTPError holds the http error description
func ( err ErrIAPUnsupportedJWTSigningMethod ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusInternalServerError , Code : ErrorCodeIAPUnsupportedJWTSigningMethod , Message : "Unsupported JWT signing method." }
}
// ErrIAPJWTMissingKID represents a "ErrIAPJWTMissingKID" kind of error.
2020-12-28 20:05:28 +00:00
type ErrIAPJWTMissingKID struct { }
2020-11-26 02:25:57 +00:00
// IsErrIAPUnsupportedJWTSigningMethod checks if an error is a ErrIAPJWTMissingKID.
func IsErrIAPJWTMissingKID ( err error ) bool {
_ , ok := err . ( ErrIAPJWTMissingKID )
return ok
}
func ( err ErrIAPJWTMissingKID ) Error ( ) string {
return "JWT missing KID"
}
// ErrorCodeErrIAPJWTMissingKID holds the unique world-error code of this error
const ErrorCodeErrIAPJWTMissingKID = 12005
// HTTPError holds the http error description
func ( err ErrIAPJWTMissingKID ) HTTPError ( ) web . HTTPError {
return web . HTTPError { HTTPCode : http . StatusInternalServerError , Code : ErrorCodeErrIAPJWTMissingKID , Message : "JWT missing KID." }
}