{"record":{"id":"d0cd8da4f11a527d","repo":"ory/kratos","slug":"api-key-auth-strategy-requires-a-string-name","errorCode":null,"errorMessage":"api_key auth strategy requires a string name","messagePattern":"api_key auth strategy requires a string name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"request/auth.go","lineNumber":36,"sourceCode":"\t}\n\tapiKeyStrategy struct {\n\t\tname  string\n\t\tvalue string\n\t\tin    string\n\t}\n\tAuthStrategy interface {\n\t\tapply(req *retryablehttp.Request)\n\t}\n)\n\nfunc authStrategy(typ string, config map[string]any) (AuthStrategy, error) {\n\tswitch typ {\n\tcase \"\":\n\t\treturn NewNoopAuthStrategy(), nil\n\tcase \"api_key\":\n\t\tname, ok := config[\"name\"].(string)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"api_key auth strategy requires a string name\")\n\t\t}\n\t\tvalue, ok := config[\"value\"].(string)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"api_key auth strategy requires a string value\")\n\t\t}\n\t\tin, _ := config[\"in\"].(string) // in is optional\n\t\treturn NewAPIKeyStrategy(in, name, value), nil\n\tcase \"basic_auth\":\n\t\tuser, ok := config[\"user\"].(string)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"basic_auth auth strategy requires a string user\")\n\t\t}\n\t\tpassword, ok := config[\"password\"].(string)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"basic_auth auth strategy requires a string password\")\n\t\t}\n\t\treturn NewBasicAuthStrategy(user, password), nil\n\t}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/ory/kratos/blob/b86338da04a040247a07f46100a86dcfb3875909/request/auth.go#L18-L54","documentation":"authStrategy constructs the HTTP auth strategy for a webhook caller from a generic map. For type \"api_key\" it requires a string \"name\" field (the header/query parameter name); if config[\"name\"] is absent or not a string, builder creation fails with this error.","triggerScenarios":"Webhook auth config {\"type\": \"api_key\"} with no \"name\" key, or \"name\" set to a non-string (number, bool, object, null), passed into NewBuilder's request config.","commonSituations":"YAML config where the header name is unquoted and parsed as a number (e.g. name: 123); forgetting the name key; copying a basic_auth config but switching type to api_key without adding name/value.","solutions":["Add a string \"name\" field to the api_key auth config","Quote the name value in YAML so it stays a string","Set \"name\" to the header (or query param) name, e.g. \"X-Api-Key\"","Also verify \"value\" is a string, since the next check will fail otherwise"],"exampleFix":"// before\nauth: {type: api_key, value: secret123}\n// after\nauth: {type: api_key, name: X-Api-Key, value: secret123}","handlingStrategy":"validation","validationCode":"// Go: check api_key auth config before building\nfunc validateAPIKeyAuth(cfg map[string]interface{}) error {\n\tif _, ok := cfg[\"name\"].(string); !ok {\n\t\treturn errors.New(\"api_key auth requires a string name\")\n\t}\n\tif _, ok := cfg[\"value\"].(string); !ok {\n\t\treturn errors.New(\"api_key auth requires a string value\")\n\t}\n\treturn nil\n}","typeGuard":"func hasAPIKeyName(cfg map[string]interface{}) bool {\n\t_, ok := cfg[\"name\"].(string)\n\treturn ok\n}","tryCatchPattern":"b, err := request.NewBuilder(cfg)\nif err != nil {\n\tif strings.Contains(err.Error(), \"requires a string name\") {\n\t\treturn fmt.Errorf(\"webhook api_key auth: add a string 'name' (header/param name) to config\")\n\t}\n\treturn err\n}","preventionTips":["Quote all auth fields in YAML so numbers/bools stay strings","Validate the full config against the Ory Kratos JSON schema before start","Name api_key fields exactly: type, in, name, value","Start from an official example config rather than writing from scratch"],"tags":["configuration","webhook","auth","type-mismatch"],"backgroundTag":"missing-required-config-field","analyzedSha":"b86338da04a040247a07f46100a86dcfb3875909","analyzedAt":"2026-09-07T15:58:15.934Z","contentChangedAt":"2026-09-07T15:58:15.934Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}