Skip to content

Fix/organization connections empty properties#55

Open
BrandtKruger wants to merge 9 commits intokinde-oss:mainfrom
BrandtKruger:fix/organization-connections-empty-properties
Open

Fix/organization connections empty properties#55
BrandtKruger wants to merge 9 commits intokinde-oss:mainfrom
BrandtKruger:fix/organization-connections-empty-properties

Conversation

@BrandtKruger
Copy link
Contributor

Explain your changes

Fix bug for organization connections empty properties

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

- Implemented GetAuthURLWithInvitation method to include invitation_code and is_invitation parameters in the authentication URL.
- Updated UseKindeAuth function to utilize the new method for redirecting users with invitation codes.
- Added comprehensive tests for invitation code handling in authorization code flow.

This enhancement allows for better user onboarding through invitation codes.
- Changed Connections field and related methods in GetConnectionsResponse to use ConnectionConnection instead of Connection.
- Updated the Decode method to reflect the new type for better consistency and clarity in the API response structure.
@BrandtKruger BrandtKruger requested a review from a team as a code owner January 26, 2026 18:21
@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds OAuth2 invitation-code support, extensive Management API surface changes (new optional types, billing and APIScopes fields, renamed/deleted generated types, validation updates), many generated client/server renames for DeleteAPIApplicationScope, updated handlers/metrics, and new tests plus example programs exercising GetOrganizationConnections. (38 words)

Changes

Cohort / File(s) Summary
OAuth2 — Invitation code
oauth2/authorization_code/authorization_code.go, oauth2/authorization_code/options.go, oauth2/authorization_code/authorization_code_test.go
Added GetAuthURLWithInvitation(invitationCode string) and WithInvitationCode(invitationCode string); GetAuthURL() delegates to the new method. Invitation query params (invitation_code, is_invitation) handled and covered by tests (presence, absence, overwrite).
Gin integration
frameworks/gin_kinde/gin_kinde.go
When unauthenticated, reads invitation_code from request query and uses GetAuthURLWithInvitation(invitationCode) for redirect construction instead of GetAuthURL().
Generated Management API — JSON/optional types
kinde/management_api/oas_json_gen.go, kinde/management_api/oas_schemas_gen.go
Wide generator changes introducing Opt* optional/nullable wrapper types, nullable handling in Encode/Decode/Marshal/Unmarshal, added types (e.g., ConnectionConnection, CreateApiKeyReqType, billing/APIScopes fields), removed some SamlAcsURL fields, and many new getters/setters. GetConnectionsResponse.Connections changed to []ConnectionConnection.
Generated Management API — Client/handler/ops renames & routing
kinde/management_api/oas_client_gen.go, kinde/management_api/oas_handlers_gen.go, kinde/management_api/oas_interfaces_gen.go, kinde/management_api/oas_operations_gen.go, kinde/management_api/oas_router_gen.go, kinde/management_api/oas_server_gen.go, kinde/management_api/oas_unimplemented_gen.go
Renamed misspelled operation/type symbols from DeleteAPIAppliationScope*DeleteAPIApplicationScope* across interface, client, handlers, router, operations constants, server handler signatures and unimplemented stubs. No logic change beyond renames.
Generated Management API — Params / query enhancements
kinde/management_api/oas_parameters_gen.go, kinde/management_api/oas_client_gen.go
Added query parameter encoding/decoding for active_since (GetUsers) and api_scopes (GetSearchUsers). Updated parameter types and unpack/decoding functions to accept these new filters.
Generated Management API — Response decoders/encoders & validation
kinde/management_api/oas_response_decoders_gen.go, kinde/management_api/oas_response_encoders_gen.go, kinde/management_api/oas_validators_gen.go
Renamed encoder/decoder functions to match DeleteAPIApplicationScope* types; removed 204 No Content handling for AddOrganizationUsers; added response validation call for GetUsers responses; added validators (e.g., CreateApiKeyReqType.Validate()), expanded enum validation cases, and new UsersResponse/UsersItem validation logic.
Generated Management API — Security mapping & metrics change
kinde/management_api/oas_security_gen.go, kinde/management_api/oas_handlers_gen.go
Fixed security map key to use renamed DeleteAPIApplicationScopeOperation; in many handlers adjusted metric recording creation to pass attributes via metric.WithAttributes(attrs) (changed how attributes are constructed when recording metrics) — otherwise handler logic unchanged aside from operation/otel name corrections.
Tests & Examples
kinde/management_api/get_connections_response_test.go, kinde/management_api/get_organization_connections_integration_test.go, examples/test_organization_connections/main.go, test_get_organization_connections.go
Added unit tests for GetConnectionsResponse/ConnectionConnection, integration tests (mock server) for GetOrganizationConnections including error cases (400,403,429), and two example/test programs that exercise GetOrganizationConnections via client-credentials flow with detailed env var validation and user-facing error guidance.
Repo tooling / generate directive
kinde/management_api/generate.go
Updated go:generate to use local OpenAPI spec file spec/kinde-management-api-spec.yaml instead of remote URL.

Sequence Diagram(s)

(Skipped)

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (28 files):

⚔️ .gitignore (content)
⚔️ frameworks/gin_kinde/gin_kinde.go (content)
⚔️ go.mod (content)
⚔️ go.sum (content)
⚔️ jwt/jwt.go (content)
⚔️ jwt/jwt_options.go (content)
⚔️ jwt/jwt_test.go (content)
⚔️ jwt/token.go (content)
⚔️ kinde/management_api/generate.go (content)
⚔️ kinde/management_api/oas_client_gen.go (content)
⚔️ kinde/management_api/oas_handlers_gen.go (content)
⚔️ kinde/management_api/oas_interfaces_gen.go (content)
⚔️ kinde/management_api/oas_json_gen.go (content)
⚔️ kinde/management_api/oas_operations_gen.go (content)
⚔️ kinde/management_api/oas_parameters_gen.go (content)
⚔️ kinde/management_api/oas_response_decoders_gen.go (content)
⚔️ kinde/management_api/oas_response_encoders_gen.go (content)
⚔️ kinde/management_api/oas_router_gen.go (content)
⚔️ kinde/management_api/oas_schemas_gen.go (content)
⚔️ kinde/management_api/oas_security_gen.go (content)
⚔️ kinde/management_api/oas_server_gen.go (content)
⚔️ kinde/management_api/oas_unimplemented_gen.go (content)
⚔️ kinde/management_api/oas_validators_gen.go (content)
⚔️ oauth2/authorization_code/authorization_code.go (content)
⚔️ oauth2/authorization_code/authorization_code_test.go (content)
⚔️ oauth2/authorization_code/example_middleware.go (content)
⚔️ oauth2/authorization_code/options.go (content)
⚔️ oauth2/client_credentials/options.go (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix/organization connections empty properties' clearly describes the main bug fix being addressed in the pull request.
Description check ✅ Passed The description explains the bug fix (organization connections have empty properties) and references the technical approach, which relates to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@kinde/management_api/get_organization_connections_integration_test.go`:
- Around line 226-227: The for-loop starting with "for _, tt := range tests {"
is indented one extra tab; remove the extra tab so the line aligns with
surrounding code (same indentation level as the preceding test setup) to fix
formatting inconsistency around the loop that encloses t.Run(tt.name, func(t
*testing.T) { ... }) in the test function.
🧹 Nitpick comments (3)
examples/test_organization_connections/main.go (1)

122-190: Consider extracting duplicate error response handling into a helper function.

The error handling blocks for 400, 403, and 429 responses follow an identical pattern: cast to ErrorResponse, iterate errors, print guidance. This code is duplicated across this file and test_get_organization_connections.go.

♻️ Suggested refactor
func printErrorDetails(errResp *management_api.ErrorResponse) {
    errors := errResp.GetErrors()
    if len(errors) > 0 {
        for i, err := range errors {
            if code, ok := err.Code.Get(); ok {
                fmt.Printf("Error %d Code: %s\n", i+1, code)
            }
            if message, ok := err.Message.Get(); ok {
                fmt.Printf("Error %d Message: %s\n", i+1, message)
            }
        }
    }
}
test_get_organization_connections.go (1)

1-268: Significant duplication with examples/test_organization_connections/main.go.

This file is nearly identical to the example file. Both serve the same purpose of testing the GetOrganizationConnections fix. Consider:

  1. Keeping only one: The examples/ version has better documentation and follows the project's example structure.
  2. If both are needed: Extract shared logic into a reusable package to avoid maintenance burden.

The only notable differences are minor wording variations in error messages and comments.

kinde/management_api/get_connections_response_test.go (1)

214-235: Assert “unset” for omitted fields to guard the empty-properties bug.

In TestConnectionConnection_Decode, when want* is empty the test skips validation, which could allow Decode to incorrectly mark fields as set (the bug this PR addresses). Consider asserting IsSet() == false for omitted fields.

🧪 Proposed test tightening
-			if tt.wantID != "" {
-				if id, ok := conn.ID.Get(); !ok || id != tt.wantID {
-					t.Errorf("ID = %v (ok=%v), want %v", id, ok, tt.wantID)
-				}
-			}
+			if tt.wantID != "" {
+				if id, ok := conn.ID.Get(); !ok || id != tt.wantID {
+					t.Errorf("ID = %v (ok=%v), want %v", id, ok, tt.wantID)
+				}
+			} else if conn.ID.IsSet() {
+				t.Errorf("ID should be unset when not provided")
+			}
 
-			if tt.wantName != "" {
-				if name, ok := conn.Name.Get(); !ok || name != tt.wantName {
-					t.Errorf("Name = %v (ok=%v), want %v", name, ok, tt.wantName)
-				}
-			}
+			if tt.wantName != "" {
+				if name, ok := conn.Name.Get(); !ok || name != tt.wantName {
+					t.Errorf("Name = %v (ok=%v), want %v", name, ok, tt.wantName)
+				}
+			} else if conn.Name.IsSet() {
+				t.Errorf("Name should be unset when not provided")
+			}
 
-			if tt.wantDisp != "" {
-				if disp, ok := conn.DisplayName.Get(); !ok || disp != tt.wantDisp {
-					t.Errorf("DisplayName = %v (ok=%v), want %v", disp, ok, tt.wantDisp)
-				}
-			}
+			if tt.wantDisp != "" {
+				if disp, ok := conn.DisplayName.Get(); !ok || disp != tt.wantDisp {
+					t.Errorf("DisplayName = %v (ok=%v), want %v", disp, ok, tt.wantDisp)
+				}
+			} else if conn.DisplayName.IsSet() {
+				t.Errorf("DisplayName should be unset when not provided")
+			}
 
-			if tt.wantStrat != "" {
-				if strat, ok := conn.Strategy.Get(); !ok || strat != tt.wantStrat {
-					t.Errorf("Strategy = %v (ok=%v), want %v", strat, ok, tt.wantStrat)
-				}
-			}
+			if tt.wantStrat != "" {
+				if strat, ok := conn.Strategy.Get(); !ok || strat != tt.wantStrat {
+					t.Errorf("Strategy = %v (ok=%v), want %v", strat, ok, tt.wantStrat)
+				}
+			} else if conn.Strategy.IsSet() {
+				t.Errorf("Strategy should be unset when not provided")
+			}

- Modified the indentation of the test loop in get_organization_connections_integration_test.go for improved readability and consistency with Go formatting standards.
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 26, 2026
- Updated WithInvitationCode function to set the prompt parameter to "create" when an invitation code is provided.
- Added assertions in tests to verify that the prompt is correctly set in authURLOptions and included in the generated authentication URL.
- Improved test coverage for scenarios involving invitation codes, ensuring proper handling of the prompt parameter.
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 28, 2026
- Updated GetAuthURLWithInvitation to set the prompt parameter to "create" only if no custom prompt is provided.
- Added tests to verify that the prompt parameter behaves correctly with and without invitation codes, ensuring custom prompts are preserved.
- Improved test coverage for scenarios involving invitation codes and prompt handling.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oauth2/authorization_code/authorization_code.go (1)

41-48: Update in-repo mock to implement the complete interface.

Adding GetAuthURLWithInvitation to IAuthorizationCodeFlow is a breaking change for external implementations. The MockAuthorizationCodeFlow in oauth2/authorization_code/middleware_test.go is incomplete—it only implements Middleware() but lacks the required interface methods including GetAuthURL(), GetAuthURLWithInvitation(), and others. Either implement all interface methods on the mock or remove it if it's not intended to satisfy the interface contract. Additionally, ensure external consumers are aware of this change.

🧹 Nitpick comments (1)
oauth2/authorization_code/authorization_code_test.go (1)

98-103: Assert constructor errors to avoid silent test failures.

Right now the error return is discarded. Please assert err == nil (and optionally kindeAuthFlow != nil) to fail fast if setup changes. This pattern applies to the other new tests too.

♻️ Proposed update
-	kindeAuthFlow, _ := NewAuthorizationCodeFlow(
+	kindeAuthFlow, err := NewAuthorizationCodeFlow(
 		testKindeServerURL, "b9da18c441b44d81bab3e8232de2e18d", "client_secret", callbackURL,
 		WithSessionHooks(newTestSessionHooks()),
 		WithCustomStateGenerator(func(*AuthorizationCodeFlow) string { return "test_state" }),
 	)
+	assert.NoError(err, "failed to create auth flow")
+	assert.NotNil(kindeAuthFlow, "auth flow should not be nil")

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 28, 2026
…a spec

Add local OpenAPI spec and fix get_connections_response so connections
array decodes correctly. API returns connection objects directly; spec
had items as connection (wrapper). Use connection_connection schema for
get_connections_response.connections items and connection.connection.

- Add spec/kinde-management-api-spec.yaml (from api-spec.kinde.com)
- Add connection_connection schema; get_connections_response.connections
  items and connection.connection reference it
- Update generate.go to use local spec
- Regenerate management_api (ogen) so GetConnectionsResponse.Connections
  is []ConnectionConnection; no manual oas_* patches

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
kinde/management_api/oas_parameters_gen.go (1)

1487-1659: ⚠️ Potential issue | 🟠 Major

Public type rename is breaking for downstream users.
DeleteAPIAppliationScopeParamsDeleteAPIApplicationScopeParams will break existing imports; consider a compatibility alias in a hand-written file (and release notes/semver) to smooth upgrades.

✅ Compatibility alias (non-generated file)
+// file: kinde/management_api/compat_types.go
+package management_api
+
+// Deprecated: use DeleteAPIApplicationScopeParams.
+type DeleteAPIAppliationScopeParams = DeleteAPIApplicationScopeParams
🧹 Nitpick comments (1)
kinde/management_api/oas_json_gen.go (1)

23673-23691: Minor: value assigned before error check in generated decoder.

Lines 23678–23680 assign elem = string(v) before checking err. While this is safe here (the error triggers an early return before elem is appended), it's an ordering inversion that could mask issues if the pattern were ever hand-edited. Since this is ogen-generated code, no action needed—just noting for awareness.

v, err := d.Str()
elem = string(v)  // assigned before err check
if err != nil {
    return err
}

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant