IceWhaleTech/CasaOS · error
e.Error
Error message
e.Error
What it means
During the Google Drive OAuth authorization-code exchange, the token endpoint responded with an error payload (TokenError.Error non-empty). The raw error string (typically 'invalid_grant' or 'redirect_uri_mismatch') is used as a fmt.Errorf format string and returned.
Source
Thrown at drivers/google_drive/util.go:43
func (d *GoogleDrive) getRefreshToken() error {
url := "https://www.googleapis.com/oauth2/v4/token"
var resp base.TokenResp
var e TokenError
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).
SetFormData(map[string]string{
"client_id": d.ClientID,
"client_secret": d.ClientSecret,
"code": d.Code,
"grant_type": "authorization_code",
"redirect_uri": "https://cloudoauth.files.casaos.app",
}).Post(url)
if err != nil {
return err
}
logger.Info("get refresh token", zap.String("res", res.String()))
if e.Error != "" {
return fmt.Errorf(e.Error)
}
d.RefreshToken = resp.RefreshToken
return nil
}
func (d *GoogleDrive) refreshToken() error {
url := "https://www.googleapis.com/oauth2/v4/token"
var resp base.TokenResp
var e TokenError
res, err := base.RestyClient.R().SetResult(&resp).SetError(&e).
SetFormData(map[string]string{
"client_id": d.ClientID,
"client_secret": d.ClientSecret,
"refresh_token": d.RefreshToken,
"grant_type": "refresh_token",
}).Post(url)
if err != nil {
return errView on GitHub (pinned to 0d3b2f444e)
Solutions
- Start the OAuth flow again and exchange the new code immediately.
- Confirm ClientID/ClientSecret and that the authorized redirect URI in Google Cloud Console is exactly https://cloudoauth.files.casaos.app.
- Check the logged response body for the error_description field for the precise reason.
Example fix
// before return fmt.Errorf(e.Error) // after return errors.New(e.Error)
Defensive patterns
Strategy: validation
Validate before calling
if d.ClientID == "" || d.ClientSecret == "" || d.Code == "" {
return errors.New("Google Drive OAuth requires ClientID, ClientSecret and a fresh Code")
} Try / catch
if err := d.GetRefreshTokenByCode(); err != nil {
if strings.Contains(err.Error(), "invalid_grant") || strings.Contains(err.Error(), "redirect_uri_mismatch") {
// regenerate code / fix console redirect URI; do not retry same code
}
return err
} Prevention
- Register https://cloudoauth.files.casaos.app as an authorized redirect URI in Google Cloud Console
- Automate the code handoff so it is exchanged within seconds of consent
- Keep ClientID/ClientSecret in versioned config, validated at startup
When it happens
Trigger: Exchanging d.Code when it is expired, already redeemed, or was issued for a different client_id/redirect_uri; wrong ClientID/ClientSecret in the driver config.
Common situations: Authorization code older than ~10 minutes or reused after a failed attempt; redirect_uri differs from the registered 'https://cloudoauth.files.casaos.app'; credentials from a different Google Cloud project.
Related errors
AI-assisted analysis of IceWhaleTech/CasaOS@0d3b2f444e (2026-08-15).
Data as JSON: /api/errors/ff88036dda97de0f.
Report an issue: GitHub.