-
-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for azure ad v2 multitenant apps #148
Conversation
Codecov Report
@@ Coverage Diff @@
## master #148 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 18 18
Lines 798 803 +5
=====================================
+ Hits 798 803 +5 |
Hello @ulrikstrid I'm really reluctant to be adding vendor specific workarounds to a library that aims to be interoperable between certified solutions, which Azure AD is. That being said let's give it a chance, if you wouldn't mind, fixing the test syntax not to use trailing commas (eslint should pick up on this for you) and writing down an understandable reasoning behind this change. What use case is trying to solve and why is it needed, with code examples please. I will then ping the responsible person from Microsoft for consult. Thank you for putting your effort into this and bearing with the above. |
I tried to fix the linting issues but might take another go at it as it seems I didn't get it to work. Our use case is that we want to create a multi tenant application where other companies can login with their own Azure AD to our application. This is, as stated in #84, currently not possible because Microsoft does some non-standard things in their discovery document. They return issuer URL that should have The returned issuer is always This PR allows to use a array of valid tenantId's, if that list is omited we just match the Our usage code is this: const adIssuer = await Issuer.discover(
`https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration`
);
const adClient = new adIssuer.Client({
redirect_uri: REDIRECT_URI,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
token_endpoint_auth_method: "client_secret_basic",
isAzureADv2Multitenant: true,
azureADv2ValidTenantIds: ["74d3d36e-789f-4168-99dd-4a6052d32573"] // GUID changed from our real GUID
}); Anything else you want me to clarify? |
The test is failing because node |
Co-authored-by: Simon Gottschlag <[email protected]>
@ulrikstrid before i reach out to Mike, can't you do discovery on a route which is specific to your tenant id? I seem to recall https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration does have a tenant specific result when you replace |
When I change common to my tenant id I get back a issuer with my tenant id in it, but then I need to have separate routes for each of our customers and I would really like to avoid that as that is a lot more work than adding a new customer to the database. |
that is indeed the case
Since the PR suggests you know the tenantIds upfront i think you can get without it. At authorization request time, do you know the |
I don't know the |
So are you blindly accepting users from tenant ids not belonging to your current customer? |
Anyone can get to the login, but with the changes in this PR I can match them to the list of tenant ids I provide in the configuration |
Does a customer of yours provide his tenant id? |
We will know tenant id's ahead of time as we need to register them as customers in the application. But we don't know them for each connection. |
The main goal of this is to have one "Azure AD Application" that is configured to be multi tenant. This means we can connect an application using node-openid-client to it and use Azure AD for authentication of all users (from any tenant) with this. For some usecases, this is something that you would like to do (to use Azure AD as an OP just like you use GitHub and Google). In our case, we don't want to allow access to all Azure AD tenants, but specific ones. On our side, we will store the customers with an Azure AD tenant ID - which we will pick up for all customers and generate the array to use with |
I think its pointless to compare tid and iss and it only makes this azure-specific and unnecessary complex. If someone wants to do that, they can do that afterwards in their own code. What I propose is to have something like "ignoreIssuerValidation" or "validateIssuer: false" flags instead for ignoring it. Additionally, you could have something like "validIssuers" array for having multiple issuers instead of ignoring it completely. This way it is not tied to Azure AD and can be used in other cases while still allowing multiple Azure tenants to be supplied to the validIssuers array. They just have to be in full iss format instead of just the tenant-id. This kind of approach is what Microsoft also suggests in their documentation for multi-tenanted applications.
|
The solution i'm leaning towards is to refactor the ID Token validation so that it allows for some prototype overloading on specific parts. That's one thing. The other is i'll probably expose (as part of this library or a new one, not sure yet) another issuer/client constructor just for AAD. |
Just checking in, i haven't forgotten about this, I'm just now planning to revive the work on 3.x (due in April with node 12 release) and i'll include this there. |
I had to add support for MS login across multiple tenants today and just ended up forking this project and adding my own little dirty patch to define custom iss validation. Let me know if I can help on testing or implementing proper support. |
Coming back to this as I progress on v3.x There are a few points of feedback i need confirmed from you.
Thoughts? |
This PR adds support for Azure AD v2 multitenant apps. Flags are documented in README.