server better organized

This commit is contained in:
2026-01-24 12:41:32 -07:00
parent 7154494016
commit ff231897df
3 changed files with 43 additions and 57 deletions
+9 -4
View File
@@ -49,8 +49,8 @@ func NewAuth(
}
}
// AddIdentity will add an Identity to the context that can then be retrieved via GetIdentity.
func (a *Auth) AddIdentity(c *gin.Context) {
// Identify will add an Identity to the context that can then be retrieved via GetIdentity.
func (a *Auth) Identify(c *gin.Context) {
if err := a.addIdentity(c); err != nil {
c.Error(err)
c.Abort()
@@ -98,9 +98,14 @@ func (a *Auth) addIdentity(c *gin.Context) error {
return nil
}
// Authenticate should only be used along with and after AddIdentity
// Authenticate should only be used along with and after Identify
// Typically used with response.Handler to make a gin.HandlerFunc.
func (a *Auth) Authenticate(assertions ...AuthorizationAssertions) func(c *gin.Context) (response.Response, error) {
func (a *Auth) Authenticate(assertions ...AuthorizationAssertions) func(c *gin.Context) {
return response.Handler(a.AuthenticateHandler(assertions...))
}
// See Authenticate.
func (a *Auth) AuthenticateHandler(assertions ...AuthorizationAssertions) func(c *gin.Context) (response.Response, error) {
return func(c *gin.Context) (response.Response, error) {
id, ok := getIdentity(c)
if !ok {