auth

package
v0.0.0-...-70c7384 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeJWT

func MakeJWT(user model.User) (string, error)

Types

type GitHubClient

type GitHubClient interface {
	ExchangeCodeToAccessKey(ctx context.Context, clientID, clientSecret, code string) (string, error)
	IsMember(ctx context.Context, accessKey, org, user string) (bool, error)
	GetUser(ctx context.Context, accessKey, user string) (*github.User, error)
}

type GitHubClientMock

type GitHubClientMock struct {
	// ExchangeCodeToAccessKeyFunc mocks the ExchangeCodeToAccessKey method.
	ExchangeCodeToAccessKeyFunc func(ctx context.Context, clientID string, clientSecret string, code string) (string, error)

	// GetUserFunc mocks the GetUser method.
	GetUserFunc func(ctx context.Context, accessKey string, user string) (*github.User, error)

	// IsMemberFunc mocks the IsMember method.
	IsMemberFunc func(ctx context.Context, accessKey string, org string, user string) (bool, error)
	// contains filtered or unexported fields
}

GitHubClientMock is a mock implementation of GitHubClient.

func TestSomethingThatUsesGitHubClient(t *testing.T) {

	// make and configure a mocked GitHubClient
	mockedGitHubClient := &GitHubClientMock{
		ExchangeCodeToAccessKeyFunc: func(ctx context.Context, clientID string, clientSecret string, code string) (string, error) {
			panic("mock out the ExchangeCodeToAccessKey method")
		},
		GetUserFunc: func(ctx context.Context, accessKey string, user string) (*github.User, error) {
			panic("mock out the GetUser method")
		},
		IsMemberFunc: func(ctx context.Context, accessKey string, org string, user string) (bool, error) {
			panic("mock out the IsMember method")
		},
	}

	// use mockedGitHubClient in code that requires GitHubClient
	// and then make assertions.

}

func (*GitHubClientMock) ExchangeCodeToAccessKey

func (mock *GitHubClientMock) ExchangeCodeToAccessKey(ctx context.Context, clientID string, clientSecret string, code string) (string, error)

ExchangeCodeToAccessKey calls ExchangeCodeToAccessKeyFunc.

func (*GitHubClientMock) ExchangeCodeToAccessKeyCalls

func (mock *GitHubClientMock) ExchangeCodeToAccessKeyCalls() []struct {
	Ctx          context.Context
	ClientID     string
	ClientSecret string
	Code         string
}

ExchangeCodeToAccessKeyCalls gets all the calls that were made to ExchangeCodeToAccessKey. Check the length with:

len(mockedGitHubClient.ExchangeCodeToAccessKeyCalls())

func (*GitHubClientMock) GetUser

func (mock *GitHubClientMock) GetUser(ctx context.Context, accessKey string, user string) (*github.User, error)

GetUser calls GetUserFunc.

func (*GitHubClientMock) GetUserCalls

func (mock *GitHubClientMock) GetUserCalls() []struct {
	Ctx       context.Context
	AccessKey string
	User      string
}

GetUserCalls gets all the calls that were made to GetUser. Check the length with:

len(mockedGitHubClient.GetUserCalls())

func (*GitHubClientMock) IsMember

func (mock *GitHubClientMock) IsMember(ctx context.Context, accessKey string, org string, user string) (bool, error)

IsMember calls IsMemberFunc.

func (*GitHubClientMock) IsMemberCalls

func (mock *GitHubClientMock) IsMemberCalls() []struct {
	Ctx       context.Context
	AccessKey string
	Org       string
	User      string
}

IsMemberCalls gets all the calls that were made to IsMember. Check the length with:

len(mockedGitHubClient.IsMemberCalls())

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(githubClient GitHubClient, storage Storage, ghClientID, ghClientSecret string) *Service

func (*Service) GitHubAuthCallback

func (s *Service) GitHubAuthCallback(ctx context.Context, sessionCode string) (*model.User, string, error)
func (s *Service) GitHubAuthLink() string

func (*Service) RegisterUser

func (s *Service) RegisterUser(ctx context.Context, ghUser *github.User, accessKey string) (*model.User, error)

type Storage

type Storage interface {
	CreateOrUpdate(context.Context, model.User) (*model.User, error)
	Update(context.Context, model.User) error
	GetByGitHubLogin(context.Context, string) (*model.User, error)
	Deactivate(context.Context, string) error
}

Jump to

Keyboard shortcuts

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