auth

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const AuthContextKey = "auth"
View Source
const (
	SCOPES = "read:user,user:email,read:org,read:members"
)

Variables

View Source
var (
	GithubAuthorizeURL, _   = url.Parse("https://github.com/login/oauth/authorize")
	GithubAccessTokenURL, _ = url.Parse("https://github.com/login/oauth/access_token")
	GithubUserURL, _        = url.Parse("https://api.github.com/user")
	GithubMemberURL, _      = url.Parse("https://api.github.com/orgs/cartabinaria/memberships/")
)

Functions

func GetAdmin

func GetAdmin(req *http.Request) bool

func GetMember added in v0.3.7

func GetMember(req *http.Request) bool

func GetUser

func GetUser(req *http.Request) auth.User

func WhoAmIHandler

func WhoAmIHandler(res http.ResponseWriter, req *http.Request)

@Summary Who am I @Description Return user information if logged in @Tags login @Produce json @Success 200 {object} User @Failure 400 {object} string @Router /whoami [get]

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(config *Config) *Authenticator

func (*Authenticator) CallbackHandler

func (a *Authenticator) CallbackHandler(res http.ResponseWriter, req *http.Request)

@Summary Login Callback @Description CallbackHandler handles the OAuth callback, obtaining the GitHub's Bearer token @Description for the logged-in user, and generating a wrapper JWT for our session. @Tags login @Param code query string true "code query parameter" @Param redirect_uri query string true "url to redirect if login is successful" @Success 200 {object} string @Failure 400 {object} httputil.ApiError @Router /login/callback [get]

func (*Authenticator) CheckMembership

func (a *Authenticator) CheckMembership(token string, login string) (string, error)

func (*Authenticator) LoginHandler

func (a *Authenticator) LoginHandler(res http.ResponseWriter, req *http.Request)

@Summary Login user @Description LoginHandler handles login requests, redirecting the web client to GitHub's first stage @Description for the OAuth flow, where the user has to grant access to the specified scopes @Tags login @Param redirect_uri query string true "url to redirect if login is successful" Url @Success 200 {object} string @Failure 400 {object} httputil.ApiError @Router /login [get]

func (*Authenticator) LogoutHandler

func (a *Authenticator) LogoutHandler(res http.ResponseWriter, req *http.Request)

@Summary Logout user @Description Reset the cookie @Tags login @Param redirect_uri query string true "url to redirect if login is successful" Url @Success 200 {object} string @Failure 400 {object} httputil.ApiError @Router /logout [get]

func (*Authenticator) Middleware

func (a *Authenticator) Middleware(next http.Handler) http.Handler

func (*Authenticator) ParseJWTCookie

func (a *Authenticator) ParseJWTCookie(cookie string, w http.ResponseWriter, r *http.Request) (*jwt.Token, error)

type Config

type Config struct {
	ClientID     string        // The OAuth client ID
	ClientSecret string        // The OAuth client secret
	BaseURL      *url.URL      // The base URL from where cartabinaria/upld is being served from
	SigningKey   []byte        // The key to sign the JWTs with
	Expiration   time.Duration // How long should user sessions last?
	CookieDomain string        // The domain for the generated cookies
}

type GithubAccessTokenRequest

type GithubAccessTokenRequest struct {
	ClientId     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Code         string `json:"code"`
}

GithubAccessTokenRequest is the request we send to GitHub to request for a token

type GithubAccessTokenResponse

type GithubAccessTokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
}

GithubAccessTokenResponse is the response received from GitHub when requesting for a token

type GithubData

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

type GithubMemberUserResponse

type GithubMemberUserResponse struct {
	Message string `json:"message,omitempty"`
	Role    string `json:"role,omitempty"`
}

type GithubUserResponse

type GithubUserResponse struct {
	ID        uint   `json:"id"`
	Name      string `json:"name"`
	AvatarUrl string `json:"avatar_url"`
	Email     string `json:"email"`
	Login     string `json:"login"`
	Url       string `json:"url"`
}

Jump to

Keyboard shortcuts

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