auth

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("Unauthorized")

Functions

func CheckOrgMembership

func CheckOrgMembership(ctx context.Context, accessToken, org string) (bool, error)

CheckOrgMembership returns true if the authenticated user belongs to the given organization.

func ExchangeCodeForToken

func ExchangeCodeForToken(ctx context.Context, clientID, clientSecret, code string) (string, error)

ExchangeCodeForToken exchanges a GitHub OAuth code for an access token.

func FromContextKey

func FromContextKey(ctx context.Context, claims *Claims) context.Context

func GenerateOAuthState

func GenerateOAuthState(secret []byte, sessionID string) (string, error)

GenerateOAuthState creates a random nonce and signs it with the given secret, returning a state string suitable for use in the OAuth `state` parameter. The format is: base64url(nonce) + "." + base64url(HMAC-SHA256(nonce, secret))

func GetUsername

func GetUsername(ctx context.Context, accessToken string) (string, error)

GetUsername retrieves the authenticated GitHub user's login name.

func GithubAuthURL

func GithubAuthURL(clientID, state, redirectURI string, isOrg bool) string

func IssueSessionToken

func IssueSessionToken(secret []byte, username string) (string, error)

IssueSessionToken creates a signed JWT session token for the given user. The token is valid for 24 hours.

func ValidateOAuthState

func ValidateOAuthState(secret []byte, state string) (string, error)

ValidateOAuthState verifies that the given state string was produced by GenerateOAuthState with the same secret. Returns an error if validation fails.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
}

Claims is the custom JWT claims structure.

func ParseToken

func ParseToken(secret []byte, tokenString string) (*Claims, error)

ParseToken parses and validates a signed JWT token, returning the claims.

func ToContext

func ToContext(ctx context.Context) (*Claims, error)

Jump to

Keyboard shortcuts

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