Documentation
¶
Index ¶
- Constants
- Variables
- func GetAdmin(req *http.Request) bool
- func GetMember(req *http.Request) bool
- func GetUser(req *http.Request) auth.User
- func WhoAmIHandler(res http.ResponseWriter, req *http.Request)
- type Authenticator
- func (a *Authenticator) CallbackHandler(res http.ResponseWriter, req *http.Request)
- func (a *Authenticator) CheckMembership(token string, login string) (string, error)
- func (a *Authenticator) LoginHandler(res http.ResponseWriter, req *http.Request)
- func (a *Authenticator) LogoutHandler(res http.ResponseWriter, req *http.Request)
- func (a *Authenticator) Middleware(next http.Handler) http.Handler
- func (a *Authenticator) ParseJWTCookie(cookie string, w http.ResponseWriter, r *http.Request) (*jwt.Token, error)
- type Config
- type GithubAccessTokenRequest
- type GithubAccessTokenResponse
- type GithubData
- type GithubMemberUserResponse
- type GithubUserResponse
Constants ¶
const AuthContextKey = "auth"
const (
SCOPES = "read:user,user:email,read:org,read:members"
)
Variables ¶
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 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
}