{"id":"8005dd364e4b9917","repo":"jackc/pgx","slug":"failed-to-obtain-oauth-token-w","errorCode":null,"errorMessage":"failed to obtain OAuth token: %w","messagePattern":"failed to obtain OAuth token: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/auth_oauth.go","lineNumber":19,"sourceCode":"package pgconn\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\n\t\"github.com/jackc/pgx/v5/pgproto3\"\n)\n\nfunc (c *PgConn) oauthAuth(ctx context.Context) error {\n\tif c.config.OAuthTokenProvider == nil {\n\t\treturn errors.New(\"OAuth authentication required but no token provider configured\")\n\t}\n\n\ttoken, err := c.config.OAuthTokenProvider(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to obtain OAuth token: %w\", err)\n\t}\n\n\t// https://www.rfc-editor.org/rfc/rfc7628.html#section-3.1\n\tinitialResponse := []byte(\"n,,\\x01auth=Bearer \" + token + \"\\x01\\x01\")\n\n\tsaslInitialResponse := &pgproto3.SASLInitialResponse{\n\t\tAuthMechanism: \"OAUTHBEARER\",\n\t\tData:          initialResponse,\n\t}\n\tc.frontend.Send(saslInitialResponse)\n\terr = c.flushWithPotentialWriteReadDeadlock()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tmsg, err := c.receiveMessage()\n\tif err != nil {\n\t\treturn err","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/auth_oauth.go#L1-L37","documentation":"Error \"failed to obtain OAuth token: %w\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgconn/auth_oauth.go:19 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}