如何在MSAL角度配置中为所有不需要的API添加范围null

问题描述

我们有一个有角度的应用程序,它调用了多个API。当前,我们只对仅向两个API注入b2c访问令牌感兴趣,并希望避免使用其他API。

我们的API如下

https://testdomain.com/onprem/proxy/handler/api/account/someendpoint
https://testdomain.com/onprem/proxy/handler/something/api/account/someendpoint
https://testdomain.com/onprem/something/api/account/endpoint
https://testdomain.com/cloud/api/app1/something/endpoint

由于API调用的结构不同。我们目前的实施方式如下

export const protectedResourceMap: [string,string[]][] = [
['/cloud/api/app1/account/gettestaccount',['scope1']],['/cloud/api/app2/account/getanotheraccount',['scope2']],['/onprem/*/*/*/*/*',null],['/onprem/*/*/*/*/*/*',['/onprem/*/*/*/*',null]
]

因此,MSAL拦截器正在使用 minimatch 将req.url与protectedresourcemap进行匹配。 在上面的示例中,我用scopes:null指定了3种不同的模式。因此getScopesForEndpoint()将被呼叫5次,即使在这5次呼叫中,有3次是不需要的。

请提出一些更好的方法来向protectedResourceMap的{​​{1}}中添加url,这样我就可以减少对scopes: null调用并提高前端应用程序的性能。 / p>

谢谢。

解决方法

getScopesForEndpoint将始终被调用,即使在更改为minimatch之前也是如此。如果您担心在这种情况下的性能,我们可以考虑改进getScopesForEndpoint使其不调用minimatch(如果设置了null)。