larksuite/cli · error
failed to get user info: missing open_id in response
Error message
failed to get user info: missing open_id in response
What it means
getUserInfo returns 'failed to get user info: missing open_id in response' when the user_info API returns code 0 (success) but resp.Data.OpenID is empty — the envelope says success yet no open_id was delivered. This guards against silently persisting an empty user identity during login. It is a plain fmt.Errorf, not a typed errs.* error per the repository error contract.
Source
Thrown at cmd/auth/auth.go:101
func getUserInfo(ctx context.Context, sdk *lark.Client, accessToken string) (openId, name string, err error) {
apiResp, err := sdk.Do(ctx, &larkcore.ApiReq{
HttpMethod: http.MethodGet,
ApiPath: larkauth.PathUserInfoV1,
SupportedAccessTokenTypes: []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser},
}, larkcore.WithUserAccessToken(accessToken))
if err != nil {
return "", "", err
}
var resp userInfoResponse
if err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {
return "", "", fmt.Errorf("failed to parse user info: %w", err)
}
if resp.Code != 0 {
return "", "", fmt.Errorf("failed to get user info [%d]: %s", resp.Code, resp.Msg)
}
if resp.Data.OpenID == "" {
return "", "", fmt.Errorf("failed to get user info: missing open_id in response")
}
name = resp.Data.Name
if name == "" {
name = "(unknown)"
}
return resp.Data.OpenID, name, nil
}
// appInfo contains application information (owner, scopes).
type appInfo struct {
OwnerOpenId string
UserScopes []string
}
// appInfoResponse is the API response for /open-apis/application/v6/applications/:app_id.
type appInfoResponse struct {
Code int `json:"code"`View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Verify the call uses a valid user_access_token (not a tenant/app token) via larkcore.WithUserAccessToken; re-login with `lark-cli auth login` to refresh it.
- Dump the raw user_info response (SDK logging or proxy) to confirm whether data.open_id is truly absent.
- Confirm the app is configured for user identity (authen) and the logged-in user actually authorized the app.
- If the API consistently omits open_id on success, update the CLI/SDK or report a possible API schema change.
Defensive patterns
Strategy: validation
Validate before calling
openID, name, err := getUserInfo(ctx, client, token)
if err == nil && openID == "" {
return fmt.Errorf("login produced no user identity; ensure a user_access_token was used")
} Try / catch
openID, name, err := getUserInfo(ctx, client, token)
if err != nil && strings.Contains(err.Error(), "missing open_id") {
return fmt.Errorf("user identity missing from successful response; re-login or check token type: %w", err)
}
if err != nil { return err } Prevention
- Always pass the token as a user_access_token (larkcore.WithUserAccessToken), never a tenant token
- Re-login to obtain a fresh token if identity resolution fails
- Confirm the user completed app authorization during login
- Capture the raw user_info payload to distinguish empty-identity responses from schema changes
When it happens
Trigger: GET /open-apis/authen/v1/user_info returns {code:0} but data.open_id is absent or empty string — typically when the access token does not identify a user (e.g. wrong token type passed via WithUserAccessToken), or the API responds with an unexpected partial payload.
Common situations: Token-type mixups in the SDK request options; authen API behavior changes or beta endpoints returning success with minimal data; unusual app configurations where the user identity is not resolvable; proxies returning sanitized/empty JSON bodies.
Related errors
- failed to get user info [%d]: %s
- failed to verify user identity: %w
- user_info API returned HTTP %d
- stored token data is corrupt
- note detail is empty
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/011846265171f7a0.
Report an issue: GitHub.