This commit is contained in:
2024-08-13 12:19:14 +07:00
parent 634c492519
commit c385748979
7 changed files with 99 additions and 16 deletions
+34
View File
@@ -1,12 +1,46 @@
package service
import (
"bytes"
"fmt"
"io"
"log"
"net/http"
model2 "github.com/IceWhaleTech/CasaOS-UserService/service/model"
)
type AuthentikService interface {
HelloWorld() string
GetUserInfo(accessToken string) model2.AuthentikUser
}
type authentikService struct {
}
func (a *authentikService) GetUserInfo(accessToken string) model2.AuthentikUser {
bearer := "Bearer " + accessToken
req, err := http.NewRequest("GET", "", bytes.NewBuffer(nil))
req.Header.Set("Authorization", bearer)
req.Header.Add("Accept", "application/json")
client := &http.Client{}
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
for key, val := range via[0].Header {
req.Header[key] = val
}
return err
}
resp, err := client.Do(req)
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
} else {
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}
return model2.AuthentikUser{}
}
func (a *authentikService) HelloWorld() string {
return "Hello World!"
}
+25
View File
@@ -0,0 +1,25 @@
package model
type AuthentikUser struct {
User struct {
Avatar string `json:"avatar"`
Email string `json:"email"`
Groups []struct {
Name string `json:"name"`
Pk string `json:"pk"`
} `json:"groups"`
IsActive bool `json:"is_active"`
IsSuperuser bool `json:"is_superuser"`
Name string `json:"name"`
Pk int64 `json:"pk"`
Settings struct {
Theme struct {
Base string `json:"base"`
} `json:"theme"`
} `json:"settings"`
SystemPermissions []string `json:"system_permissions"`
Type string `json:"type"`
UID string `json:"uid"`
Username string `json:"username"`
} `json:"user"`
}