oauth

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderGithub = "github"

	// Github API endpoints
	GithubURLAuthorize = "/login/oauth/authorize"
	GithubURLToken     = "/login/oauth/access_token"
	GithubURLUser      = "/user"
	GithubURLEmails    = "/user/emails"
)

Variables

View Source
var ErrInvalidClientCredentials = errors.New("invalid client credentials")

Functions

func CallbackURL

func CallbackURL(appID string) string

Types

type App

type App struct {
	ID           string
	ClientID     string
	ClientSecret string
	RedirectURL  url.URL
	AuthHost     url.URL
	APIHost      url.URL
	Provider     string
}

type AuthorizationRequest

type AuthorizationRequest struct {
	AppID    string `param:"app_id"`
	ClientID string `query:"client_id"`
	Scopes   string `query:"scopes"`
	State    string `query:"state"`
}

type CallbackRequest

type CallbackRequest struct {
	AppID string `param:"app_id"`
	Code  string `query:"code"`
	State string `query:"state"`
}

type Factory

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

func NewFactory

func NewFactory(apps map[string]*App) *Factory

func (*Factory) GetBackend

func (f *Factory) GetBackend(appID string) (IBackend, error)

type Github

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

func (*Github) AuthorizationURL

func (g *Github) AuthorizationURL(state string, scopes []string) string

func (*Github) GetToken

func (g *Github) GetToken(ctx context.Context, code string) (*oauth2.Token, error)

func (*Github) GetUser

func (g *Github) GetUser(ctx context.Context, token *oauth2.Token) (*model.User, error)

func (*Github) RefreshToken

func (g *Github) RefreshToken(ctx context.Context, refreshToken string) (*oauth2.Token, error)

type GithubEmail

type GithubEmail struct {
	Email    string `json:"email"`
	Primary  bool   `json:"primary"`
	Verified bool   `json:"verified"`
}

type GithubEmails

type GithubEmails []GithubEmail

func (GithubEmails) PrimaryEmail

func (r GithubEmails) PrimaryEmail() (string, error)

type GithubUserResponse

type GithubUserResponse struct {
	ID    int    `json:"id"`
	Email string `json:"email"`
	Login string `json:"login"`
	Name  string `json:"name"`
}

func (*GithubUserResponse) ToModel

func (r *GithubUserResponse) ToModel() *model.User

type Handler

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

func NewHandler

func NewHandler(runner *model.Runner, deepsource *model.DeepSource, store store.Store, tokenService *token.Service, factory *Factory) *Handler

func (*Handler) HandleAuthorize

func (h *Handler) HandleAuthorize(c echo.Context) error

func (*Handler) HandleCallback

func (h *Handler) HandleCallback(c echo.Context) error

func (*Handler) HandleRefresh

func (h *Handler) HandleRefresh(c echo.Context) error

func (*Handler) HandleSession

func (h *Handler) HandleSession(c echo.Context) error

func (*Handler) HandleToken

func (h *Handler) HandleToken(c echo.Context) error

func (*Handler) HandleUser

func (h *Handler) HandleUser(c echo.Context) error

type IBackend

type IBackend interface {
	AuthorizationURL(state string, scopes []string) string
	GetToken(ctx context.Context, code string) (*oauth2.Token, error)
	RefreshToken(ctx context.Context, refreshToken string) (*oauth2.Token, error)
	GetUser(ctx context.Context, token *oauth2.Token) (*model.User, error)
}

func NewGithub

func NewGithub(app *App) (IBackend, error)

type RefreshRequest

type RefreshRequest struct {
	AppID        string `param:"app_id"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	RefreshToken string `json:"refresh_token"`
}

type SessionRequest

type SessionRequest struct {
	AppID string `param:"app_id"`
	State string `query:"state"`
}

type TokenRequest

type TokenRequest struct {
	AppID        string `param:"app_id"`
	Code         string `query:"code" json:"code"`
	ClientID     string `query:"client_id" json:"client_id"`
	ClientSecret string `query:"client_secret" json:"client_secret"`
}

type UserRequest

type UserRequest struct {
	AppID       string
	AccessToken string
}

func (*UserRequest) Parse

func (r *UserRequest) Parse(c echo.Context) error

type UserResponse

type UserResponse struct {
	ID       string `json:"id"`
	UserName string `json:"username"`
	FullName string `json:"full_name"`
	Email    string `json:"email"`
}

Jump to

Keyboard shortcuts

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