@nathapp/nestjs-iam-oauth
Bridges @nathapp/nestjs-iam users and sessions into @nathapp/nestjs-oauth.
IamOAuthModule.register(); // global by default
It provides:
| Token |
Default |
Purpose |
RESOURCE_OWNER_SERVICE |
DefaultIamResourceOwnerService |
Claims and isActive for the OAuth grants and UserInfo. |
SESSION_TERMINATOR |
DefaultIamSessionTerminator |
Ends IAM sessions on OIDC logout. |
CURRENT_USER_RESOLVER |
DefaultIamCurrentUserResolver |
Resolves the signed-in user at /oauth/authorize. |
USER_DEACTIVATION_HOOK |
DefaultIamOAuthUserDeactivationHook |
Revokes OAuth tokens when IAM suspends or deletes a user. |
registerAsync({ services: { ... } }) replaces any of them.
Tenant isolation
DefaultIamCurrentUserResolver returns no user when the session's tenant differs
from the request tenant, so a session signed in at tenant A cannot authorize at
tenant B's issuer. When no request tenant is resolved (no tenant context wired,
or no tenant on the request), the session resolves as before.
Deactivated users
DefaultIamResourceOwnerService.isActive returns true only for an IAM user
with status ACTIVE. An unknown user, any other status, or a bridge without
USER_SERVICE fails closed. The authorization-code, refresh-token and
device-code grants and UserInfo refuse an inactive user.
DefaultIamOAuthUserDeactivationHook calls
OAuthUserTokenRevoker.revokeAllForUser(userId) inside the IAM
suspend/delete transaction. With the Prisma repositories the revocation
commits or rolls back with the status change; a revoker error fails the
suspend/delete.
Wiring notes
- With
IamOAuthModule.register({ global: false }), IamModule cannot see the
hook and suspend/delete skip OAuth revocation. Provide
USER_DEACTIVATION_HOOK in a module IamModule resolves it from. The
isActive check on the grants and UserInfo still applies.
OAuthUserTokenRevoker (from @nathapp/nestjs-oauth) must be resolvable.
The hook requires it on purpose, so a missing revoker fails at boot instead of
silently skipping revocation.
- A token repository without the optional
revokeByUser method is skipped with
a warning. @nathapp/nestjs-oauth-prisma implements it.