This commit is contained in:
KaySar12 2024-08-14 12:06:18 +07:00
parent 74786ca6c8
commit bcaa226c29
12 changed files with 57 additions and 19 deletions

View File

@ -8,4 +8,5 @@ LogFileExt = log
DBPath = /var/lib/casaos/db DBPath = /var/lib/casaos/db
UserDataPath = /var/lib/casaos UserDataPath = /var/lib/casaos
OMVServer = http://10.0.0.4:1081/rpc.php OMVServer = http://10.0.0.4:1081/rpc.php
SecretKey = N1PCdw3M2B1TfJhoaY2mL736p2vCUc47 SecretKey = N1PCdw3M2B1TfJhoaY2mL736p2vCUc47
AuthentikServer = https://auth.c14soft.com

2
dist/metadata.json vendored
View File

@ -1 +1 @@
{"project_name":"casaos-user-service","tag":"v1.0.0","previous_tag":"","version":"1.0.1","commit":"c385748979d44c704f123d60348b8273856a0d2c","date":"2024-08-13T16:27:44.744967057+07:00","runtime":{"goos":"linux","goarch":"amd64"}} {"project_name":"casaos-user-service","tag":"v1.0.0","previous_tag":"","version":"1.0.1","commit":"74786ca6c859a55918f01be0bbb824dcf14b3018","date":"2024-08-14T11:40:02.309227418+07:00","runtime":{"goos":"linux","goarch":"amd64"}}

View File

@ -5,13 +5,14 @@ type CommonModel struct {
} }
type APPModel struct { type APPModel struct {
LogPath string LogPath string
LogSaveName string LogSaveName string
LogFileExt string LogFileExt string
UserDataPath string UserDataPath string
DBPath string DBPath string
OMVServer string OMVServer string
SecretKey string AuthentikServer string
SecretKey string
} }
type Result struct { type Result struct {

View File

@ -41,7 +41,7 @@ func GetDb(dbPath string) *gorm.DB {
gdb = db gdb = db
err = db.AutoMigrate(model2.UserDBModel{}, model.EventModel{}) err = db.AutoMigrate(model2.UserDBModel{}, model.EventModel{}, model2.AuthentikCredentialsDBModel{})
if err != nil { if err != nil {
logger.Error("check or create db error", zap.Any("error", err)) logger.Error("check or create db error", zap.Any("error", err))
} }

View File

@ -63,7 +63,7 @@ func EventListen() {
if event.Name == "local-storage:raid_status" { if event.Name == "local-storage:raid_status" {
continue continue
} }
service.MyService.Event().CreateEvemt(model) service.MyService.Event().CreateEvent(model)
// logger.Info("info", zap.Any("写入信息1", model)) // logger.Info("info", zap.Any("写入信息1", model))
// output, err := json.MarshalIndent(event, "", " ") // output, err := json.MarshalIndent(event, "", " ")
// if err != nil { // if err != nil {

View File

@ -31,7 +31,6 @@ func InitRouter() *gin.Engine {
r.POST("/v1/users/logout", v1.PostLogout) r.POST("/v1/users/logout", v1.PostLogout)
r.GET("/v1/users/name", v1.GetUserAllUsername) // all/name r.GET("/v1/users/name", v1.GetUserAllUsername) // all/name
r.POST("/v1/users/refresh", v1.PostUserRefreshToken) r.POST("/v1/users/refresh", v1.PostUserRefreshToken)
// No short-term modifications
r.GET("/v1/users/image", v1.GetUserImage) r.GET("/v1/users/image", v1.GetUserImage)
r.GET("/v1/users/:username", v1.GetUserInfoByUsername) r.GET("/v1/users/:username", v1.GetUserInfoByUsername)
r.GET("/v1/users/status", v1.GetUserStatus) // init/check r.GET("/v1/users/status", v1.GetUserStatus) // init/check

View File

@ -46,7 +46,7 @@ var (
baseURL = "https://auth.c14soft.com" baseURL = "https://auth.c14soft.com"
clientID = "6KwKSxLCtaQ4r6HoAn3gdNMbNOAf75j3SejLIAx7" clientID = "6KwKSxLCtaQ4r6HoAn3gdNMbNOAf75j3SejLIAx7"
clientSecret = "PE05fcDP4qESUmyZ1TNYpZNBxRPq70VpFI81vehsoJ6WhGz5yPXMljrFrOdMRdRhrYmF03fHWTZHgO9ZdNENrLN13BzL8CAgtEkTsyjXfgx9GvISheIjYfpSfvo219fL" clientSecret = "PE05fcDP4qESUmyZ1TNYpZNBxRPq70VpFI81vehsoJ6WhGz5yPXMljrFrOdMRdRhrYmF03fHWTZHgO9ZdNENrLN13BzL8CAgtEkTsyjXfgx9GvISheIjYfpSfvo219fL"
authURL = "https://auth.c14soft.com/application/o/nextzenos-oidc/" // authURL = "https://auth.c14soft.com/application/o/nextzenos-oidc/"
callbackURL = "http://172.26.157.79:8080/v1/users/oidc/callback" callbackURL = "http://172.26.157.79:8080/v1/users/oidc/callback"
) )
@ -331,7 +331,7 @@ func generateTokens(user model2.UserDBModel) (system_model.VerifyInformation, er
return system_model.VerifyInformation{ return system_model.VerifyInformation{
AccessToken: accessToken, AccessToken: accessToken,
RefreshToken: refreshToken, RefreshToken: refreshToken,
ExpiresAt: time.Now().Add(3 * time.Hour).Unix(), ExpiresAt: time.Now().Add(3 * time.Hour * time.Duration(1)).Unix(),
}, nil }, nil
} }

View File

@ -7,20 +7,38 @@ import (
"net/http" "net/http"
model2 "github.com/IceWhaleTech/CasaOS-UserService/service/model" model2 "github.com/IceWhaleTech/CasaOS-UserService/service/model"
"gorm.io/gorm"
) )
type AuthentikService interface { type AuthentikService interface {
GetUserInfo(accessToken string, baseURL string) (model2.AuthentikUser, error) GetUserInfo(accessToken string, baseURL string) (model2.AuthentikUser, error)
GetUserApp(accessToken string, baseURL string) (model2.AuthentikApplication, error) GetUserApp(accessToken string, baseURL string) (model2.AuthentikApplication, error)
CreateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel
UpdateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel
GetCredential(id int) model2.AuthentikCredentialsDBModel
} }
type authentikService struct { type authentikService struct {
db *gorm.DB
} }
var ( var (
APICorePrefix = "/api/v3/core" APICorePrefix = "/api/v3/core"
) )
func (a *authentikService) CreateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel {
a.db.Create(&m)
return m
}
func (a *authentikService) UpdateCredential(m model2.AuthentikCredentialsDBModel) model2.AuthentikCredentialsDBModel {
a.db.Model(&m).Where("id = ?", m.Id).Updates(m)
return m
}
func (a *authentikService) GetCredential(id int) model2.AuthentikCredentialsDBModel {
var m model2.AuthentikCredentialsDBModel
a.db.Limit(1).Where("id = ?", id).First(&m)
return m
}
func (a *authentikService) GetUserApp(accessToken string, baseURL string) (model2.AuthentikApplication, error) { func (a *authentikService) GetUserApp(accessToken string, baseURL string) (model2.AuthentikApplication, error) {
bearer := "Bearer " + accessToken bearer := "Bearer " + accessToken
path := baseURL + APICorePrefix + "/applications/" path := baseURL + APICorePrefix + "/applications/"
@ -93,6 +111,8 @@ func (a *authentikService) GetUserInfo(accessToken string, baseURL string) (mode
return user, nil return user, nil
} }
func NewAuthentikService() AuthentikService { func NewAuthentikService(db *gorm.DB) AuthentikService {
return &authentikService{} return &authentikService{
db: db,
}
} }

View File

@ -8,7 +8,7 @@ import (
) )
type EventService interface { type EventService interface {
CreateEvemt(m model.EventModel) model.EventModel CreateEvent(m model.EventModel) model.EventModel
GetEvents() (list []model.EventModel) GetEvents() (list []model.EventModel)
GetEventByUUID(uuid string) (m model.EventModel) GetEventByUUID(uuid string) (m model.EventModel)
DeleteEvent(uuid string) DeleteEvent(uuid string)
@ -19,7 +19,7 @@ type eventService struct {
db *gorm.DB db *gorm.DB
} }
func (e *eventService) CreateEvemt(m model.EventModel) model.EventModel { func (e *eventService) CreateEvent(m model.EventModel) model.EventModel {
e.db.Create(&m) e.db.Create(&m)
return m return m
} }

View File

@ -0,0 +1,17 @@
package model
import "time"
// Soon to be removed
type AuthentikCredentialsDBModel struct {
Id int `gorm:"column:id;primary_key" json:"id"`
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
Server string `json:"server"`
CreatedAt time.Time `gorm:"<-:create;autoCreateTime" json:"created_at,omitempty"`
UpdatedAt time.Time `gorm:"<-:create;<-:update;autoUpdateTime" json:"updated_at,omitempty"`
}
func (p *AuthentikCredentialsDBModel) TableName() string {
return "o_authentik_credentials"
}

View File

@ -30,7 +30,7 @@ func NewService(db *gorm.DB, RuntimePath string) Repository {
user: NewUserService(db), user: NewUserService(db),
event: NewEventService(db), event: NewEventService(db),
omv: NewOMVService(), omv: NewOMVService(),
authentik: NewAuthentikService(), authentik: NewAuthentikService(db),
} }
} }