csh_auth

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 13 Imported by: 0

README

csh-auth

An @ComputerScienceHouse authentication wrapper for Gin.

Usage

Initialize your csh-auth object
auth := csh-auth.Init(
    clientID            // the OIDC client ID
    clientSecret        // the OIDC client secret
    serverURL           // the "base" URL that this service is hosted from, e.g. "http://localhost:8000"
    loginURL            // the URL for users to start the OAuth flow and login.
                        // Commonly, this is set to something like ServerHost+"/auth/login"
    callbackURL         // the URL that users will be redirected to at the end of the OAuth flow.
                        // Commonly, this is set to something like ServerHost+"/auth/callback"
    scopes              // pick scopes the application will use
)
Add csh-auth endpoints for user login
r.GET("/auth/login", auth.HandleLogin) // This endpoint should match the path for loginURL
r.GET("/auth/callback", auth.HandleCallback) // This endpoint should match the path for callbackURL
r.GET("/auth/logout", auth.HandleLogout)
Add endpoints to be behind authentication

For client authentication, use auth.CookieMiddleware()
For application authentication via Bearer tokens, use auth.HeaderMiddleware(). The HeaderMiddleware only accepts the Authorization header with the format Bearer: <JWT AccessToken>.

For a single route: r.GET("/locked/prize", auth.CookieMiddleware(), endpoint_hidden_prize)
This works because Gin will run the widest scope function to the most narrow scope function, in order.

For more/all routes: Check the Gin Middleware documentation page.

Get user information

The information for a user is located at gin.Context#Get("cshauth"). This information includes the JWT information as well.

Documentation

Index

Constants

View Source
const ContextKey = "cshauth"
View Source
const CookieName = "Auth"
View Source
const ProviderURI = "https://sso.csh.rit.edu/auth/realms/csh"

Variables

View Source
var StateLookup map[string]string

Functions

This section is empty.

Types

type Auth

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

func Init

func Init(oidcClientID string, oidcClientSecret string, serverURL string, loginURL string, callbackURL string, scopes []string) (Auth, error)

func (*Auth) CookieMiddleware

func (auth *Auth) CookieMiddleware() gin.HandlerFunc

func (*Auth) HandleCallback

func (auth *Auth) HandleCallback(c *gin.Context)

func (*Auth) HandleLogin

func (auth *Auth) HandleLogin(c *gin.Context)

func (*Auth) HandleLogout

func (auth *Auth) HandleLogout(c *gin.Context)

func (*Auth) HeaderMiddleware

func (auth *Auth) HeaderMiddleware() gin.HandlerFunc

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UserInfo
}

type UserInfo

type UserInfo struct {
	Uuid     string   `json:"uuid"`
	Email    string   `json:"email"`
	Username string   `json:"preferred_username"`
	FullName string   `json:"name"`
	Groups   []string `json:"groups"`
}

Jump to

Keyboard shortcuts

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