authservice

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppLike

type AppLike interface {
	DB() db.Client
	Key() string
	Config() *fs.Config
	GetAuthProvider(string) fs.AuthProvider
	Roles() []*fs.Role
	JwtCustomClaimsFunc() fs.JwtCustomClaimsFunc
}

type AuthService

type AuthService struct {
	DB                  func() db.Client
	AppKey              func() string
	AppConfig           func() *fs.Config
	GetAuthProvider     func(string) fs.AuthProvider
	Roles               func() []*fs.Role
	JwtCustomClaimsFunc func() fs.JwtCustomClaimsFunc
}

func New

func New(app AppLike) *AuthService

func (*AuthService) AuthUserCan added in v0.6.0

func (as *AuthService) AuthUserCan(c fs.Context, user *fs.User, resourceID string) bool

func (*AuthService) Authorize added in v0.3.0

func (as *AuthService) Authorize(c fs.Context) error

func (*AuthService) Callback

func (as *AuthService) Callback(c fs.Context, _ any) (u *fs.JWTTokens, err error)

func (*AuthService) CleanupExpiredSessions added in v0.9.3

func (as *AuthService) CleanupExpiredSessions(c fs.Context) (int, error)

CleanupExpiredSessions removes expired sessions from the database

func (*AuthService) CreateResource added in v0.6.0

func (as *AuthService) CreateResource(api *fs.Resource, authProviders map[string]fs.AuthProvider)

func (*AuthService) GenerateJWTTokens added in v0.9.3

func (as *AuthService) GenerateJWTTokens(c fs.Context, user *fs.User) (*fs.JWTTokens, error)

GenerateJWTTokens generates tokens for a user. If refresh token is enabled, it generates both access and refresh tokens. Otherwise, it generates only an access token.

func (*AuthService) GetAccessTokenExpiration added in v0.9.3

func (as *AuthService) GetAccessTokenExpiration() time.Duration

GetAccessTokenExpiration returns the access token expiration duration

func (*AuthService) GetPermission added in v0.3.0

func (as *AuthService) GetPermission(roleID uint64, resource string) *fs.Permission

func (*AuthService) GetRefreshTokenExpiration added in v0.9.3

func (as *AuthService) GetRefreshTokenExpiration() time.Duration

GetRefreshTokenExpiration returns the refresh token expiration duration

func (*AuthService) GetRolesFromIDs added in v0.3.0

func (as *AuthService) GetRolesFromIDs(ids []uint64) []*fs.Role

func (*AuthService) IsRefreshTokenEnabled added in v0.9.3

func (as *AuthService) IsRefreshTokenEnabled() bool

IsRefreshTokenEnabled returns whether refresh token feature is enabled

func (*AuthService) LocalLoginWrapper added in v0.9.3

func (as *AuthService) LocalLoginWrapper(
	localAuthProvider *auth.LocalProvider,
) func(c fs.Context, payload *auth.LoginData) (*fs.JWTTokens, error)

LocalLoginWrapper wraps the local login to support token generation

func (*AuthService) Login

func (as *AuthService) Login(c fs.Context, _ any) (_ any, err error)

func (*AuthService) Logout added in v0.9.3

func (as *AuthService) Logout(c fs.Context, req *RefreshTokenRequest) (bool, error)

Logout invalidates the refresh token

func (*AuthService) LogoutAll added in v0.9.3

func (as *AuthService) LogoutAll(c fs.Context, _ any) (bool, error)

LogoutAll invalidates all sessions for the current user

func (*AuthService) Me added in v0.5.0

func (as *AuthService) Me(c fs.Context, _ any) (*fs.User, error)

func (*AuthService) ParseUser added in v0.3.0

func (as *AuthService) ParseUser(c fs.Context) error

func (*AuthService) RefreshToken added in v0.9.3

func (as *AuthService) RefreshToken(c fs.Context, req *RefreshTokenRequest) (*fs.JWTTokens, error)

RefreshToken handles the token refresh endpoint

func (*AuthService) VerifyIDToken added in v0.7.5

func (as *AuthService) VerifyIDToken(c fs.Context, payload fs.IDToken) (u *fs.JWTTokens, err error)

type RefreshTokenRequest added in v0.9.3

type RefreshTokenRequest struct {
	RefreshToken string `json:"refresh_token"`
}

RefreshTokenRequest represents the request to refresh a token

Jump to

Keyboard shortcuts

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