Version: v0.0.0-...-30a92e5 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 23 Imported by: 0




View Source
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"


View Source
var JWTSecret string

JWTSecret exposes the JWT secret.

View Source
var RedirectURI string

RedirectURI exposes the allowed redirect URI.


func ConnectDB

func ConnectDB(rawURL string) *gorm.DB

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 GetVersion

func GetVersion() string

GetVersion returns the application version.

func Getenv

func Getenv(variable string) string

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 InitExternalURL

func InitExternalURL()

InitExternalURL loads the external URL.

func InitJWTSecret

func InitJWTSecret()

InitJWTSecret loads the JWT secret.

func InitRedirectURI

func InitRedirectURI()

InitRedirectURI loads the redirect URI.

func InitializeEnforcer

func InitializeEnforcer(db *gorm.DB)

InitializeEnforcer creates a new enforcer via the GORM database adapter.

func InjectAuthenticationTransaction

func InjectAuthenticationTransaction(r *http.Request)

InjectAuthenticationTransaction sets the state to prevent CSRF attacks and to encode organisation and redirect URI information.

func InjectProvider

func InjectProvider(r *http.Request, ID string)

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 Remove

func Remove(s []string, i int) []string

Remove removes an array element without keeping the original order.

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.

func SetVersion

func SetVersion(v string)

SetVersion configures the application version.

func UserFromGoth

func UserFromGoth(gothUser *goth.User) *models.User

UserFromGoth will create a new user from the goth user struct.


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

type ConnectionInformation struct {
	Driver string
	Path   string

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.

type HTTPError

type HTTPError struct {
	Title  string `json:"title"`
	Status int    `json:"status"`
	Reason string `json:"reason"`

HTTPError is the information about an HTTP error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL