{"modulePath":"github.com/RedAFD/code-core","version":"v1.14.0-rc8","isLatest":false,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package sso\n\n## Functions\n\n```go\nfunc CheckOAuthAccessToken(accessToken string) int64\n```\nCheckOAuthAccessToken returns uid of user from oauth token\n\n```go\nfunc Free()\n```\nFree should be called exactly once when the application is terminating to allow SSO plugins to release necessary resources\n\n```go\nfunc Init()\n```\nInit should be called exactly once when the application starts to allow SSO plugins to allocate necessary resources\n\n```go\nfunc Register(method SingleSignOn)\n```\nRegister adds the specified instance to the list of available SSO methods\n\n```go\nfunc SessionUser(sess SessionStore) *models.User\n```\nSessionUser returns the user object corresponding to the \"uid\" session variable.\n\n```go\nfunc SignedInUser(req *http.Request, w http.ResponseWriter, ds DataStore, sess SessionStore) (*models.User, bool)\n```\nSignedInUser returns the user object of signed user. It returns a bool value to indicate whether user uses basic auth or not.\n\n## Types\n\n```go\ntype Basic struct {\n}\n```\nBasic implements the SingleSignOn interface and authenticates requests (API requests only) by looking for Basic authentication data or \"x-oauth-basic\" token in the \"Authorization\" header.\n\n```go\nfunc (b *Basic) Free() error\n```\nFree does nothing as the Basic implementation does not have to release any resources\n\n```go\nfunc (b *Basic) Init() error\n```\nInit does nothing as the Basic implementation does not need to allocate any resources\n\n```go\nfunc (b *Basic) IsEnabled() bool\n```\nIsEnabled returns true as this plugin is enabled by default and its not possible to disable it from settings.\n\n```go\nfunc (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User\n```\nVerifyAuthData extracts and validates Basic data (username and password/token) from the \"Authorization\" header of the request and returns the corresponding user object for that name/token on successful validation. Returns nil if header is empty or validation fails.\n\n```go\ntype DataStore middleware.DataStore\n```\nDataStore represents a data store\n\n```go\ntype OAuth2 struct {\n}\n```\nOAuth2 implements the SingleSignOn interface and authenticates requests (API requests only) by looking for an OAuth token in query parameters or the \"Authorization\" header.\n\n```go\nfunc (o *OAuth2) Free() error\n```\nFree does nothing as the OAuth2 implementation does not have to release any resources\n\n```go\nfunc (o *OAuth2) Init() error\n```\nInit does nothing as the OAuth2 implementation does not need to allocate any resources\n\n```go\nfunc (o *OAuth2) IsEnabled() bool\n```\nIsEnabled returns true as this plugin is enabled by default and its not possible to disable it from settings.\n\n```go\nfunc (o *OAuth2) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User\n```\nVerifyAuthData extracts the user ID from the OAuth token in the query parameters or the \"Authorization\" header and returns the corresponding user object for that ID. If verification is successful returns an existing user object. Returns nil if verification fails.\n\n```go\ntype ReverseProxy struct {\n}\n```\nReverseProxy implements the SingleSignOn interface, but actually relies on a reverse proxy for authentication of users. On successful authentication the proxy is expected to populate the username in the \"setting.ReverseProxyAuthUser\" header. Optionally it can also populate the email of the user in the \"setting.ReverseProxyAuthEmail\" header.\n\n```go\nfunc (r *ReverseProxy) Free() error\n```\nFree does nothing as the ReverseProxy implementation does not have to release resources\n\n```go\nfunc (r *ReverseProxy) Init() error\n```\nInit does nothing as the ReverseProxy implementation does not need initialization\n\n```go\nfunc (r *ReverseProxy) IsEnabled() bool\n```\nIsEnabled checks if EnableReverseProxyAuth setting is true\n\n```go\nfunc (r *ReverseProxy) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User\n```\nVerifyAuthData extracts the username from the \"setting.ReverseProxyAuthUser\" header of the request and returns the corresponding user object for that name. Verification of header data is not performed as it should have already been done by the revese proxy. If a username is available in the \"setting.ReverseProxyAuthUser\" header an existing user object is returned (populated with username or email found in header). Returns nil if header is empty.\n\n```go\ntype Session struct {\n}\n```\nSession checks if there is a user uid stored in the session and returns the user object for that uid.\n\n```go\nfunc (s *Session) Free() error\n```\nFree does nothing as the Session implementation does not have to release any resources\n\n```go\nfunc (s *Session) Init() error\n```\nInit does nothing as the Session implementation does not need to allocate any resources\n\n```go\nfunc (s *Session) IsEnabled() bool\n```\nIsEnabled returns true as this plugin is enabled by default and its not possible to disable it from settings.\n\n```go\nfunc (s *Session) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User\n```\nVerifyAuthData checks if there is a user uid stored in the session and returns the user object for that uid. Returns nil if there is no user uid stored in the session.\n\n```go\ntype SessionStore session.Store\n```\nSessionStore represents a session store\n\n```go\ntype SingleSignOn interface {\n\t// Init should be called exactly once before using any of the other methods,\n\t// in order to allow the plugin to allocate necessary resources\n\tInit() error\n\n\t// Free should be called exactly once before application closes, in order to\n\t// give chance to the plugin to free any allocated resources\n\tFree() error\n\n\t// IsEnabled checks if the current SSO method has been enabled in settings.\n\tIsEnabled() bool\n\n\t// VerifyAuthData tries to verify the SSO authentication data contained in the request.\n\t// If verification is successful returns either an existing user object (with id \u003e 0)\n\t// or a new user object (with id = 0) populated with the information that was found\n\t// in the authentication data (username or email).\n\t// Returns nil if verification fails.\n\tVerifyAuthData(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User\n}\n```\nSingleSignOn represents a SSO authentication method (plugin) for HTTP requests.\n\n```go\nfunc Methods() []SingleSignOn\n```\nMethods returns the instances of all registered SSO methods\n\n","path":"github.com/RedAFD/code-core/modules/auth/sso","name":"sso","synopsis":"","isRedistributable":true}
