mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-06 00:59:39 +03:00
OIDC with Azure Active Directory B2C: Unexpected Issuer or Unexpected type of key #4258
Closed
opened 2026-02-05 08:22:17 +03:00 by OVERLORD
·
4 comments
No Branch/Tag Specified
development
further_theme_development
l10n_development
release
llm_only
vectors
v25-11
docker_env
drawio_rendering
user_permissions
ldap_host_failover
svg_image
prosemirror
captcha_example
fix/video-export
v25.12.3
v25.12.2
v25.12.1
v25.12
v25.11.6
v25.11.5
v25.11.4
v24.11.4
v25.11.3
v25.11.2
v25.11.1
v25.11
v25.07.3
v25.07.2
v25.07.1
v25.07
v25.05.2
v25.05.1
v25.05
v25.02.5
v25.02.4
v25.02.3
v25.02.2
v25.02.1
v25.02
v24.12.1
v24.12
v24.10.3
v24.10.2
v24.10.1
v24.10
v24.05.4
v24.05.3
v24.05.2
v24.05.1
v24.05
v24.02.3
v24.02.2
v24.02.1
v24.02
v23.12.3
v23.12.2
v23.12.1
v23.12
v23.10.4
v23.10.3
v23.10.2
v23.10.1
v23.10
v23.08.3
v23.08.2
v23.08.1
v23.08
v23.06.2
v23.06.1
v23.06
v23.05.2
v23.05.1
v23.05
v23.02.3
v23.02.2
v23.02.1
v23.02
v23.01.1
v23.01
v22.11.1
v22.11
v22.10.2
v22.10.1
v22.10
v22.09.1
v22.09
v22.07.3
v22.07.2
v22.07.1
v22.07
v22.06.2
v22.06.1
v22.06
v22.04.2
v22.04.1
v22.04
v22.03.1
v22.03
v22.02.3
v22.02.2
v22.02.1
v22.02
v21.12.5
v21.12.4
v21.12.3
v21.12.2
v21.12.1
v21.12
v21.11.3
v21.11.2
v21.11.1
v21.11
v21.10.3
v21.10.2
v21.10.1
v21.10
v21.08.6
v21.08.5
v21.08.4
v21.08.3
v21.08.2
v21.08.1
v21.08
v21.05.4
v21.05.3
v21.05.2
v21.05.1
v21.05
v21.04.6
v21.04.5
v21.04.4
v21.04.3
v21.04.2
v21.04.1
v21.04
v0.31.8
v0.31.7
v0.31.6
v0.31.5
v0.31.4
v0.31.3
v0.31.2
v0.31.1
v0.31.0
v0.30.7
v0.30.6
v0.30.5
v0.30.4
v0.30.3
v0.30.2
v0.30.1
v0.30.0
v0.29.3
v0.29.2
v0.29.1
v0.29.0
v0.28.3
v0.28.2
v0.28.1
v0.28.0
v0.27.5
v0.27.4
v0.27.3
v0.27.2
v0.27.1
v0.27
v0.26.4
v0.26.3
v0.26.2
v0.26.1
v0.26.0
v0.25.5
v0.25.4
v0.25.3
v0.25.2
v0.25.1
v0.25.0
v0.24.3
v0.24.2
v0.24.1
v0.24.0
v0.23.2
v0.23.1
v0.23.0
v0.22.0
v0.21.0
v0.20.3
v0.20.2
v0.20.1
v0.20.0
v0.19.0
v0.18.5
v0.18.4
v0.18.3
v0.18.2
v0.18.1
v0.18.0
v0.17.4
v0.17.3
v0.17.2
v0.17.1
v0.17.0
v0.16.3
v0.16.2
v0.16.1
v0.16.0
v0.15.3
v0.15.2
v0.15.1
v0.15.0
v0.14.3
v0.14.2
v0.14.1
v0.14.0
v0.13.1
v0.13.0
v0.12.2
v0.12.1
v0.12.0
v0.11.2
v0.11.1
v0.11.0
v0.10.0
v0.9.3
v0.9.2
v0.9.1
v0.9.0
v0.8.2
v0.8.1
v0.8.0
v0.7.6
v0.7.5
v0.7.4
v0.7.3
0.7.2
v.0.7.1
v0.7.0
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
Labels
Clear labels
🎨 Design
📖 Docs Update
🐛 Bug
🐛 Bug
:cat2:🐈 Possible duplicate
💿 Database
☕ Open to discussion
💻 Front-End
🐕 Support
🚪 Authentication
🌍 Translations
🔌 API Task
🏭 Back-End
⛲ Upstream
🔨 Feature Request
🛠️ Enhancement
🛠️ Enhancement
🛠️ Enhancement
❤️ Happy feedback
🔒 Security
🔍 Pending Validation
💆 UX
📝 WYSIWYG Editor
🌔 Out of scope
🔩 API Request
:octocat: Admin/Meta
🖌️ View Customization
❓ Question
🚀 Priority
🛡️ Blocked
🚚 Export System
♿ A11y
🔧 Maintenance
> Markdown Editor
pull-request
Mirrored from GitHub Pull Request
No Label
🐕 Support
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/BookStack#4258
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @JanekOstendorf on GitHub (Oct 4, 2023).
Attempted Debugging
Searched GitHub Issues
Describe the Scenario
I'm working on using Microsoft's Azure Actice Directory B2C for authentication with BookStack.
Azure AD B2C does support and use OpenID Connect, which already is supported by BookStack.
However, when setting up the OIDC configuration, I run into one of two problems, depending on whether
OIDC_ISSUER_DISCOVERYis enabled or disabled:Scenario 1:
OIDC_ISSUER_DISCOVERYenabledAzure AD B2C provides a discovery URL at
https://[tenant name].b2clogin.com/[tenant name].onmicrosoft.com/[policy name]/v2.0/.well-known/openid-configuration, so I usedhttps://[tenant name].b2clogin.com/[tenant name].onmicrosoft.com/[policy name]/v2.0/as theOIDC_ISSUERin the BookStack configuration.The
[policy name]in the URL is the name of the B2C policy, which defines the behavior of B2C regarding UI, login method, etc.This way, BookStack retrieves the discovery info at
<issuer>/.well-known/openid-configurationcorrectly and gets the correct info from B2C.Configuration
On login, BookStack does not redirect to the OIDC Identity Provider.
The browser displays this error message:
From the code I can see that this happens when the issuer from
OIDC_ISSUERdoes not match theissuerfield in the auto discovers JSON.The issuer URL does indeed not match.
Microsoft lists the actual issuer URL
https://[tenant name].b2clogin.com/[tenant UUID]/v2.0/in the JSONopenid-configurationwhich is also the URL used in the actual OIDC/OAuth tokens.This actual issuer URL is used for all B2C policies.
For the
openid-configuration, however, it is necessary to distinguish between the different B2C policies, because they use different endpoints for authorization and token.Scenario 2:
OIDC_ISSUER_DISCOVERYdisabledIn order to solve the problem with the issuer mismatch, I tried setting up the integration without
OIDC_ISSUER_DISCOVERY:I retrieved these values directly from the JSON returned from the discovery URL at
https://[tenant name].b2clogin.com/[tenant name].onmicrosoft.com/[policy name]/v2.0/.well-known/openid-configuration.BookStack then correctly redirects to the login page of B2C.
When BookStack receives the token back, the browser shows this error message:
From what I can see in the code, this error is thrown when the OIDC key configuration does not fit into these possibilities:
OIDC_ISSUER_DISCOVERYis enabled, thejwks_uriis read from the discovery JSON and the keys are then downloaded from there.OIDC_PUBLIC_KEYmust be a local file and the configuration string must start withfile://. It is not possible to set a JWKS URI manually this way.However in my scenario, I would like to set
OIDC_PUBLIC_KEYto the JWKS URL manually, but BookStack does not allow this.Possible solutions
I understand that Azure AD B2C might not be following the OIDC specs correctly with their difference between the actual issuer URI and the URI for
openid-configuration.Because of this, I'd like to set the OIDC endpoints manually.
I would also like to use the existing JWKS URI instead of downloading the public key files locally.
Microsoft may change keys without further notice and already provides the JWKS URI for this purpose.
Is it possible to change the behavior of the
OIDC_PUBLIC_KEYconfiguration to allow to set JWKS URIs manually?Exact BookStack Version
v23.08.3
Log Content
For scenario 1 with
OIDC_ISSUER_DISCOVERenabled, the browser shows this error message when clicking theLogin with ...button on the BookStack login page:In scenario 2 with
OIDC_ISSUER_DISCOVERdisabled, the browser redirects to Azure AD B2C correctly when clicking theLogin with ...button.When Azure AD B2C redirects back to BookStack, the browser shows this error message:
The
laravel.log, nginx logs, and PHP logs do not contain any errors.Hosting Environment
I'm currently hosting this as a Proof of Concept running on Windows using Docker Desktop with WSL Ubuntu 22.04.2 LTS.
I am running using the Linuxserver Docker image
lscr.io/linuxserver/bookstackwithmysql:8.0.32as the image for the database container.@ssddanbrown commented on GitHub (Oct 4, 2023):
Hi @JanekOstendorf,
Thanks for the amount of detail provided for this.
To be honest though, I really am not keen on making changes and/or supporting features at our cost due to the complexities and issues of Microsoft. The keys setup is part of the discovery spec, and really that should be followed rather than us maintaining partial compatibility support.
It could be possible to hack support for this via the logical theme system, but might be a bit janky (fetching keys manually and caching for a time).
While looking over this issue I did come across this from Microsoft docs:
https://learn.microsoft.com/en-us/azure/active-directory-b2c/tokens-overview#compatibility
Specifically "Compatibility > Issuer (iss) claim" section which states:
Do you have this compatibility option active? Further related docs here.
@JanekOstendorf commented on GitHub (Oct 6, 2023):
Hi! Thanks for your response.
I will check out the token compatibility and check if they work with our custom B2C policies. This looks like a good way to solve this. I'll report back.
@ssddanbrown commented on GitHub (Nov 2, 2023):
Since it's been a little while I'm going to go ahead and close this off.
If that solved things, please still report back though so that it can help others that may have come across the same scenario.
@JanekOstendorf commented on GitHub (Dec 19, 2023):
Hi!
I just wanted to let you know that we were able to get the Azure AD B2C integration running with the
AuthorityWithTfpoption enabled (https://learn.microsoft.com/en-us/azure/active-directory-b2c/tokens-overview#compatibility).Thanks again for your help.