简体   繁体   English

如何让我的 angular 应用程序与我可以在 Azure 门户中按下的 b2c“撤销会话”按钮一起工作

[英]How do I get my angular application to work with b2c “revoke session” button which I can press in the Azure portal

My use case is to be able to forcibly require users to log in again both from a lost device/account compromised situation but also to update their cached user account which we enrich with additional information in our Angular app.我的用例是能够强制要求用户在丢失设备/帐户受损的情况下再次登录,还可以更新他们缓存的用户帐户,我们在 Angular 应用程序中添加了更多信息。

In Azure B2C I have available several administration buttons including the [Revoke Sessions].在 Azure B2C 中,我有几个管理按钮,包括 [Revoke Sessions]。 Behind the scenes this calls the graph function as described here (which my API can call programmatically later):- https://docs.microsoft.com/en-us/graph/api/user-revokesigninsessions?view=graph-rest-1.0&tabs=csharp在幕后,这调用了图 function,如此处所述(我的 API 可以稍后以编程方式调用):- https://graph-user-revssignins?view 1.0&tabs=csharp

b2c 中的管理按钮显示撤销会话

In my Angular application, I cannot get this to force my user to log in again on subsequent calls for secured resources.在我的 Angular 应用程序中,我无法强制我的用户在后续调用安全资源时再次登录。 I am expecting that when I make any call after pressing this button, it would send back a failure code that I could trap in an interceptor or similar.我希望当我在按下此按钮后拨打任何电话时,它会发回一个失败代码,我可以将其捕获在拦截器或类似物中。

The documentation is not clear & I am not even sure if I am misinterpreting how the action works.文档不清楚,我什至不确定我是否误解了该操作的工作原理。 I have looked at various answers including one about skewing time and customising the basic susi flow but that seems excessive for something which should be a common use case.我查看了各种答案,包括一个关于倾斜时间和自定义基本 susi 流程的答案,但这对于应该是一个常见用例的东西来说似乎太过分了。

I am using the published sample available at the following location with changes to point it to my B2C area.我正在使用以下位置提供的已发布示例,并进行更改以将其指向我的 B2C 区域。 Which has standard flows configured.其中配置了标准流程。 The issue occurs with the MSAL 1 and 2 code - neither work for this. MSAL 1 和 2 代码会出现此问题 - 均不适用于此问题。 用于注册登录的 B2C 用户流程

https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-angular-v2-samples/angular11-b2c-sample https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-angular-v2-samples/angular11-b2c-sample

Using this code with my settings, I am able to sign into B2C using the with a created account, edit my profile and view my example secured api.将此代码与我的设置一起使用,我可以使用创建的帐户登录 B2C,编辑我的个人资料并查看我的示例安全 api。

Within the B2C environment I press the revoke session button.在 B2C 环境中,我按下撤销 session 按钮。 On the client I try calling my api again and it just calls it as before.在客户端上,我尝试再次调用我的 api,它只是像以前一样调用它。

I suspect the change has to go into this part of app.component.ts sample:-我怀疑将 go 更改为app.component.ts示例的这一部分:-

      this.msalBroadcastService.msalSubject$
      .pipe(
        filter((msg: EventMessage) => msg.eventType === EventType.LOGIN_FAILURE || msg.eventType === EventType.ACQUIRE_TOKEN_FAILURE),
        takeUntil(this._destroying$)
      )
      .subscribe((result: EventMessage) => {
        console.log(result);
        if (result.error instanceof AuthError) {
          // Check for forgot password error
          // Learn more about AAD error codes at https://docs.microsoft.com/azure/active-directory/develop/reference-aadsts-error-codes
          if (result.error.message.includes('AADB2C90118')) {

            // login request with reset authority
            let resetPasswordFlowRequest = {
              scopes: ["openid"],
              authority: this.policies.authorities.forgotPassword.authority,
            }

            this.login(resetPasswordFlowRequest);
          }
        }
      });

The documentation with that sample points you to here for other events:- https://docs.microsoft.com/en-gb/azure/active-directory/develop/reference-aadsts-error-codes but again there is nothing mentioned about what to expect from revoke.带有该示例的文档将您指向此处以了解其他事件:- https://docs.microsoft.com/en-gb/azure/active-directory/develop/reference-aadsts-error-codes但同样没有提及撤销的期望是什么。

What am I missing and how can I get the sample application to force someone to log in again when they try to access a protected resource after that button has been pressed?我错过了什么?当某人在按下该按钮后尝试访问受保护的资源时,如何让示例应用程序强制他们再次登录?

Thank you谢谢

Azure AD can apply policies, including revoked sessions only when the next request for sign-in or acquiring access token is made. Azure AD 可以应用策略,包括仅在下一次请求登录或获取访问令牌时才撤销会话。

AAD today works in a stateless mode, so if a user is active in their web app because the session is based upon cookies that are still valid, and/or Access tokens still haven't run through their validity (they are valid for 1 hr after issuance by default), there is no server side mechanism to force sign out a user or invalidate an issued Access token. AAD 今天在无状态模式下工作,因此如果用户在其 web 应用程序中处于活动状态,因为 session 基于 cookies 仍然有效,并且/或运行的访问权仍然有效,并且/或默认情况下发布后),没有服务器端机制来强制注销用户或使已发布的访问令牌无效。

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

相关问题 在 NativeScript angular 应用程序中使用 Azure AD B2C 进行身份验证 - Authenticate using Azure AD B2C in a NativeScript angular Application 如何从 angular 调用 B2C Graph API? - How can I call B2C Graph API from angular? 在Azure AD B2C门户中使用loginRedirect生成访问令牌 - Generating access Token with loginRedirect in Azure AD B2C portal 如何将自定义值传递给 Azure AD B2C 并需要将该参数与响应或通用重定向 URI 一起返回? - How can I pass a custom value to Azure AD B2C and need to return that parameter along with the response or with the common Redirect URI? Angular Azure B2C SSO问题 - Angular Azure B2C SSO issue Azure Ad B2C:如何使用 msal-angular 传递在重定向中仍然可用的参数 url - Azure Ad B2C: How to use use msal-angular to pass parameter which still available in redirect url 来自 Angular 应用程序和 msal 的 Azure AD B2C:加载自定义 UI Html - Azure AD B2C from an Angular application and msal: Loading customized UI Html 使用 Azure AD B2C 从 Angular 应用程序和 msal.js 登录重定向用户 - Login redirect a user with Azure AD B2C from an Angular application and msal.js 如何设置我在用户流 AZ AD B2C 中看到的屏幕 - How set up the screen that I see in my user flow AZ AD B2C 如何让我的Angular5 spyOn按预期工作? - How can I get my Angular5 spyOn to work as expected?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM