auth

package
Version: v0.0.0-...-a45a581 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionKey     = "session"
	UserKey        = "user"
	Cookie         = "cookie"
	OutgoingCookie = "Set-Cookie"
)

Session keys.

View Source
const (
	State    = "state" // As defined by the OAuth2 RFC.
	Redirect = "redirect"
)

Query keys.

View Source
const TeacherSuffix = "-teacher"

TeacherSuffix is the suffix appended to the provider with the teacher scope.

Variables

View Source
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 Add

func Add(cookie string, userID uint64)

Add adds cookie for userID, replacing userID's current cookie, if any.

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 Get

func Get(cookie string) uint64

func GetCallbackURL

func GetCallbackURL(baseURL, provider string) string

GetCallbackURL returns the callback URL for a given base URL and a provider.

func GetEventsURL

func GetEventsURL(baseURL, provider string) string

GetEventsURL returns the event URL for a given base URL and a provider.

func GetProviderURL

func GetProviderURL(baseURL, route, provider, endpoint string) string

GetProviderURL returns a URL endpoint given a base URL and a provider.

func GetProviders

func GetProviders() *pb.Providers

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

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) FetchUser

func (p *FakeProvider) FetchUser(session goth.Session) (goth.User, error)

FetchUser is used only for testing.

func (*FakeProvider) Name

func (p *FakeProvider) Name() string

Name 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

type FakeSession struct {
	ID          string
	Name        string
	Email       string
	AuthURL     string
	AccessToken string
}

FakeSession is used only for testing.

func (*FakeSession) Authorize

func (s *FakeSession) Authorize(provider goth.Provider, params goth.Params) (string, error)

Authorize 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 NewScms

func NewScms() *Scms

NewScms returns reference to new thread-safe map

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.

func (*Scms) GetSCM

func (s *Scms) GetSCM(accessToken string) (sc scm.SCM, ok bool)

GetSCM returns an scm client for the given access token, if such token exists; otherwise, nil and false is returned.

type UserSession

type UserSession struct {
	ID        uint64
	Providers map[string]struct{}
}

UserSession holds user session information.

func (UserSession) String

func (us UserSession) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL