Files
backend/internal/models/auth.go

90 lines
3.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
// Agent представляет информацию о лаунчере, который делает запрос
type Agent struct {
Name string `json:"name"` // "Minecraft"
Version int `json:"version"` // 1
}
// AuthenticateRequest - это тело запроса на /authserver/authenticate
type AuthenticateRequest struct {
Agent Agent `json:"agent"`
Username string `json:"username"`
Password string `json:"password"`
ClientToken string `json:"clientToken"`
}
// ProfileInfo содержит краткую информацию о профиле игрока
type ProfileInfo struct {
ID string `json:"id"` // UUID пользователя без дефисов
Name string `json:"name"` // Никнейм пользователя
}
// AuthenticateResponse - это тело успешного ответа
type AuthenticateResponse struct {
AccessToken string `json:"accessToken"`
ClientToken string `json:"clientToken"`
AvailableProfiles []ProfileInfo `json:"availableProfiles"`
SelectedProfile ProfileInfo `json:"selectedProfile"`
User *UserProperty `json:"user,omitempty"` // Необязательное поле с доп. свойствами
}
// UserProperty - часть ответа, может содержать доп. свойства пользователя
type UserProperty struct {
ID string `json:"id"` // UUID пользователя
Properties []any `json:"properties"` // Обычно пустой массив
}
// TextureInfo содержит URL для конкретной текстуры
type TextureInfo struct {
URL string `json:"url"`
}
// Textures содержит ссылки на скин и плащ
type Textures struct {
SKIN *TextureInfo `json:"SKIN,omitempty"`
CAPE *TextureInfo `json:"CAPE,omitempty"`
}
// ProfilePropertyValue - это закодированное в Base64 значение свойства textures
type ProfilePropertyValue struct {
Timestamp int64 `json:"timestamp"`
ProfileID string `json:"profileId"`
ProfileName string `json:"profileName"`
Textures Textures `json:"textures"`
}
// ProfileProperty - это свойство 'textures' в ответе
type ProfileProperty struct {
Name string `json:"name"` // Всегда "textures"
Value string `json:"value"` // Base64(ProfilePropertyValue)
Signature string `json:"signature"` // Base64(RSA-SHA1(Value))
}
// SessionProfileResponse - это ответ от /sessionserver/session/minecraft/profile/{uuid}
type SessionProfileResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Properties []ProfileProperty `json:"properties"`
}
// JoinRequest - это тело запроса на /sessionserver/session/minecraft/join
type JoinRequest struct {
AccessToken string `json:"accessToken"`
SelectedProfile string `json:"selectedProfile"` // UUID пользователя без дефисов
ServerID string `json:"serverId"`
}
// LoginRequest - это тело запроса на /api/login
type LoginRequest struct {
// Позволяем логиниться как по username, так и по email
Login string `json:"login"`
Password string `json:"password"`
}
// LoginResponse - это тело успешного ответа с JWT
type LoginResponse struct {
Token string `json:"token"`
User *User `json:"user"` // Отдаем информацию о пользователе
}