auth

package
v0.0.0-...-ada06ba Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CurrentOrganization current organization key
	CurrentOrganization utils.ContextKey = "org"
)
View Source
const DroneHookTokenType bauth.TokenType = "hook"

DroneHookTokenType is the Drone token type used for API sessions

View Source
const DroneSessionCookie = "user_sess"

DroneSessionCookie holds the name of the Cookie Drone sets in the browser

View Source
const DroneSessionCookieType = "sess"

DroneSessionCookieType is the Drone token type used for browser sessions

View Source
const DroneUserTokenType bauth.TokenType = "user"

DroneUserTokenType is the Drone token type used for API sessions

Variables

View Source
var (
	Auth *auth.Auth

	// JwtIssuer ("iss") claim identifies principal that issued the JWT
	JwtIssuer string

	// JwtAudience ("aud") claim identifies the recipients that the JWT is intended for
	JwtAudience string

	Handler gin.HandlerFunc
)

Init authorization

Functions

func AddDefaultRoleForUser

func AddDefaultRoleForUser(userID interface{})

AddDefaultRoleForUser adds all the default non-org-specific role to a user.

func AddDefaultRoleForVirtualUser

func AddDefaultRoleForVirtualUser(userID interface{})

AddDefaultRoleForVirtualUser adds org list role to a virtual user.

func AddOrgRoleForUser

func AddOrgRoleForUser(userID interface{}, orgids ...uint)

AddOrgRoleForUser adds a user to an organization by adding the associated organization role.

func AddOrgRoles

func AddOrgRoles(orgids ...uint)

AddOrgRoles creates an organization role, by adding the default (*) org policies for the given organization.

func BanzaiLogoutHandler

func BanzaiLogoutHandler(context *auth.Context)

BanzaiLogoutHandler does the qor/auth DefaultLogoutHandler default logout behaviour + deleting the Drone cookie

func DelCookie

func DelCookie(w http.ResponseWriter, r *http.Request, name string)

DelCookie deletes a cookie.

func DeleteOrgRoleForUser

func DeleteOrgRoleForUser(userID uint, orgid uint)

DeleteOrgRoleForUser removes a user from an organization by removing the associated organization role.

func DeleteToken

func DeleteToken(c *gin.Context)

DeleteToken deletes the calling user's access token specified by token id

func GenerateToken

func GenerateToken(c *gin.Context)

GenerateToken generates token from context

func GetGithubUser

func GetGithubUser(accessToken string) (*github.User, error)

GetGithubUser returns github user by token

func GetOrgNameFromVirtualUser

func GetOrgNameFromVirtualUser(virtualUser string) string

GetOrgNameFromVirtualUser returns the organization name for which the virtual user has access

func GetTokens

func GetTokens(c *gin.Context)

GetTokens returns the calling user's access tokens

func GormErrorToStatusCode

func GormErrorToStatusCode(err error) int

GormErrorToStatusCode translates GORM errors to HTTP status codes

func Init

func Init()

Init initializes the auth

func Install

func Install(engine *gin.Engine)

Install the whole OAuth and JWT Token based auth/authz mechanism to the specified Gin Engine.

func IsHttps

func IsHttps(r *http.Request) bool

IsHttps is a helper function that evaluates the http.Request and returns True if the Request uses HTTPS. It is able to detect, using the X-Forwarded-Proto, if the original request was HTTPS and routed through a reverse proxy with SSL termination.

func NewAuthorizer

func NewAuthorizer() gin.HandlerFunc

NewAuthorizer returns the MySQL based default authorizer

func NewGithubAuthorizeHandler

func NewGithubAuthorizeHandler(provider *githubauth.GithubProvider) func(context *auth.Context) (*claims.Claims, error)

NewGithubAuthorizeHandler handler for Github auth

func SetCookie

func SetCookie(w http.ResponseWriter, r *http.Request, name, value string)

SetCookie writes the cookie value.

Types

type BanzaiSessionStorer

type BanzaiSessionStorer struct {
	auth.SessionStorer
}

BanzaiSessionStorer stores the banzai session

func (*BanzaiSessionStorer) Update

func (sessionStorer *BanzaiSessionStorer) Update(w http.ResponseWriter, req *http.Request, claims *claims.Claims) error

Update updates the BanzaiSessionStorer

type BanzaiUserStorer

type BanzaiUserStorer struct {
	auth.UserStorer
	// contains filtered or unexported fields
}

BanzaiUserStorer struct

func (BanzaiUserStorer) Save

func (bus BanzaiUserStorer) Save(schema *auth.Schema, context *auth.Context) (user interface{}, userID string, err error)

Save differs from the default UserStorer.Save() in that it extracts Token and Login and saves to Drone DB as well

type BearerAuthorizer

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

BearerAuthorizer stores the casbin handler

func (*BearerAuthorizer) CheckPermission

func (a *BearerAuthorizer) CheckPermission(r *http.Request) bool

CheckPermission checks the user/method/path combination from the request. Returns true (permission granted) or false (permission forbidden)

func (*BearerAuthorizer) GetUserID

func (a *BearerAuthorizer) GetUserID(r *http.Request) string

GetUserID gets the user name from the request. Currently, only HTTP Bearer token authentication is supported

func (*BearerAuthorizer) RequirePermission

func (a *BearerAuthorizer) RequirePermission(c *gin.Context)

RequirePermission returns the 403 Forbidden to the client

type DroneClaims

type DroneClaims struct {
	*claims.Claims
	Type bauth.TokenType `json:"type,omitempty"`
	Text string          `json:"text,omitempty"`
}

DroneClaims struct to store the drone claim related things

type DroneUser

type DroneUser struct {
	ID     int64  `gorm:"column:user_id;primary_key"`
	Login  string `gorm:"column:user_login"`
	Token  string `gorm:"column:user_token"`
	Secret string `gorm:"column:user_secret"`
	Expiry int64  `gorm:"column:user_expiry"`
	Email  string `gorm:"column:user_email"`
	Image  string `gorm:"column:user_avatar"`
	Active bool   `gorm:"column:user_active"`
	Admin  bool   `gorm:"column:user_admin"`
	Hash   string `gorm:"column:user_hash"`
	Synced int64  `gorm:"column:user_synced"`
}

DroneUser struct

func (DroneUser) TableName

func (DroneUser) TableName() string

TableName sets DroneUser's table name

type GithubExtraInfo

type GithubExtraInfo struct {
	Login string
	Token string
}

GithubExtraInfo struct for github credentials

type Organization

type Organization struct {
	ID        uint                 `gorm:"primary_key" json:"id"`
	GithubID  *int64               `gorm:"unique" json:"githubId,omitempty"`
	CreatedAt time.Time            `json:"createdAt"`
	UpdatedAt time.Time            `json:"updatedAt"`
	Name      string               `gorm:"unique,not null" json:"name"`
	Users     []User               `gorm:"many2many:user_organizations" json:"users,omitempty"`
	Clusters  []model.ClusterModel `gorm:"foreignkey:organization_id" json:"clusters,omitempty"`
	Role      string               `json:"-" gorm:"-"` // Used only internally
}

Organization struct

func GetCurrentOrganization

func GetCurrentOrganization(req *http.Request) *Organization

GetCurrentOrganization return the user's organization

func (*Organization) IDString

func (org *Organization) IDString() string

IDString returns the ID as string

type User

type User struct {
	ID            uint           `gorm:"primary_key" json:"id"`
	CreatedAt     time.Time      `json:"createdAt"`
	UpdatedAt     time.Time      `json:"updatedAt"`
	Name          string         `form:"name" json:"name,omitempty"`
	Email         string         `form:"email" json:"email,omitempty"`
	Login         string         `gorm:"unique;not null" form:"login" json:"login"`
	Image         string         `form:"image" json:"image,omitempty"`
	Organizations []Organization `gorm:"many2many:user_organizations" json:"organizations,omitempty"`
	Virtual       bool           `json:"-" gorm:"-"` // Used only internally
}

User struct

func GetCurrentUser

func GetCurrentUser(req *http.Request) *User

GetCurrentUser returns the current user

func GetCurrentUserFromDB

func GetCurrentUserFromDB(req *http.Request) (*User, error)

GetCurrentUserFromDB returns the current user from the database

func (*User) IDString

func (user *User) IDString() string

IDString returns the ID as string

type UserOrganization

type UserOrganization struct {
	UserID         uint
	OrganizationID uint
	Role           string `gorm:"default:'admin'"`
}

UserOrganization describes the user organization

Jump to

Keyboard shortcuts

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