Skip to content

Fix/create identity identity id decode - #58

Closed
BrandtKruger wants to merge 4 commits into
kinde-oss:mainfrom
BrandtKruger:fix/create-identity-identity-id-decode
Closed

Fix/create identity identity id decode#58
BrandtKruger wants to merge 4 commits into
kinde-oss:mainfrom
BrandtKruger:fix/create-identity-identity-id-decode

Conversation

@BrandtKruger

Copy link
Copy Markdown
Contributor

Explain your changes

create identity identity id decode

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.
When creating an identity with an existing enterprise identity, the Kinde
API returns identity_id instead of id in the response. Add a post-generation
patch script so CreateIdentityResponseIdentity.Decode() accepts identity_id
and maps it to ID for compatibility.

- Add fix_create_identity_identity.go to run after ogen (generate.go)
- Patch targets only CreateIdentityResponseIdentity.Decode via unique block
- Add unit tests for id and identity_id decode paths
@BrandtKruger
BrandtKruger requested a review from a team as a code owner January 30, 2026 15:44
@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown

Walkthrough

Adds invitation-code-aware auth URL generation and wiring: new AuthorizationCodeFlow API and option, Gin handler uses the invitation_code query parameter for redirects, tests for auth URL behavior, and a small code-generation patch tool plus tests to map identity_id into generated decoding logic.

Changes

Cohort / File(s) Summary
Authorization Code Flow
oauth2/authorization_code/authorization_code.go, oauth2/authorization_code/options.go, oauth2/authorization_code/authorization_code_test.go
Adds GetAuthURLWithInvitation(invitationCode string) and WithInvitationCode() option; GetAuthURL() delegates to the new method. Tests added to verify URL contains invitation_code and is_invitation when provided and omitted when empty.
Framework Integration (Gin)
frameworks/gin_kinde/gin_kinde.go
Unauthenticated handler now reads invitation_code query parameter and calls GetAuthURLWithInvitation(invitationCode) (instead of GetAuthURL()) before redirecting.
Management API — Generated Decoder Patch + Tests
kinde/management_api/fix_create_identity_identity.go, kinde/management_api/generate.go, kinde/management_api/create_identity_response_test.go
Adds a build-tagged patch tool that edits oas_json_gen.go to handle identity_id in CreateIdentityResponseIdentity.Decode, a //go:generate directive to run the tool, and three tests covering decoding behavior for id and identity_id variants.

Sequence Diagram(s)

sequenceDiagram
  participant User as "User (browser)"
  participant Gin as "Gin Handler\n(`gin_kinde`)"
  participant Flow as "AuthorizationCodeFlow\n(GetAuthURLWithInvitation)"
  participant OAuth as "Authorization Server"

  User->>Gin: Request protected resource (may include ?invitation_code=ABC)
  Gin->>Gin: detect unauthenticated, read `invitation_code`
  Gin->>Flow: GetAuthURLWithInvitation("ABC")
  Flow->>Flow: build auth URL (include PKCE + invitation_code + is_invitation)
  Flow-->>Gin: auth URL
  Gin-->>User: 302 Redirect -> auth URL
  User->>OAuth: Follow redirect (auth request includes invitation params)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the main change but is generic and vague—it doesn't clearly convey what was actually changed beyond referencing field names. Revise the title to be more specific about the change, such as 'Add invitation code support to authorization flow' or similar, to better represent the primary objective of the changeset.
Description check ❓ Inconclusive The description is minimal and uses only generic terms like 'create identity identity id decode' without providing meaningful detail about the changeset. Expand the description to explain what was changed and why—e.g., adding invitation code support, fixing identity_id field decoding, or integrating new flow patterns.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@kinde/management_api/create_identity_response_test.go`:
- Around line 53-63: The decoder generation for CreateIdentityResponse is
missing handling for the "identity_id" JSON field, causing response.Decode in
create_identity_response_test.go to not set identity.ID; update and commit the
patched oas_json_gen.go output (or add a CI go generate step) so the generated
decoder in the function/method that decodes CreateIdentityResponse handles both
"id" and "identity_id" into response.Identity.ID (ensure the decoding logic in
the generated decoder for Identity.ID recognizes the "identity_id" key and sets
Identity.ID.IsSet()/Get() accordingly), then run tests to verify
response.Decode, response.Identity.IsSet(), and identity.ID are correctly
populated.

In `@kinde/management_api/fix_create_identity_identity.go`:
- Around line 89-94: The current check for bytes.Count(content, oldBlock) treats
a missing pattern as a non-error (os.Exit(0)), hiding generator drift and
leaving CreateIdentityResponseIdentity.Decode unpatched; change the behavior in
the count == 0 branch to fail hard (e.g., replace os.Exit(0) with a non-zero
exit or use log.Fatalf/log.Panicf) so the process returns an error and surfaces
the issue immediately when oldBlock is not found in content; ensure the message
includes context about CreateIdentityResponseIdentity.Decode and the pattern
lookup so CI/tests will fail loudly.

Comment thread kinde/management_api/create_identity_response_test.go
Comment thread kinde/management_api/fix_create_identity_identity.go
@KeeganBeuthin

Copy link
Copy Markdown

Good Morning @BrandtKruger, Just finished taking a look at this. A couple things I'd like to note

The current PR patches only in CI, so the shipped SDK would probably still remain broken then or am I missing somehting? Would it not be better to have the openAPI spec updated and regenerate it?

If that is not possible perhaps we should just patch locally, what do you think?

I also wanted to check why the invitation code change is included in this set of changes relating to the identity id decode.

@BrandtKruger

Copy link
Copy Markdown
Contributor Author

Good Morning @BrandtKruger, Just finished taking a look at this. A couple things I'd like to note

The current PR patches only in CI, so the shipped SDK would probably still remain broken then or am I missing somehting? Would it not be better to have the openAPI spec updated and regenerate it?

If that is not possible perhaps we should just patch locally, what do you think?

I also wanted to check why the invitation code change is included in this set of changes relating to the identity id decode.

Hi, let me have a look. Thank you.

@BrandtKruger
BrandtKruger deleted the fix/create-identity-identity-id-decode branch February 7, 2026 12:08
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.

2 participants