{"modulePath":"github.com/GoPlugin/pluginV2","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package auth\n\n## Constants\n\n```go\nconst (\n\t// APIKey is the header name for the API token identifier for user authentication.\n\tAPIKey = \"X-API-KEY\"\n\n\t// APISecret is the header name for the API token secret for user authentication.\n\tAPISecret = \"X-API-SECRET\"\n\n\t// SessionName is the session name\n\tSessionName = \"clsession\"\n\n\t// SessionIDKey is the session ID key in the session map\n\tSessionIDKey = \"clsession_id\"\n\n\t// SessionUserKey is the User key in the session map\n\tSessionUserKey = \"user\"\n\n\t// SessionExternalInitiatorKey is the External Initiator key in the session map\n\tSessionExternalInitiatorKey = \"external_initiator\"\n)\n```\n\n## Functions\n\n```go\nfunc Authenticate(store Authenticator, methods ...authMethod) gin.HandlerFunc\n```\nAuthenticate is middleware which authenticates the request by attempting to authenticate using all the provided methods.\n\n```go\nfunc AuthenticateBySession(c *gin.Context, authr Authenticator) error\n```\nAuthenticateBySession authenticates the request by the session cookie.\n\nImplements authMethod\n\n```go\nfunc AuthenticateByToken(c *gin.Context, authr Authenticator) error\n```\nAuthenticateByToken authenticates a User by their API token.\n\nImplements authMethod\n\n```go\nfunc AuthenticateExternalInitiator(c *gin.Context, store Authenticator) error\n```\nAuthenticateExternalInitiator authenticates an external initiator request.\n\nImplements authMethod\n\n```go\nfunc AuthenticateGQL(authenticator Authenticator, lggr logger.Logger) gin.HandlerFunc\n```\nAuthenticateGQL middleware checks the session cookie for a user and sets it on the request context if it exists. It is the responsibility of each resolver to validate whether it requires an authenticated user.\n\nWe currently only support GQL authentication by session cookie.\n\n```go\nfunc GetAuthenticatedExternalInitiator(c *gin.Context) (*bridges.ExternalInitiator, bool)\n```\nGetAuthenticatedExternalInitiator extracts the external initiator from the context.\n\n```go\nfunc GetAuthenticatedUser(c *gin.Context) (*clsessions.User, bool)\n```\nGetAuthenticatedUser extracts the authentication user from the context.\n\n```go\nfunc RequiresAdminRole(handler func(*gin.Context)) func(*gin.Context)\n```\nRequiresAdminRole extracts the user object from the context, and asserts the user's role is 'admin'\n\n```go\nfunc RequiresEditRole(handler func(*gin.Context)) func(*gin.Context)\n```\nRequiresEditRole extracts the user object from the context, and asserts the user's role is at least 'edit'\n\n```go\nfunc RequiresRunRole(handler func(*gin.Context)) func(*gin.Context)\n```\nRequiresRunRole extracts the user object from the context, and asserts the user's role is at least 'run'\n\n```go\nfunc SetGQLAuthenticatedSession(ctx context.Context, user clsessions.User, sessionID string) context.Context\n```\nSetGQLAuthenticatedSession sets the authenticated session in the context\n\nThere shouldn't be a need to do this outside of testing\n\n## Types\n\n```go\ntype Authenticator interface {\n\tAuthorizedUserWithSession(sessionID string) (clsessions.User, error)\n\tFindExternalInitiator(eia *auth.Token) (*bridges.ExternalInitiator, error)\n\tFindUser(email string) (clsessions.User, error)\n\tFindUserByAPIToken(apiToken string) (clsessions.User, error)\n}\n```\nAuthenticator defines the interface to authenticate requests against a datastore.\n\n```go\ntype GQLSession struct {\n\tSessionID string\n\tUser      *clsessions.User\n}\n```\n\n```go\nfunc GetGQLAuthenticatedSession(ctx context.Context) (*GQLSession, bool)\n```\nGetGQLAuthenticatedSession extracts the authentication session from a context.\n\n","path":"github.com/GoPlugin/pluginV2/core/web/auth","name":"auth","synopsis":"","isRedistributable":true}
