feat(auth): Add login, register, session_info and api creation
This commit is contained in:
34
app/services/api_key.go
Normal file
34
app/services/api_key.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"git.secnex.io/secnex/auth-api/database"
|
||||
"git.secnex.io/secnex/auth-api/models"
|
||||
"git.secnex.io/secnex/auth-api/utils"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func CreateApiKey() *utils.HTTPResponse {
|
||||
keyID := uuid.New()
|
||||
key := utils.GenerateRandomString(32)
|
||||
createApiKey := &models.ApiKey{
|
||||
ID: keyID,
|
||||
Key: key,
|
||||
}
|
||||
|
||||
if err := database.DB.Create(createApiKey).Error; err != nil {
|
||||
return utils.NewHTTPResponse(fiber.StatusInternalServerError, &fiber.Map{
|
||||
"message": "Error creating API key",
|
||||
}, "", nil, nil)
|
||||
}
|
||||
|
||||
apiKeyPlain := fmt.Sprintf("%s:%s", keyID.String(), key)
|
||||
apiKey := base64.StdEncoding.EncodeToString([]byte(apiKeyPlain))
|
||||
return utils.NewHTTPResponse(fiber.StatusOK, &fiber.Map{
|
||||
"message": "API key created successfully",
|
||||
"key": apiKey,
|
||||
}, "", nil, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user