oauth_key.go 798 B

123456789101112131415161718192021222324252627282930
  1. package codex
  2. import (
  3. "errors"
  4. "github.com/QuantumNous/new-api/common"
  5. )
  6. type OAuthKey struct {
  7. IDToken string `json:"id_token,omitempty"`
  8. AccessToken string `json:"access_token,omitempty"`
  9. RefreshToken string `json:"refresh_token,omitempty"`
  10. AccountID string `json:"account_id,omitempty"`
  11. LastRefresh string `json:"last_refresh,omitempty"`
  12. Email string `json:"email,omitempty"`
  13. Type string `json:"type,omitempty"`
  14. Expired string `json:"expired,omitempty"`
  15. }
  16. func ParseOAuthKey(raw string) (*OAuthKey, error) {
  17. if raw == "" {
  18. return nil, errors.New("codex channel: empty oauth key")
  19. }
  20. var key OAuthKey
  21. if err := common.Unmarshal([]byte(raw), &key); err != nil {
  22. return nil, errors.New("codex channel: invalid oauth key json")
  23. }
  24. return &key, nil
  25. }