auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CookieName string
View Source
var ErrBadGithubStatus = errors.New("bad status code from github")

ErrBadGithubStatus gets returned from GetGithubUser if a 200 is not returned from github

Functions

func CallbackHandler

func CallbackHandler(w http.ResponseWriter, r *http.Request)

CallbackHandler is the callback from Github to grab the auth token

func JWT

func JWT(token *jwt.Token) (interface{}, error)

TODO: Should the method of getting the token change?

func LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request)

LoginHandler will send the request to Github to make sure that the user is logged in

func ShowClaims

func ShowClaims(w http.ResponseWriter, r *http.Request)

ShowClaims shows the claims in the users cookie for the frontend

Types

type BytegolfUser

type BytegolfUser struct {
	BGID            string
	LastUpdatedTime time.Time
	CreatedTime     time.Time

	GithubUser GithubUser
}

BytegolfUser is the structure of how bytegolf user's are stored in the database

func BGUser

func BGUser(ghu *GithubUser) (*BytegolfUser, error)

BGUser returns a bytegolf user based on the github user. Will create one if one does not exist yet

func NewBytegolfUser

func NewBytegolfUser(ghu GithubUser) *BytegolfUser

NewBytegolfUser returns a new bytegolf user

func (*BytegolfUser) Collection

func (bgu *BytegolfUser) Collection() *firestore.CollectionRef

func (*BytegolfUser) Data

func (bgu *BytegolfUser) Data() interface{}

func (*BytegolfUser) DocID

func (bgu *BytegolfUser) DocID() string

func (BytegolfUser) ToProfile

func (bgu BytegolfUser) ToProfile() BytegolfUserProfile

ToProfile takes the BytegolfUser (Database object) and mutates it to a Profile (Frontend object)

type BytegolfUserProfile

type BytegolfUserProfile struct {
	BGID        string `json:"BGID"`
	DisplayName string `json:"DisplayName"`
	GithubURL   string `json:"GithubUrl"`
	AvatarURL   string `json:"AvatarUrl"`
}

BytegolfUserProfile is the BytegolfUser struct but with no sensitive fields

type Claims

type Claims struct {
	BGID string `json:"BGID"`

	jwt.StandardClaims
}

Claims is what gets stored in the JWT

func LoggedIn

func LoggedIn(r *http.Request) *Claims

type GithubUser

type GithubUser struct {
	ID        int64     `json:"id"`
	Login     string    `json:"login"`
	URL       string    `json:"html_url"`
	AvatarURL string    `json:"avatar_url"`
	UpdatedAt time.Time `json:"updated_at"`
}

GithubUser is the object that comes back from github on a user lookup

func GetGithubUser

func GetGithubUser(token string) (*GithubUser, error)

GetGithubUser gets a github user using their access token

Jump to

Keyboard shortcuts

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