39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// AuthUseCase 認證用例介面
|
|
type AuthUseCase interface {
|
|
CreateToken(ctx context.Context, req CreateTokenRequest) (*TokenResponse, error)
|
|
RefreshToken(ctx context.Context, refreshToken string) (*TokenResponse, error)
|
|
ValidateToken(ctx context.Context, accessToken string) (*TokenClaims, error)
|
|
Logout(ctx context.Context, accessToken string) error
|
|
LogoutAllByUserID(ctx context.Context, uid string) error
|
|
}
|
|
|
|
// CreateTokenRequest 創建令牌請求
|
|
type CreateTokenRequest struct {
|
|
ClientID string `json:"client_id"`
|
|
GrantType string `json:"grant_type"`
|
|
Username string `json:"username,omitempty"`
|
|
Password string `json:"password,omitempty"`
|
|
DeviceID string `json:"device_id,omitempty"`
|
|
}
|
|
|
|
// TokenResponse 令牌響應
|
|
type TokenResponse struct {
|
|
AccessToken string `json:"access_token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
TokenType string `json:"token_type"`
|
|
ExpiresIn int64 `json:"expires_in"`
|
|
}
|
|
|
|
// TokenClaims 令牌聲明
|
|
type TokenClaims struct {
|
|
UID string `json:"uid"`
|
|
ClientID string `json:"client_id"`
|
|
DeviceID string `json:"device_id"`
|
|
}
|