Documentation
¶
Index ¶
- Constants
- Variables
- func ConnectDB(rawURL string) *gorm.DB
- func Enforcer() *casbin.Enforcer
- func GetVersion() string
- func Getenv(variable string) string
- func InitExternalURL()
- func InitJWTSecret()
- func InitRedirectURI()
- func InitializeEnforcer(db *gorm.DB)
- func InjectAuthenticationTransaction(r *http.Request)
- func InjectProvider(r *http.Request, ID string)
- func LoadAuthenticationProvider(entity *models.AuthenticationProvider) error
- func Remove(s []string, i int) []string
- func SendData(w http.ResponseWriter, status int, data interface{})
- func SendError(w http.ResponseWriter, status int, reason string)
- func SessionStore() *sessions.CookieStore
- func SetVersion(v string)
- func UserFromGoth(gothUser *goth.User) *models.User
- type AuthenticationTransaction
- type ConnectionInformation
- type ContextKey
- type DataPayload
- type ErrorPayload
- type HTTPError
Constants ¶
const ( // ReasonValidationFailed occurs when the request body field validation fails. ReasonValidationFailed = "Validation Failed" // ReasonQueryFailed occurs when the SQL query fails. ReasonQueryFailed = "Query Failed" // ReasonJSONInvalid occurs when the JSON payload cannot be parsed. ReasonJSONInvalid = "JSON Invalid" // ReasonEntityExists occurs when there is a duplicate. ReasonEntityExists = "Entity Exists" // ReasonEntityUnknown occurs when an entity cannot be found. ReasonEntityUnknown = "Entity Unknown" // ReasonEndpointUnsupported occurs when the endpoint is not part of the specification. ReasonEndpointUnsupported = "Endpoint Unsupported" // ReasonTokenExpired occurs if the authentication token is expired. ReasonTokenExpired = "Token Expired" // ReasonIATClaimInvalid occurs if the authentication token has an invalid "issued at" claim. ReasonIATClaimInvalid = "IAT Claim Invalid" // ReasonNBFClaimInvalid occurs if the authentication token has an invalid "not before" claim. ReasonNBFClaimInvalid = "NBF Claim Invalid" // ReasonUserIDClaimInvalid occurs if the authentication token has an invalid "user_id" claim. ReasonUserIDClaimInvalid = "User ID Claim Invalid" // ReasonOrganisationIDClaimInvalid occurs if the authentication token has an invalid "organisation_id" claim. ReasonOrganisationIDClaimInvalid = "Organisation ID Claim Invalid" // ReasonAlgorithmInvalid occurs if the authentication token uses the wrong signing algorithm. ReasonAlgorithmInvalid = "Algorithm Invalid" // ReasonSignatureInvalid occurs if the token has an invalid signature. ReasonSignatureInvalid = "Signature Invalid" // ReasonPolicyCheckFailed occurs if the enforcer returns an error. ReasonPolicyCheckFailed = "Policy Check Failed" // ReasonInsufficientPrivileges occurs if the user has no access to a specific resource. ReasonInsufficientPrivileges = "Insufficient Privileges" // ReasonProviderUnknown occurs when the authentication provider type is unknown. ReasonProviderUnknown = "Provider Unknown" // ReasonSessionMissing occurs if the user cannot be loaded from the session. ReasonSessionMissing = "Session Missing" // ReasonStateInvalid occurs if the authentication transaction cannot be extracted. ReasonStateInvalid = "State Invalid" // ReasonOrganisationIDMissing occurs if the organisation ID is not provided. ReasonOrganisationIDMissing = "Organisation ID Missing" // ReasonRedirectURIInvalid occurs if the redirect URI is not allowed or empty. ReasonRedirectURIInvalid = "Redirect URI Invalid" // ReasonIssuingJWTFailed occurs if the JWT cannot be issued. ReasonIssuingJWTFailed = "Issuing JWT Failed" )
Variables ¶
var JWTSecret string
JWTSecret exposes the JWT secret.
var RedirectURI string
RedirectURI exposes the allowed redirect URI.
Functions ¶
func ConnectDB ¶
ConnectDB connects to a database. It provides a database-agnostic interface, so the connection string format is a URL for MySQL, MariaDB and PostgreSQL.
func Enforcer ¶
func Enforcer() *casbin.Enforcer
Enforcer returns the enforcer instance of the server.
func Getenv ¶
Getenv attempts to get the value of an environment variable from a file path. If the value is not a file path, it will use the value.
func InitializeEnforcer ¶
InitializeEnforcer creates a new enforcer via the GORM database adapter.
func InjectAuthenticationTransaction ¶
InjectAuthenticationTransaction sets the state to prevent CSRF attacks and to encode organisation and redirect URI information.
func InjectProvider ¶
InjectProvider injects the authentication provider name into the HTTP request object for the authentication library.
func LoadAuthenticationProvider ¶
func LoadAuthenticationProvider(entity *models.AuthenticationProvider) error
LoadAuthenticationProvider ensures that the authentication provider is loaded in goth.
func SendData ¶
func SendData(w http.ResponseWriter, status int, data interface{})
SendData sends a data response by using the response writer.
func SendError ¶
func SendError(w http.ResponseWriter, status int, reason string)
SendError sends an HTTP error by using the response writer.
func SessionStore ¶
func SessionStore() *sessions.CookieStore
SessionStore configures and returns a new session store.
Types ¶
type AuthenticationTransaction ¶
type AuthenticationTransaction struct { State string `json:"state"` RedirectURI string `json:"redirect_uri"` OrganisationID string `json:"organisation_id"` }
AuthenticationTransaction contains the information about the current authentication request.
func ExtractAuthenticationTransaction ¶
func ExtractAuthenticationTransaction(r *http.Request) *AuthenticationTransaction
ExtractAuthenticationTransaction extracts the authentication transaction from the "state" query parameter.
type ConnectionInformation ¶
ConnectionInformation contains the parsed database driver and the parse database path.
type ContextKey ¶
type ContextKey string
ContextKey is a datatype to create context keys.
func (*ContextKey) String ¶
func (key *ContextKey) String() string
String casts the context key to a string.
type DataPayload ¶
type DataPayload struct {
Data interface{} `json:"data"`
}
DataPayload is the structure that responses will have if data is sent occurs.
type ErrorPayload ¶
type ErrorPayload struct {
Error interface{} `json:"error"`
}
ErrorPayload is the structure that responses will have if an error occurs.
func NewHTTPError ¶
func NewHTTPError(status int, reason string) *ErrorPayload
NewHTTPError creates the payload for a new HTTP error.