Add workflows to dynamically capture IdP claims and inject into tokens - #19
Koosha-Owji wants to merge 3 commits into
Conversation
WalkthroughTwo new TypeScript workflows were added: one captures IdP/OIDC id_token claims on PostAuthentication and stores them as a JSON user property; the other runs on token generation, reads that stored JSON, and injects claims into access and ID tokens with an Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Auth as PostAuthentication
participant API as KindeAPI
participant Props as UserProperties
participant TokenGen as TokenGeneration
participant Tokens as Access/ID Tokens
User->>Auth: OAuth2/OIDC login (id_token present)
activate Auth
Auth->>API: ensure `idp_claims` property exists (GET/POST)
API->>Props: create or verify property
Auth->>API: PATCH users/{userId}/properties with filtered idp_claims JSON
deactivate Auth
Note over TokenGen,API: On each token generation
TokenGen->>API: GET users/{userId}/properties
API->>Props: return properties (including `idp_claims`)
TokenGen->>TokenGen: parse `idp_claims` JSON
TokenGen->>Tokens: inject claims as idp\_<claimName> into access & id tokens
TokenGen-->>User: tokens issued with injected IdP claims
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
postUserAuthentication/IdpTokenWorkflow.ts (1)
1-7: Remove unused import.The
idTokenCustomClaimsimport is not used anywhere in the code. Consider removing it to keep the imports clean.Apply this diff:
import { onPostAuthenticationEvent, WorkflowSettings, WorkflowTrigger, accessTokenCustomClaims, - idTokenCustomClaims, } from "@kinde/infrastructure";
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
postUserAuthentication/IdpTokenWorkflow.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-19T06:39:44.342Z
Learnt from: ages96
Repo: kinde-starter-kits/workflow-examples PR: 6
File: postUserAuthentication/impossibleTravelWorkflow.ts:0-0
Timestamp: 2025-06-19T06:39:44.342Z
Learning: In Kinde's postUserAuthentication workflows, after the OTP authentication step, event.context.user consistently returns null for fields like name and email, with only the user ID being available. Therefore, kindeAPI.get() is required to retrieve the full user details including name and email fields.
Applied to files:
postUserAuthentication/IdpTokenWorkflow.ts
🔇 Additional comments (1)
postUserAuthentication/IdpTokenWorkflow.ts (1)
61-94: LGTM!The implementation is well-structured with proper defensive checks:
- Validates OAuth2 protocol before processing
- Guards against missing ID token claims
- Clear early returns prevent unnecessary execution
- Type definitions are explicit and the email extraction logic is straightforward
The extensive inline comments make it easy for future developers to extend this workflow with additional claims.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
captureIdpClaimsToTokens/AddIdpClaimsToTokensWorkflow.ts(1 hunks)captureIdpClaimsToTokens/CaptureIdpClaimsWorkflow.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
captureIdpClaimsToTokens/AddIdpClaimsToTokensWorkflow.ts (1)
captureIdpClaimsToTokens/CaptureIdpClaimsWorkflow.ts (1)
workflowSettings(48-59)
captureIdpClaimsToTokens/CaptureIdpClaimsWorkflow.ts (1)
captureIdpClaimsToTokens/AddIdpClaimsToTokensWorkflow.ts (1)
workflowSettings(52-67)
|
@Koosha-Owji it would be nice if you also updated the readme to include these new examples. |
Explain your changes
This PR adds two workflows that dynamically capture ALL claims from social identity providers (Google, Microsoft, etc.) and inject them into Kinde tokens.
How it works
Workflow 1: CaptureIdpClaimsWorkflow (PostAuthentication)
aiotoken, etc.)idp_claimsuser property as JSONWorkflow 2: AddIdpClaimsToTokensWorkflow (TokensGeneration)
idp_claimsproperty via Management APIidp_prefixChecklist
🛟 If you need help, consider asking for advice over in the Kinde community.
Summary by CodeRabbit