agentsclimarketplace

Jwt extraction via base controller

Skill kjuhwa/skills-hub/skills/backend/jwt-extraction-via-base-controller

Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.

Install
npx -y skills add kjuhwa/skills-hub --skill jwt-extraction-via-base-controller

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Consolidate repeated `JwtTokenService.getXxxFromBearerToken(headerAuthorization)` calls across Spring controllers by moving the service and helper methods onto a shared `BaseController`. Subclass controllers call `getOrganizationId(h)` / `getLoginId(h)` / `getRoleIds(h)` directly.

SKILL.md

2.2 KB, 357 tokens by cl100k_base, as published. Nobody here has run it

JWT Claim Extraction via BaseController

Put JwtTokenService + protected helper methods (getOrganizationId, getLoginId, getRoleIds) on a shared BaseController. Concrete controllers extend and call helpers directly, eliminating per-controller field declarations and reducing Authorization header handling to one line per use.

When to use

  • Multiple Spring controllers share the same bearer-token claim extraction.
  • You don't yet need a full @AuthenticationPrincipal / HandlerMethodArgumentResolver layer.
  • Refactor target: repeated jwtTokenService.getXxxFromBearerToken(headerAuthorization) calls.

Steps

  1. Introduce or reuse abstract class BaseController.
  2. Add @Autowired protected JwtTokenService jwtTokenService;protected is intentional so subclasses see it directly while DI still works.
  3. Add helpers:
    protected String getOrganizationId(String h) { return jwtTokenService.getOrganizationIdFromBearerToken(h); }
    protected String getLoginId(String h)        { return jwtTokenService.getLoginIdFromBearerToken(h); }
    protected List<String> getRoleIds(String h)  { return jwtTokenService.getRoleIdsFromBearerToken(h); }
    
  4. Subclass controllers: remove private final JwtTokenService jwtTokenService, drop its import, replace calls with the helpers.
  5. Skip for controllers that don't consume JWT (file upload, dev-only token minting).

Counter / Caveats

  • Prefer HandlerMethodArgumentResolver + @AuthPrincipal if you have many controllers or need strong test isolation.
  • Inheritance-based sharing couples controllers to BaseController; keep BaseController thin (exception handling + these helpers only).

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.