Documentation ¶
Index ¶
- Constants
- Variables
- func AccessControl(logger *zap.SugaredLogger, db database.Database, scms *Scms) echo.MiddlewareFunc
- func Add(cookie string, userID uint64)
- func EnableProvider(p *Provider, ...) bool
- func Get(cookie string) uint64
- func GetCallbackURL(baseURL, provider string) string
- func GetEventsURL(baseURL, provider string) string
- func GetProviderURL(baseURL, route, provider, endpoint string) string
- func GetProviders() *pb.Providers
- func OAuth2Callback(logger *zap.SugaredLogger, db database.Database, scms *Scms) echo.HandlerFunc
- func OAuth2Login(logger *zap.SugaredLogger, db database.Database) echo.HandlerFunc
- func OAuth2Logout(logger *zap.SugaredLogger) echo.HandlerFunc
- func PreAuth(logger *zap.SugaredLogger, db database.Database) echo.MiddlewareFunc
- func UserVerifier() grpc.UnaryServerInterceptor
- type FakeProvider
- func (p *FakeProvider) BeginAuth(state string) (goth.Session, error)
- func (p *FakeProvider) Client() *http.Client
- func (p *FakeProvider) Debug(debug bool)
- func (p *FakeProvider) FetchUser(session goth.Session) (goth.User, error)
- func (p *FakeProvider) Name() string
- func (p *FakeProvider) RefreshToken(refreshToken string) (*oauth2.Token, error)
- func (p *FakeProvider) RefreshTokenAvailable() bool
- func (p *FakeProvider) SetName(name string)
- func (p *FakeProvider) UnmarshalSession(data string) (goth.Session, error)
- type FakeSession
- type Provider
- type Scms
- type UserSession
Constants ¶
const ( SessionKey = "session" UserKey = "user" Cookie = "cookie" OutgoingCookie = "Set-Cookie" )
Session keys.
const ( State = "state" // As defined by the OAuth2 RFC. Redirect = "redirect" )
Query keys.
const TeacherSuffix = "-teacher"
TeacherSuffix is the suffix appended to the provider with the teacher scope.
Variables ¶
var ( ErrInvalidSessionCookie = status.Errorf(codes.Unauthenticated, "Request does not contain a valid session cookie.") ErrContextMetadata = status.Errorf(codes.Unauthenticated, "Could not obtain metadata from context") )
Functions ¶
func AccessControl ¶
func AccessControl(logger *zap.SugaredLogger, db database.Database, scms *Scms) echo.MiddlewareFunc
AccessControl returns an access control middleware. Given a valid context with sufficient access the next handler is called. Missing or invalid credentials results in a 401 unauthorized response.
func EnableProvider ¶
func EnableProvider(p *Provider, createProvider func(key, secret, callback string, scopes ...string) goth.Provider) bool
EnableProvider enables the specified provider and returns true if the corresponding environment variables are set.
func GetCallbackURL ¶
GetCallbackURL returns the callback URL for a given base URL and a provider.
func GetEventsURL ¶
GetEventsURL returns the event URL for a given base URL and a provider.
func GetProviderURL ¶
GetProviderURL returns a URL endpoint given a base URL and a provider.
func GetProviders ¶
GetProviders returns a list of all providers enabled by goth.
func OAuth2Callback ¶
func OAuth2Callback(logger *zap.SugaredLogger, db database.Database, scms *Scms) echo.HandlerFunc
OAuth2Callback handles the callback from an oauth2 provider.
func OAuth2Login ¶
func OAuth2Login(logger *zap.SugaredLogger, db database.Database) echo.HandlerFunc
OAuth2Login tries to authenticate against an oauth2 provider.
func OAuth2Logout ¶
func OAuth2Logout(logger *zap.SugaredLogger) echo.HandlerFunc
OAuth2Logout invalidates the session for the logged in user.
func PreAuth ¶
func PreAuth(logger *zap.SugaredLogger, db database.Database) echo.MiddlewareFunc
PreAuth checks the current user session and executes the next handler if none was found for the given provider.
func UserVerifier ¶
func UserVerifier() grpc.UnaryServerInterceptor
Types ¶
type FakeProvider ¶
type FakeProvider struct { HTTPClient *http.Client Callback string // contains filtered or unexported fields }
FakeProvider is used only for testing.
func (*FakeProvider) BeginAuth ¶
func (p *FakeProvider) BeginAuth(state string) (goth.Session, error)
BeginAuth is used only for testing.
func (*FakeProvider) Client ¶
func (p *FakeProvider) Client() *http.Client
Client is used only for testing.
func (*FakeProvider) Debug ¶
func (p *FakeProvider) Debug(debug bool)
Debug is used only for testing.
func (*FakeProvider) RefreshToken ¶
func (p *FakeProvider) RefreshToken(refreshToken string) (*oauth2.Token, error)
RefreshToken is used only for testing
func (*FakeProvider) RefreshTokenAvailable ¶
func (p *FakeProvider) RefreshTokenAvailable() bool
RefreshTokenAvailable is used only for testing
func (*FakeProvider) SetName ¶
func (p *FakeProvider) SetName(name string)
SetName is to update the name of the provider (needed in case of multiple providers of 1 type)
func (*FakeProvider) UnmarshalSession ¶
func (p *FakeProvider) UnmarshalSession(data string) (goth.Session, error)
UnmarshalSession is used only for testing.
type FakeSession ¶
FakeSession is used only for testing.
func (*FakeSession) GetAuthURL ¶
func (s *FakeSession) GetAuthURL() (string, error)
GetAuthURL is used only for testing.
func (*FakeSession) Marshal ¶
func (s *FakeSession) Marshal() string
Marshal is used only for testing.
type Provider ¶
type Provider struct { Name string KeyEnv string SecretEnv string CallbackURL string StudentScopes []string TeacherScopes []string }
Provider contains information about how to enable the same authentication provider with different scopes. The provider will be registered under Name with the student scope, and under Name + TeacherSuffix with the teacher scope.
type Scms ¶
type Scms struct {
// contains filtered or unexported fields
}
Scms stores information about active scm clients.
func (*Scms) GetOrCreateSCMEntry ¶
func (s *Scms) GetOrCreateSCMEntry(logger *zap.Logger, provider, accessToken string) (scm.SCM, error)
GetOrCreateSCMEntry returns an scm client for the given remote identity (provider, access token) pair. If no scm client exists for the given remote identity, one will be created and stored for later retrival.
type UserSession ¶
UserSession holds user session information.
func (UserSession) String ¶
func (us UserSession) String() string