Documentation ¶
Overview ¶
Package auth provides a system for identifying and authenticating users through third party cloud systems in Cogent Core apps.
Index ¶
- func Auth(c *AuthConfig) (*oauth2.Token, *oidc.UserInfo, error)
- func Button(par core.Widget, c *ButtonsConfig, provider string, ...) *core.Button
- func Buttons(par core.Widget, c *ButtonsConfig) *core.Frame
- func Google(c *AuthConfig) (*oauth2.Token, *oidc.UserInfo, error)
- func GoogleButton(par core.Widget, c *ButtonsConfig) *core.Button
- type AuthConfig
- type ButtonsConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Auth ¶
Auth authenticates the user using the given configuration information and returns the resulting oauth token and user info. See AuthConfig for more information on the configuration options.
func Button ¶
func Button(par core.Widget, c *ButtonsConfig, provider string, authFunc func(c *AuthConfig) (*oauth2.Token, *oidc.UserInfo, error)) *core.Button
Button makes a new button for signing in with the provider that has the given name and auth func. It should not typically be used by end users; instead, use Buttons or the platform-specific functions (eg: Google). The configuration options can be nil, in which case default values will be used.
func Buttons ¶
func Buttons(par core.Widget, c *ButtonsConfig) *core.Frame
Buttons adds a new vertical layout to the given parent with authentication buttons for major platforms, using the given configuration options. See ButtonsConfig for more information on the configuration options. The configuration options can be nil, in which case default values will be used.
func Google ¶
Google authenticates the user with Google using Auth and the given configuration information and returns the resulting oauth token and user info. It sets the values of [AuthConfig.ProviderName], [AuthConfig.ProviderURL], [AuthConfig.ClientID], and [AuthConfig.ClientSecret] if they are not already set.
func GoogleButton ¶
func GoogleButton(par core.Widget, c *ButtonsConfig) *core.Button
GoogleButton adds a new button for signing in with Google to the given parent using the given configuration information.
Types ¶
type AuthConfig ¶
type AuthConfig struct { // Ctx is the context to use. It is [context.TODO] if unspecified. Ctx context.Context // ProviderName is the name of the provider to authenticate with (eg: "google") ProviderName string // ProviderURL is the URL of the provider (eg: "https://accounts.google.com") ProviderURL string // ClientID is the client ID for the app, which is typically obtained through a developer oauth // portal (eg: the Credentials section of https://console.developers.google.com/). ClientID string // ClientSecret is the client secret for the app, which is typically obtained through a developer oauth // portal (eg: the Credentials section of https://console.developers.google.com/). ClientSecret string // TokenFile is an optional function that returns the filename at which the token for the given user will be stored as JSON. // If it is nil or it returns "", the token is not stored. Also, if it is non-nil, Auth skips the user-facing authentication // step if it finds a valid token at the file (ie: remember me). It checks all [AuthConfig.Accounts] until it finds one // that works for that step. If [AuthConfig.Accounts] is nil, it checks with a blank ("") email account. TokenFile func(email string) string // Accounts are optional accounts to check for the remember me feature described in [AuthConfig.TokenFile]. // If it is nil and TokenFile is not, it defaults to contain one blank ("") element. Accounts []string // Scopes are additional scopes to request beyond the default "openid", "profile", and "email" scopes Scopes []string }
AuthConfig is the configuration information passed to Auth.
type ButtonsConfig ¶
type ButtonsConfig struct { // SuccessFunc, if non-nil, is the function called after the user successfully // authenticates. It is passed the user's authentication token and info. SuccessFunc func(token *oauth2.Token, userInfo *oidc.UserInfo) // TokenFile, if non-nil, is the function used to determine what token file function is // used for [AuthConfig.TokenFile]. It is passed the provider being used (eg: "google") and the // email address of the user authenticating. TokenFile func(provider, email string) string // Accounts are optional accounts to check for the remember me feature described in [AuthConfig.TokenFile]. // See [AuthConfig.Accounts] for more information. If it is nil and TokenFile is not, it defaults to contain // one blank ("") element. Accounts []string // Scopes, if non-nil, is a map of scopes to pass to [Auth], keyed by the // provider being used (eg: "google"). Scopes map[string][]string }
ButtonsConfig is the configuration information passed to Buttons.