types.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package oauth
  2. // OAuthToken represents the token received from OAuth provider
  3. type OAuthToken struct {
  4. AccessToken string `json:"access_token"`
  5. TokenType string `json:"token_type"`
  6. RefreshToken string `json:"refresh_token,omitempty"`
  7. ExpiresIn int `json:"expires_in,omitempty"`
  8. Scope string `json:"scope,omitempty"`
  9. IDToken string `json:"id_token,omitempty"`
  10. }
  11. // OAuthUser represents the user info from OAuth provider
  12. type OAuthUser struct {
  13. // ProviderUserID is the unique identifier from the OAuth provider
  14. ProviderUserID string
  15. // Username is the username from the OAuth provider (e.g., GitHub login)
  16. Username string
  17. // DisplayName is the display name from the OAuth provider
  18. DisplayName string
  19. // Email is the email from the OAuth provider
  20. Email string
  21. // Extra contains any additional provider-specific data
  22. Extra map[string]any
  23. }
  24. // OAuthError represents a translatable OAuth error
  25. type OAuthError struct {
  26. // MsgKey is the i18n message key
  27. MsgKey string
  28. // Params contains optional parameters for the message template
  29. Params map[string]any
  30. // RawError is the underlying error for logging purposes
  31. RawError string
  32. }
  33. func (e *OAuthError) Error() string {
  34. if e.RawError != "" {
  35. return e.RawError
  36. }
  37. return e.MsgKey
  38. }
  39. // NewOAuthError creates a new OAuth error with the given message key
  40. func NewOAuthError(msgKey string, params map[string]any) *OAuthError {
  41. return &OAuthError{
  42. MsgKey: msgKey,
  43. Params: params,
  44. }
  45. }
  46. // NewOAuthErrorWithRaw creates a new OAuth error with raw error message for logging
  47. func NewOAuthErrorWithRaw(msgKey string, params map[string]any, rawError string) *OAuthError {
  48. return &OAuthError{
  49. MsgKey: msgKey,
  50. Params: params,
  51. RawError: rawError,
  52. }
  53. }