Iam Integration

v1.0.0

Use when integrating a new service with the IAM (Identity and Access Management) system - covers gRPC client setup, JWT token validation, permission checks,...

0· 112· 1 versions· 0 current· 0 all-time· Updated 11h ago· MIT-0

Install

openclaw skills install iam-integration

IAM Integration Guide

Overview

IAM is the central identity service. Services integrate via gRPC (primary) or REST. All resources are scoped by appCode + tenantCode.

Quick Reference

NeedMethodEndpoint/Service
Validate JWT tokengRPCJwtTokenService.validateAccessToken
Check permissiongRPCAuthorizationService.hasPermission
Get user by UIDgRPCAccountService.GetByUid
LoginRESTPOST /api/v1.0/login/generateTicket
Exchange ticket for tokenRESTPOST /api/v1.0/account/exchangeAuthTicket
Get current userRESTGET /api/v1.0/account/current

1. gRPC Integration (Recommended)

Dependency

<dependency>
    <groupId>com.feilun</groupId>
    <artifactId>iam-rich-client</artifactId>
</dependency>
<dependency>
    <groupId>com.feilun</groupId>
    <artifactId>iam-boot-starter</artifactId>
</dependency>

Configuration

grpc:
  client:
    iam-service:
      address: dns:///iam.${namespace}.svc.cluster.local:9090
      negotiation-type: plaintext

Token Validation

@Autowired JwtTokenRichClient jwtTokenClient;

// Validate token (with optional permission check)
ValidateAccessTokenRequest req = ValidateAccessTokenRequest.newBuilder()
    .setAccessToken(token)
    .setAppCode(appCode)
    .setTenantCode(tenantCode)
    // optional: add permission check
    .setPermissionCheck(PermissionCheck.newBuilder()
        .setObject("resource-name")
        .setAct("read")
        .build())
    .build();

ValidateAccessTokenResponse resp = jwtTokenClient.validateAccessToken(req);
// resp.getUid(), resp.getRoleCodesList(), resp.getValid()

Permission Check

@Autowired AuthorizationRichClient authClient;

HasPermissionRequest req = HasPermissionRequest.newBuilder()
    .setAppCode(appCode)
    .setTenantCode(tenantCode)
    .setSubject(uid)
    .setObject("resource-name")
    .setAct("write")
    .setSiteCode(siteCode)
    .build();

boolean allowed = authClient.hasPermission(req).getHasPermission();

Get Account Info

@Autowired AccountRichClient accountClient;

GetByUidRequest req = GetByUidRequest.newBuilder()
    .setUid(uid).setAppCode(appCode).setTenantCode(tenantCode)
    .build();

AccountProto account = accountClient.getByUid(req).getAccount();

2. REST API Integration

Required Headers

HeaderDescription
X-ACCESS-TOKENJWT token
X-AppApp code
X-TenantTenant code
X-UidUser UID (set by gateway)
X-IS-MOBILEtrue / false

Auth Filter

Add IamAuthInfoFilter to your service to auto-extract auth context from headers into thread-local.

// Access current user context anywhere in request thread
IamAuthContext ctx = IamAuthContextHolder.get();
String uid = ctx.getUid();
String tenantCode = ctx.getTenantCode();

3. Key Data Models

Account: uid, appCode, tenantCode, loginName, email, mobile,
         acctStatus(0=inactive,1=active,2=disabled,9=cancelled),
         acctType(0=sub,1=main), roleCodes[], siteScope[]

Authorization: subject(uid/role), object(resource), act(read/write/delete),
               permitAll(bool), permitTargetId[], permitObjectId[]

4. Multi-tenancy Rules

  • Every call must include appCode + tenantCode
  • JWT secrets are per-app/tenant (iam_jwt_secret table)
  • Permissions are site-scoped — always pass siteCode when checking

5. Common Mistakes

MistakeFix
Missing appCode/tenantCodeAlways required in every gRPC request
Checking permission without siteCodePass siteCode for site-scoped resources
Calling REST without X-App/X-Tenant headersRequired for all REST calls
Using system mvn to buildUse ./mvnw — project requires Maven 3.8.x via wrapper

6. Account Status Reference

CodeStatus
0Inactive (pending activation)
1Active
2Disabled
3Locked
8Cancellation in progress
9Cancelled

Version tags

latestvk972cfj8xswnssjaheasvjp68h855eh1