AshAuthentication trusted audiences
Hello, I'm in the process of deploying a multi-tenant application internally in my company. I'm authenticating users against Microsoft Entra ID using the OAuth2 strategy. We have two tenants that I need to allow users to authenticate from and wish to use the
trusted_audiences
to ensure that a user signs in from one of the tenants, but reject all others.
I have set it up as described in the docs, but when I test it locally by only allowing a "fake" audience in the list of trusted audiences, I'm still authorized to login. Do I have to do anything else to make this work, or have I misunderstood something?
Solution:Jump to solution
So it seems like my options are:
1. Change to using OIDC strategy. Supports
trusted_audiences
but struggles with using the /common/.well-known/openid-configuration
endpoint because it contains a placeholder {tenantid}
in its issuer which is not supported natively by assent. This cause the issuer validation to fail, because the issuer in my token contains my real tenant-id.
Could work, but requires a custom strategy?
2. Continue with using OAuth2 strategy. Works out of the box with multi-tenant applications, but needs to implement a custom trusted_audience
handler either as a change
function or in auth controller success callback (and then deny access unless audience matches allow-list)....7 Replies
Hm...I'm not really sure how trusted audiences work. @jart?
It could be that I don't either 😅 I just assumed that it would only allow those specified.
Honestly no idea. We just pass the options through to assent to use.
Aha, I see. After a short search in the assent Github repo, it seems like it's only actually being used for the OIDC strategy.
https://github.com/search?q=repo%3Apow-auth%2Fassent%20trusted_audiences&type=code
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.

So if I wish to do some kind of custom validation (after the strategy has completed), where's the best way to put it? As a change function in my
:register_with_azure
create action, or would you just put it in the auth_controller callback?Solution
So it seems like my options are:
1. Change to using OIDC strategy. Supports
trusted_audiences
but struggles with using the /common/.well-known/openid-configuration
endpoint because it contains a placeholder {tenantid}
in its issuer which is not supported natively by assent. This cause the issuer validation to fail, because the issuer in my token contains my real tenant-id.
Could work, but requires a custom strategy?
2. Continue with using OAuth2 strategy. Works out of the box with multi-tenant applications, but needs to implement a custom trusted_audience
handler either as a change
function or in auth controller success callback (and then deny access unless audience matches allow-list).Yeah that sounds correct to me