Documentation
¶
Overview ¶
Package provider implements all oauth2, oauth1 as well as custom and direct providers
Index ¶
- Constants
- type AvatarSaver
- type CredChecker
- type CredCheckerFunc
- type CustomHandlerOpt
- type CustomServer
- type CustomServerOpt
- type DevAuthServer
- type DirectHandler
- type Oauth1Handler
- type Oauth2Handler
- func NewBattlenet(p Params) Oauth2Handler
- func NewCustom(name string, p Params, copts CustomHandlerOpt) Oauth2Handler
- func NewDev(p Params) Oauth2Handler
- func NewFacebook(p Params) Oauth2Handler
- func NewGithub(p Params) Oauth2Handler
- func NewGoogle(p Params) Oauth2Handler
- func NewMicrosoft(p Params) Oauth2Handler
- func NewYandex(p Params) Oauth2Handler
- type Params
- type Provider
- type Sender
- type SenderFunc
- type Service
- type TelegramAPI
- type TelegramHandler
- func (th *TelegramHandler) AuthHandler(w http.ResponseWriter, r *http.Request)
- func (th *TelegramHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
- func (th *TelegramHandler) LogoutHandler(w http.ResponseWriter, r *http.Request)
- func (th *TelegramHandler) Name() string
- func (th *TelegramHandler) Run(ctx context.Context) error
- type TokenService
- type UserData
- type VerifTokenService
- type VerifyHandler
Constants ¶
const (
// MaxHTTPBodySize defines max http body size
MaxHTTPBodySize = 1024 * 1024
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AvatarSaver ¶
AvatarSaver defines minimal interface to save avatar
type CredChecker ¶ added in v0.2.0
CredChecker defines interface to check credentials
type CredCheckerFunc ¶ added in v0.2.0
CredCheckerFunc type is an adapter to allow the use of ordinary functions as CredsChecker.
type CustomHandlerOpt ¶ added in v0.8.0
type CustomHandlerOpt struct {
Endpoint oauth2.Endpoint
InfoURL string
MapUserFn func(UserData, []byte) token.User
Scopes []string
}
CustomHandlerOpt are options to initialize a handler for oauth2 server
type CustomServer ¶ added in v0.8.0
type CustomServer struct {
logger.L
URL string // root url for custom oauth2 server
WithLoginPage bool // redirect to login html page if true
LoginPageHandler func(w http.ResponseWriter, r *http.Request) // handler for user-defined login page
OauthServer *goauth2.Server // an instance of go-oauth2/oauth2 server
HandlerOpt CustomHandlerOpt
// contains filtered or unexported fields
}
CustomServer is a wrapper over go-oauth2/oauth2 server running on its own port
func NewCustomServer ¶ added in v0.8.0
func NewCustomServer(srv *goauth2.Server, sopts CustomServerOpt) *CustomServer
NewCustomServer is helper function to initiate a customer server and prefill options needed for provider registration (see Service.AddCustomProvider)
func (*CustomServer) Run ¶ added in v0.8.0
func (c *CustomServer) Run(ctx context.Context)
Run starts serving on port from c.URL
func (*CustomServer) Shutdown ¶ added in v0.8.0
func (c *CustomServer) Shutdown()
Shutdown go-oauth2/oauth2 server
type CustomServerOpt ¶ added in v0.8.0
type CustomServerOpt struct {
logger.L
URL string
WithLoginPage bool
LoginPageHandler func(w http.ResponseWriter, r *http.Request)
}
CustomServerOpt are options to initialize a custom go-oauth2/oauth2 server
type DevAuthServer ¶
type DevAuthServer struct {
logger.L
Provider Oauth2Handler
Automatic bool
// contains filtered or unexported fields
}
DevAuthServer is a fake oauth server for development it provides stand-alone server running on its own port and pretending to be the real oauth2. It also provides Dev Provider the same way as normal providers do, i.e. like github, google and others. can run in interactive and non-interactive mode. In interactive mode login attempts will show login form to select desired user name, this is the mode used for development. Non-interactive mode for tests only.
func (*DevAuthServer) Run ¶
func (d *DevAuthServer) Run(ctx context.Context)
Run oauth2 dev server on port devAuthPort
type DirectHandler ¶ added in v0.2.0
type DirectHandler struct {
logger.L
CredChecker CredChecker
ProviderName string
TokenService TokenService
Issuer string
AvatarSaver AvatarSaver
}
DirectHandler implements non-oauth2 provider authorizing user in traditional way with storage with users and hashes
func (DirectHandler) AuthHandler ¶ added in v0.2.0
func (p DirectHandler) AuthHandler(w http.ResponseWriter, r *http.Request)
AuthHandler doesn't do anything for direct login as it has no callbacks
func (DirectHandler) LoginHandler ¶ added in v0.2.0
func (p DirectHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler checks "user" and "passwd" against data store and makes jwt if all passed.
GET /something?user=name&passwd=xyz&aud=bar&sess=[0|1]
POST /something?sess[0|1] Accepts application/x-www-form-urlencoded or application/json encoded requests.
application/x-www-form-urlencoded body example: user=name&passwd=xyz&aud=bar
application/json body example:
{
"user": "name",
"passwd": "xyz",
"aud": "bar",
}
func (DirectHandler) LogoutHandler ¶ added in v0.2.0
func (p DirectHandler) LogoutHandler(w http.ResponseWriter, r *http.Request)
LogoutHandler - GET /logout
func (DirectHandler) Name ¶ added in v0.2.0
func (p DirectHandler) Name() string
Name of the handler
type Oauth1Handler ¶ added in v0.8.0
type Oauth1Handler struct {
Params
// contains filtered or unexported fields
}
Oauth1Handler implements /login, /callback and /logout handlers for oauth1 flow
func NewTwitter ¶ added in v0.8.0
func NewTwitter(p Params) Oauth1Handler
NewTwitter makes twitter oauth2 provider
func (Oauth1Handler) AuthHandler ¶ added in v0.8.0
func (h Oauth1Handler) AuthHandler(w http.ResponseWriter, r *http.Request)
AuthHandler fills user info and redirects to "from" url. This is callback url redirected locally by browser GET /callback
func (Oauth1Handler) LoginHandler ¶ added in v0.8.0
func (h Oauth1Handler) LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler - GET /login?from=redirect-back-url&site=siteID&session=1
func (Oauth1Handler) LogoutHandler ¶ added in v0.8.0
func (h Oauth1Handler) LogoutHandler(w http.ResponseWriter, r *http.Request)
LogoutHandler - GET /logout
func (Oauth1Handler) Name ¶ added in v0.8.0
func (h Oauth1Handler) Name() string
Name returns provider name
type Oauth2Handler ¶ added in v0.1.1
type Oauth2Handler struct {
Params
// contains filtered or unexported fields
}
Oauth2Handler implements /login, /callback and /logout handlers from aouth2 flow
func NewBattlenet ¶ added in v0.11.0
func NewBattlenet(p Params) Oauth2Handler
NewBattlenet makes Battle.net oauth2 provider
func NewCustom ¶ added in v0.8.0
func NewCustom(name string, p Params, copts CustomHandlerOpt) Oauth2Handler
NewCustom creates a handler for go-oauth2/oauth2 server
func NewFacebook ¶
func NewFacebook(p Params) Oauth2Handler
NewFacebook makes facebook oauth2 provider
func NewMicrosoft ¶ added in v0.11.0
func NewMicrosoft(p Params) Oauth2Handler
NewMicrosoft makes microsoft azure oauth2 provider
func (Oauth2Handler) AuthHandler ¶ added in v0.1.1
func (p Oauth2Handler) AuthHandler(w http.ResponseWriter, r *http.Request)
AuthHandler fills user info and redirects to "from" url. This is callback url redirected locally by browser GET /callback
func (Oauth2Handler) LoginHandler ¶ added in v0.1.1
func (p Oauth2Handler) LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler - GET /login?from=redirect-back-url&site=siteID&session=1
func (Oauth2Handler) LogoutHandler ¶ added in v0.1.1
func (p Oauth2Handler) LogoutHandler(w http.ResponseWriter, r *http.Request)
LogoutHandler - GET /logout
func (Oauth2Handler) Name ¶ added in v0.1.1
func (p Oauth2Handler) Name() string
Name returns provider name
type Params ¶
type Params struct {
logger.L
URL string
JwtService TokenService
Cid string
Csecret string
Issuer string
AvatarSaver AvatarSaver
}
Params to make initialized and ready to use provider
type Provider ¶ added in v0.1.1
type Provider interface {
Name() string
LoginHandler(w http.ResponseWriter, r *http.Request)
AuthHandler(w http.ResponseWriter, r *http.Request)
LogoutHandler(w http.ResponseWriter, r *http.Request)
}
Provider defines interface for auth handler
type SenderFunc ¶ added in v0.6.0
SenderFunc type is an adapter to allow the use of ordinary functions as Sender.
func (SenderFunc) Send ¶ added in v0.6.0
func (f SenderFunc) Send(address, text string) error
Send calls f(address,text) to implement Sender interface
type Service ¶
type Service struct {
Provider
}
Service represents oauth2 provider. Adds Handler method multiplexing login, auth and logout requests
func NewService ¶ added in v0.1.1
NewService makes service for given provider
type TelegramAPI ¶ added in v1.5.1
type TelegramAPI interface {
GetUpdates(ctx context.Context) (*telegramUpdate, error)
Avatar(ctx context.Context, userID int) (string, error)
Send(ctx context.Context, id int, text string) error
BotInfo(ctx context.Context) (*botInfo, error)
}
TelegramAPI is used for interacting with telegram API
func NewTelegramAPI ¶ added in v1.5.1
func NewTelegramAPI(token string, client *http.Client) TelegramAPI
NewTelegramAPI returns initialized TelegramAPI implementation
type TelegramHandler ¶ added in v1.5.1
type TelegramHandler struct {
logger.L
ProviderName string
ErrorMsg, SuccessMsg string
TokenService TokenService
AvatarSaver AvatarSaver
Telegram TelegramAPI
// contains filtered or unexported fields
}
TelegramHandler implements login via telegram
func (*TelegramHandler) AuthHandler ¶ added in v1.5.1
func (th *TelegramHandler) AuthHandler(w http.ResponseWriter, r *http.Request)
AuthHandler does nothing since we're don't have any callbacks
func (*TelegramHandler) LoginHandler ¶ added in v1.5.1
func (th *TelegramHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler generates and verifies login requests
func (*TelegramHandler) LogoutHandler ¶ added in v1.5.1
func (th *TelegramHandler) LogoutHandler(w http.ResponseWriter, r *http.Request)
LogoutHandler - GET /logout
func (*TelegramHandler) Name ¶ added in v1.5.1
func (th *TelegramHandler) Name() string
Name of the provider
type TokenService ¶
type TokenService interface {
Parse(tokenString string) (claims token.Claims, err error)
Set(w http.ResponseWriter, claims token.Claims) (token.Claims, error)
Get(r *http.Request) (claims token.Claims, token string, err error)
Reset(w http.ResponseWriter)
}
TokenService defines interface accessing tokens
type UserData ¶ added in v0.8.0
type UserData map[string]interface{}
UserData is type for user information returned from oauth2 providers /info API method
type VerifTokenService ¶ added in v0.6.0
type VerifTokenService interface {
Token(claims token.Claims) (string, error)
Parse(tokenString string) (claims token.Claims, err error)
IsExpired(claims token.Claims) bool
Set(w http.ResponseWriter, claims token.Claims) (token.Claims, error)
Reset(w http.ResponseWriter)
}
VerifTokenService defines interface accessing tokens
type VerifyHandler ¶ added in v0.6.0
type VerifyHandler struct {
logger.L
ProviderName string
TokenService VerifTokenService
Issuer string
AvatarSaver AvatarSaver
Sender Sender
Template string
UseGravatar bool
}
VerifyHandler implements non-oauth2 provider authorizing users with some confirmation. can be email, IM or anything else implementing Sender interface
func (VerifyHandler) AuthHandler ¶ added in v0.6.0
func (e VerifyHandler) AuthHandler(w http.ResponseWriter, r *http.Request)
AuthHandler doesn't do anything for direct login as it has no callbacks
func (VerifyHandler) LoginHandler ¶ added in v0.6.0
func (e VerifyHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler gets name and address from query, makes confirmation token and sends it to user. In case if confirmation token presented in the query uses it to create auth token
func (VerifyHandler) LogoutHandler ¶ added in v0.6.0
func (e VerifyHandler) LogoutHandler(w http.ResponseWriter, r *http.Request)
LogoutHandler - GET /logout
func (VerifyHandler) Name ¶ added in v0.6.0
func (e VerifyHandler) Name() string
Name of the handler