简体   繁体   English

Azure Active Directory 令牌验证

[英]Azure Active Directory Token Validation

I'm integrating Azure Active Directory into a cloud platform.我正在将 Azure Active Directory 集成到云平台中。 As our application is multi-tenant and relies on platform-specific claims, we've identified the simplest way to go about this is get an Azure AD token via our SPA, pass it back to our WebApi, validate it and return to the SPA a platform token with all the claims we need to go about our normal business (as if it was a simple username/password athentication request).由于我们的应用程序是多租户的并且依赖于特定于平台的声明,因此我们确定了最简单的方法是通过我们的 SPA 获取 Azure AD 令牌,将其传回我们的 WebApi,对其进行验证并返回给 SPA一个平台令牌,包含我们开展正常业务所需的所有声明(就好像它是一个简单的用户名/密码验证请求)。

I'm concerned at the level of security for this though.不过,我对此的安全级别感到担忧。

Some Context一些上下文
As our platform is multi-tenant, we request that clients each register the application on their Azure AD portal, then supply us with the generated Application (client ID) and Directory (tenant) ID .由于我们的平台是多租户的,因此我们要求每个客户端在其 Azure AD 门户上注册应用程序,然后向我们提供生成的应用程序(客户端 ID)目录(租户) ID We use these two pieces of information to make the initial request to Azure via our front-end SPA (following the node.js example provided by Microsoft's Quickstart guide when registering an app).我们使用这两条信息通过我们的前端 SPA 向 Azure 发出初始请求(在注册应用程序时遵循 Microsoft 的Quickstart指南提供的node.js示例)。 Now because the user is unauthenticated at this point, we needed some way to return those two specific ids for the client.现在因为用户此时未经身份验证,我们需要一些方法来为客户端返回这两个特定的 id。 We have accomplished this using a sub-domain for identification.我们已经使用子域进行识别来实现这一点。

Eg acmeinc.mydomain.com will return a different Application (client ID) and Directory (tenant) ID than billy.mydomain.com .例如acmeinc.mydomain.com将返回不同的应用程序(客户端ID)和目录(租户)ID比billy.mydomain.com These are obviously public now as this request happens from an un-authenticated front-end route.这些现在显然是公开的,因为此请求来自未经身份验证的前端路由。

I can handle the token response just fine, both in the front-end and in the back-end when I pass it along, and validate that these two pieces of information are correct in the token, but seeing as the front-end is given them to begin with, validation on these is redundant.当我传递它时,我可以在前端和后端处理令牌响应,并验证这两条信息在令牌中是否正确,但看到前端给出首先,对这些进行验证是多余的。 Also, validating the issuer seems equally redundant as someone who knows the Directory (tenant) ID, can fake that too (right?)此外,验证发行者似乎与知道目录(租户)ID 的人一样多余,也可以伪造(对吗?)

Am I missing something here?我在这里错过了什么吗? I would feel far more at ease if it were possible to request the client also include a claim that my platform generates privately such that I could validate this claim alongside the normal JWT validation.如果可以要求客户端也包含我的平台私下生成的声明,以便我可以在正常 JWT 验证的同时验证此声明,我会感到更轻松。 Custom claims do not seem possible from the Azure AD Portal. Azure AD 门户似乎无法自定义声明。

Am I missing a critical step, or just overthinking this?我是否错过了关键步骤,或者只是想多了?

Someone cannot fake the issuer in the token because the token is digitally signed.某人无法在令牌中伪造发行者,因为令牌是经过数字签名的。 Without the private keys of Azure AD, it isn't feasible to generate a valid signature.如果没有 Azure AD 的私钥,就无法生成有效的签名。 Without that, any modifications to the token will be immediately noticed because the signature does not match.否则,对令牌的任何修改都会立即被注意到,因为签名不匹配。

Your back-end should already be validating this signature if you are using standard JWT validation.如果您使用标准 JWT 验证,您的后端应该已经在验证此签名。

Requiring customers to register an app in their tenant is a bit of work that I would prefer not to put on them.要求客户在他们的租户中注册应用程序是一项我不想让他们做的工作。 Have you considered making your app a multi-tenant app in Azure AD?您是否考虑过在 Azure AD 中使您的应用成为多租户应用? That way your customers could login to your app, consent to the permissions required, and start using it.这样您的客户就可以登录您的应用程序,同意所需的权限,然后开始使用它。 Without needing to manually register anything.无需手动注册任何东西。 This could be done in an on-boarding flow where the user signs in, and then they can decide what sub-domain they want.这可以在用户登录的入职流程中完成,然后他们可以决定他们想要的子域。 You will at that point know their tenant id, which you can store.那时您将知道他们的租户 ID,您可以存储该 ID。 So in the future you can always use the correct tenant/directory id when signing them in.因此,将来您可以在登录时始终使用正确的租户/目录 ID。

The downside of this approach is managing the reply URLs.这种方法的缺点是管理回复 URL。 With the specially registered apps, they can register their own sub-domain version as a reply URL.使用专门注册的应用程序,他们可以将自己的子域版本注册为回复 URL。 With this generic multi-tenant app, you'll need to manage them.使用这个通用的多租户应用程序,您需要管理它们。 And you can't add an infinite amount of them, and wildcards aren't supported anymore either.并且您不能添加无限数量的通配符,并且也不再支持通配符。 So, your authentication would have to happen with a generic authentication reply URL like auth.mydomain.com, from which they would be redirected to their tenant URL.因此,您的身份验证必须使用像 auth.mydomain.com 这样的通用身份验证回复 URL,他们将从该 URL 重定向到其租户 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM