2021-02-24 15:24:45 -05:00
|
|
|
package authentication
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2021-02-26 16:17:04 -05:00
|
|
|
// AuthContext contains all information that the AuthProvider needs to perform the authentication.
|
2021-02-24 15:24:45 -05:00
|
|
|
type AuthContext struct {
|
|
|
|
Username string // email or username
|
2021-02-26 16:17:04 -05:00
|
|
|
Password string
|
2021-02-24 15:24:45 -05:00
|
|
|
Callback string // callback for OIDC
|
|
|
|
}
|
|
|
|
|
|
|
|
type AuthProviderType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
AuthProviderTypePassword AuthProviderType = "password"
|
|
|
|
AuthProviderTypeOauth AuthProviderType = "oauth"
|
|
|
|
)
|
|
|
|
|
2021-02-26 16:17:04 -05:00
|
|
|
// AuthProvider is a interface that can be implemented by different authentication providers like LDAP, OAUTH, ...
|
2021-02-24 15:24:45 -05:00
|
|
|
type AuthProvider interface {
|
|
|
|
GetName() string
|
|
|
|
GetType() AuthProviderType
|
|
|
|
GetPriority() int // lower number = higher priority
|
|
|
|
|
|
|
|
Login(*AuthContext) (string, error)
|
|
|
|
Logout(*AuthContext) error
|
|
|
|
GetUserModel(*AuthContext) (*User, error)
|
|
|
|
|
|
|
|
SetupRoutes(routes *gin.RouterGroup)
|
|
|
|
}
|