NestJS backend integration: clean handling of OAuth2 enrollment flow with Authentik #15963
Unanswered
AnthonyGhizzo
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I’m working on an Authentik integration in a NestJS backend for a multi-tenant SaaS project.
I’ve configured two flows:
• A login flow (XXX-dev-authentication-flow) linked to an OAuth2 provider → everything works fine via /application/o/authorize.
• A custom enrollment flow (XXX-dev-enrollment-flow) not linked to any provider → I have to redirect users manually via /if/flow/... and pass a next parameter that points to /authorize.
Example of the enrollment URL I have to build manually:
GET /if/flow/hyspose-dev-enrollment-flow/?next=https://iam.XXX.tech/application/o/authorize/?client_id=...&redirect_uri=...&scope=...&response_type=code&state=enrollment
Problem
👉 Unlike login, nothing is automated on the Authentik side for the enrollment flow:
• I must manually construct the full URL,
• Authentik doesn’t allow linking an enrollment flow directly to a provider,
• This approach feels brittle (e.g., if the client_id or redirect_uri changes),
• And I couldn’t find any official documentation clearly explaining this use case.
My questions
1. Is this the recommended way to handle OAuth2 enrollment flow in a backend/API-oriented context (e.g., NestJS, Next.js)?
2. Is there any plan to allow linking an enrollment flow directly to an OAuth2 provider, just like login flows?
3. Are there any official best practices or documentation for this kind of integration (OAuth2 with a backend-first app)?
⸻
My goal
To ensure a reliable, secure, and scalable integration of Authentik into my SaaS backend — without relying on manually-crafted next URLs.
Thanks in advance for your help 🙏
Beta Was this translation helpful? Give feedback.
All reactions