Documentation ¶
Index ¶
- Constants
- Variables
- func MapGitHub(c *aries.C, u *UserMeta, _ string) (string, error)
- func ParseRedirect(redirect string) (string, error)
- func SingleAdmin(admin string) func(user string) (interface{}, int, error)
- type App
- type Client
- type Config
- type GoogleUserInfo
- type JSONConfig
- type Module
- func (m *Module) Auth() aries.Auth
- func (m *Module) Methods() []string
- func (m *Module) Serve(c *aries.C) error
- func (m *Module) Setup(c *aries.C) error
- func (m *Module) SetupCookie(c *aries.C, user string)
- func (m *Module) SignIn(c *aries.C, method string, s *State) error
- func (m *Module) Token(user string, ttl time.Duration) *signin.Token
- type SignUp
- type SignUpConfig
- type State
- type UserMeta
Constants ¶
const ( MethodGitHub = "github" MethodGoogle = "google" MethodDigitalOcean = "digitalocean" MethodBitbucket = "bitbucket" )
Sign in methods
Variables ¶
var GitHubEndpoint = oauth2.Endpoint{
AuthURL: "https://github.com/login/oauth/authorize",
TokenURL: "https://github.com/login/oauth/access_token",
}
GitHubEndpoint is the oauth2 endpoint for GitHub.
var GoogleEndpoint = oauth2.Endpoint{ AuthURL: "https://accounts.google.com/o/oauth2/auth", TokenURL: "https://oauth2.googleapis.com/token", AuthStyle: oauth2.AuthStyleInParams, }
GoogleEndpoint is google's oauth2 endpoint. This is copied from golang.org/x/oauth2/google, to avoid dragging in useless dependencies such as protobuf.
Google engineers really should be more careful with their package dependency management.
Functions ¶
func MapGitHub ¶
MapGitHub is a login check function that only allows github login. It maps the user ID directly from GitHub users.
func ParseRedirect ¶
ParseRedirect parses an in-site redirection URL. The server parts (scheme, host, port, user info) are discarded.
Types ¶
type App ¶
type App struct { ID string Secret string RedirectURL string `json:",omitempty"` Scopes []string `json:",omitempty"` // Used only in GitHub OAuth2 WithEmail bool `json:",omitempty"` // Used only in Google OAuth2 WithProfile bool `json:",omitempty"` }
App stores the configuration of a general oauth2 application.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an oauth client for oauth2 exchanges.
func (*Client) OfflineSignInURL ¶
OfflineSignInURL returns the offline signin URL for redirection.
type Config ¶
type Config struct { GitHub *App Google *App DigitalOcean *App StateKey []byte SessionKey []byte SessionLifeTime time.Duration SessionRefresh time.Duration Bypass string Redirect string SignInRedirect string KeyRegistry keyreg.KeyRegistry // SignInCheck exchanges OAuth2 ID's for user ID. SignInCheck func(c *aries.C, u *UserMeta, purpose string) (string, error) // Check checks the user id and returns the user account structure. Check func(user string) (interface{}, int, error) PreSignOut func(c *aries.C) error }
Config is a module configuration for a GitHub Oauth handling module.
type GoogleUserInfo ¶
GoogleUserInfo stores a Google user's basic personal info.
func GetGoogleUserInfo ¶
func GetGoogleUserInfo( ctx context.Context, c *Client, tok *oauth2.Token, ) (*GoogleUserInfo, error)
GetGoogleUserInfo queries Google OAuth endpoint for user info data.
type JSONConfig ¶
type JSONConfig struct { GitHub *App Google *App DigitalOcean *App StateKey string SessionKey string SignInBypass string PublicKeys map[string]string }
JSONConfig is a JSON marshallable config that is commonly used for setting up a server.
func (*JSONConfig) Config ¶
func (c *JSONConfig) Config() *Config
Config converts a JSON marshallable config to Config.
func (*JSONConfig) SimpleGitHubConfig ¶
func (c *JSONConfig) SimpleGitHubConfig() *Config
SimpleGitHubConfig converts a JSON marshallable config to Config that uses Github as the direct user ID mapping. Users that has a public key assigned in c.PublicKeys are defined as admin.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is a module that handles stuff related to oauth.
func (*Module) SetupCookie ¶
SetupCookie sets up the session gate's cookie.
type SignUp ¶
type SignUp struct {
// contains filtered or unexported fields
}
SignUp is an HTTP module that handles user signups.
func NewSignUp ¶
func NewSignUp(m *Module, c *SignUpConfig) *SignUp
NewSignUp creates a new sign up module.
type SignUpConfig ¶
type SignUpConfig struct { Redirect string // Whether keep user signed in after signing up. SignIn bool }
SignUpConfig is the config for creating a signup module.