auth

package
v0.0.0-...-b7b4bc5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SCOPES = "read:user,user:email"
)

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

Functions

This section is empty.

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)

CallbackHandler handles the OAuth callback, obtaining the GitHub's Bearer token for the logged-in user, and generating a wrapper JWT for our upld session.

func (*Authenticator) LoginHandler

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

LoginHandler handles login requests, redirecting the web client to GitHub's first stage for the OAuth flow, where the user has to grant access to the specified scopes

func (*Authenticator) RequireJWTCookie

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

func (*Authenticator) WhoAmIHandler

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

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?
}

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 GithubUserResponse

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

type User

type User struct {
	Username  string `json:"username"`
	AvatarUrl string `json:"avatarUrl"`
	Name      string `json:"name"`
	Email     string `json:"email"`
}

Jump to

Keyboard shortcuts

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