{"record":{"id":"011846265171f7a0","repo":"larksuite/cli","slug":"failed-to-get-user-info-missing-open-id-in-respon","errorCode":null,"errorMessage":"failed to get user info: missing open_id in response","messagePattern":"failed to get user info: missing open_id in response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/auth/auth.go","lineNumber":101,"sourceCode":"func getUserInfo(ctx context.Context, sdk *lark.Client, accessToken string) (openId, name string, err error) {\n\tapiResp, err := sdk.Do(ctx, &larkcore.ApiReq{\n\t\tHttpMethod:                http.MethodGet,\n\t\tApiPath:                   larkauth.PathUserInfoV1,\n\t\tSupportedAccessTokenTypes: []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser},\n\t}, larkcore.WithUserAccessToken(accessToken))\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\tvar resp userInfoResponse\n\tif err := json.Unmarshal(apiResp.RawBody, &resp); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to parse user info: %w\", err)\n\t}\n\tif resp.Code != 0 {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to get user info [%d]: %s\", resp.Code, resp.Msg)\n\t}\n\tif resp.Data.OpenID == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to get user info: missing open_id in response\")\n\t}\n\n\tname = resp.Data.Name\n\tif name == \"\" {\n\t\tname = \"(unknown)\"\n\t}\n\treturn resp.Data.OpenID, name, nil\n}\n\n// appInfo contains application information (owner, scopes).\ntype appInfo struct {\n\tOwnerOpenId string\n\tUserScopes  []string\n}\n\n// appInfoResponse is the API response for /open-apis/application/v6/applications/:app_id.\ntype appInfoResponse struct {\n\tCode int    `json:\"code\"`","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/cmd/auth/auth.go#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"openID, name, err := getUserInfo(ctx, client, token)\nif err == nil && openID == \"\" {\n    return fmt.Errorf(\"login produced no user identity; ensure a user_access_token was used\")\n}","typeGuard":null,"tryCatchPattern":"openID, name, err := getUserInfo(ctx, client, token)\nif err != nil && strings.Contains(err.Error(), \"missing open_id\") {\n    return fmt.Errorf(\"user identity missing from successful response; re-login or check token type: %w\", err)\n}\nif err != nil { return err }","preventionTips":["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"],"tags":["auth","user-info","missing-field","api-response"],"backgroundTag":"missing-response-field","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}