Skip to content

Support hierarchical permissions in consent and permission checks - #179

Open
Osara-B wants to merge 1 commit into
thunder-id:mainfrom
Osara-B:hierarchical-permissions
Open

Osara-B wants to merge 1 commit into
thunder-id:mainfrom
Osara-B:hierarchical-permissions

Conversation

@Osara-B

@Osara-B Osara-B commented Nov 13, 2026 •

Copy link
Copy Markdown

Purpose

ThunderID now supports hierarchical permissions (). A resource server created with hierarchicalPermissions: true treats a granted permission as covering the permissions beneath it, e.g. reservations covers reservations:create. That changes two things the SDK depends on:

  • Consent: a hierarchical permission purpose in consent_prompt now carries permissionDelimiter and displayElements, and the server decides each branch by its root's decision. The SDK's Consent component showed every permission as its own switch, so it could show a child as approved when the server would deny it.
  • Tokens: a token leaves out child scopes when it carries their parent. An exact scope check therefore rejects a user who is allowed.

This PR updates the SDK to match, without changing behaviour for servers or resource servers that don't use hierarchy.

Approach

Types (@thunderid/javascript)

  • ConsentPurposeData: adds optional permissionDelimiter and displayElements.
  • ResourceServer and CreateResourceServerRequest: adds optional hierarchicalPermissions. It is not added to the update request, because the server doesn't allow changing it after creation.

Consent branch view (React and Vue)

  • New core helper getConsentPermissionBranches groups a hierarchical purpose into one branch per root. It uses the same delimiter-boundary rule as the server's PermissionCovers, so orders-archive is not a child of orders.
  • When a permission purpose has permissionDelimiter, Consent shows one switch per branch, with the permissions it covers listed read-only beneath it, and a notice that approval also covers permissions added later.
  • A branch switch sets the decision of every prompted permission in that branch, so the submitted consent_decisions match what the server will record.
  • Purposes without permissionDelimiter render the same flat list as before.
  • React exports a new ConsentPermissionBranchList with a children custom render. Vue apps can customise it through Consent's default slot, using getConsentPermissionBranches, which @thunderid/vue now exports.
  • New translation key consent.permissions.subtree_notice, in all 10 shipped locales.

Permission checks

  • hasPermission(granted, required, matching?) takes optional {delimiter, hierarchical}. Without it, the behaviour is unchanged: : with hierarchy, matching the built-in System permissions.
  • useGrantedPermissions().can(required, matching?) in React, Vue and Next.js takes the same optional matching, so apps can check their own resource server's permissions. Without it, the behaviour is unchanged, so management checks such as can('system:group:view') work as before.
  • Nuxt defineThunderIDMiddleware gains scopeMatching. requireScopes still matches exactly by default. Passing {delimiter: ':'} lets a granted parent satisfy a required child.
  • PermissionMatching is exported from @thunderid/react and @thunderid/vue.

Compatibility: this PR has no breaking changes. All new fields and options are optional, and the new behaviour only applies when the server sends permissionDelimiter or the app passes matching options, so the SDK keeps working against servers without hierarchical permissions. If an app sets hierarchicalPermissions against an older server, that server ignores the field and creates an exact-match resource server.

Related Issues

Related PRs

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.
  • Cross-SDK parity. Exactly one of parity/prs-raised or parity/prs-not-needed added.
    • If parity/prs-raised, the port links are posted as a reply on the parity check's comment.

Security checks

  • Followed secure coding standards.
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🔀 Cross-SDK feature parity

Does this change need to ship in the other ThunderID SDKs too? This check stays red until one of these labels answers that:

Label What it asserts
parity/prs-raised The ports exist in every other SDK this change reaches, or are recorded as not applying there.
parity/prs-not-needed Nothing to port: a fix, refactor, docs, CI, dependency bump, release, or a change specific to this platform.

Ports (DO NOT EDIT)

  • thunder-id/ios-sdks, iOS => #52
  • thunder-id/android-sdks, Android => #61
  • thunder-id/flutter-sdks, Flutter => #72

3 of 3 sibling SDKs accounted for.

The contract is in the SDK development specification.

@Osara-B
Osara-B force-pushed the hierarchical-permissions branch from 6798181 to 70f60ca Compare November 13, 2026 09:37
Signed-off-by: Osara-B <osara922@gmail.com>
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