A SaaS team publishes product documentation on GitBook, embeds it into their customer portal, and gates access behind IDaaS-configured authentication (social login, 2FA) so only authenticated users can view the embedded docs.
When a SaaS platform needs to deliver contextual, version-controlled documentation directly inside its customer dashboard while enforcing strict identity verification. This workflow combines GitBook’s publishing and embedding capabilities with IDaaS to ensure only verified users (via social login + 2FA) can access private documentation spaces.
Identity Providers and enforce 2FA via Security Policies > Multi-Factor Authentication. Record client_id, client_secret, and issuer URL.Space Settings > Access Control. Set visibility to Private and enable JWT Authentication. Generate an HS256 signing secret or upload a JWKS public key.POST https://<tenant>.idaas.aliyuncs.com/oauth2/token, then mint a GitBook-compatible JWT:``bash jwt encode --alg HS256 --secret $GITBOOK_HS256_SECRET \ --payload '{"sub":"user_123","email":"[email protected]","exp":1735689600}' ``
@gitbook/embed and configure it with the private space URL and auth payload:``javascript import { GitBookEmbed } from '@gitbook/embed'; const embed = new GitBookEmbed({ url: 'https://docs.yourdomain.com', auth: { type: 'jwt', token: generatedToken } }); ``
``html <div id="gitbook-docs" style="height:80vh;width:100%"></div> <script>embed.mount('#gitbook-docs');</script> ``
postMessage, and confirm GitBook serves content without 401/403 errors.User initiates login in the SaaS portal → IDaaS orchestrates social auth + 2FA, returning an OIDC session → SaaS backend validates IDaaS claims and mints a GitBook-scoped JWT → Frontend passes the JWT to @gitbook/embed → GitBook validates the signature against the configured secret/JWKS and streams private documentation. IDaaS owns identity lifecycle; GitBook owns content delivery and access validation.
redirect_urisub and exp. Omitting them triggers 403 Forbidden on embed load.X-Frame-Options isn’t whitelisted for your portal domain.redirect_uri doesn’t exactly match the OIDC app configuration (trailing slashes matter)./token endpoint before expiry.Q: How do I embed GitBook documentation behind authentication? A: You can protect an embedded documentation portal by combining GitBook Publish, GitBook Embed, and IDaaS authentication configuration. This setup lets you embed your GitBook site into a customer portal and gate access behind IDaaS methods like social login or two-factor authentication. As a result, only authenticated users can view the embedded content.