-
Notifications
You must be signed in to change notification settings - Fork 197
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
Azure B2C authentication from SPFX App Teams #2669
Comments
@Ben-Oops - Thank you for bringing this issue to our attention. We will look into it and get back to you shortly. |
@Ben-Oops thanks for providing a great level of detail in your question, including a code snippet! You're right that solution1 won't work for pop-up blocking reasons, which is why the authentication.authenticate function exists, like you are using in solution2. In solution 2, is the page that you're directing the pop-up to ( You can see a visual overview of this expected flow here: From the code that I see, it looks like the page that is getting launched in the authentication pop-up might not be making the appropriate teamsjs calls to communicate the result back to the original tab page. What do you think? |
Yes, you're absolutely right, that's the source of my problem i guess. My redirection page as you can see don't call authentication.notifySuccess. Why ? Because it's a native page which is stored inside /_layouts/15/teamslogon.aspx and i can't include custom code in it. I don't know which let's say "native redirection address" I can set up to be able to call this authentication.notifySuccess on my pop-up. Does it mean that i need to create a proxy somewhere for example a sharepoint page in order to be able to call authentication.notifySuccess ? |
Yes, you'll need to have some page where you can write custom code that calls |
Thanks for your answer. Unfortunately as it's an SPFx project based on this article i don't really know what route/path i can provide to be able to do this. https://learn.microsoft.com/en-us/microsoftteams/platform/sbs-gs-spfx?tabs=vscode%2Cviscode I don't really have a path of my application as it's handle by Teams. If i take a look to my Teams Manifest app, my content url is like this. |
Thanks again for your help. I was able to get Teams Desktop to work, but now I can't get it to work in Teams Web mode. I have the following error after the execution of authentication.notifySuccess. I saw this post https://github.com/OfficeDev/microsoft-teams-library-js/issues/1779 related to this issue but it doesn't help me. You can find below the related code i used to called authentication.notifySuccess.
|
Hmm, I'm not sure what might be causing that. Is that "TEAMS AUTH Error" string somewhere in your code or is it coming from Teams? Is Enabling TeamsJS client logging may help track down what's going on after you call BTW you may only be doing this for testing but you shouldn't send tokens back via |
TEAMS AUTH comes from a catch of mine. Authentication.js comes from TeamsJS. Search for CancelledByUser. I will try to send you more information by enabling Teams JS Client logging. Thanks again. |
Thank you for sending the log screenshot, these were very helpful! We spent some time looking at these logs this morning and there are definitely some suspicious statements that we're trying to understand.
Thanks! |
Thanks again for your help. 1 & 2: Log in PJ 3: AuthenticatePopUpParameters 4: Chrome Version 131.0.6778.265 5: Version 2.32. |
I have a couple of questions @Ben-Oops! Logs very helpful. How are you opening the authentication window? From your logs it seems like the auth window is running at I believe that the supported way to open the auth window is by calling |
I have an SPFx project which i deploy to Teams by following this tutorial: https://learn.microsoft.com/en-us/microsoftteams/platform/sbs-gs-spfx In my project i call TeamsJS authenticate directly by clicking on a login button:
I'm redirected to my Azure B2C authority login page inside the pop-up. See in the above discussion. So far so good. I set my redirect page to a sharepoint page in order to be able to capture the accessToken. I set it to https://.sharepoint.com/sites/OAuthLogin. Inside this page, i have another SPFx webpart which run this code to get the access token and close the pop-up.
This code works on Teams Desktop not on Teams Web. If you have an example of a similar project, I'd love to get it, because I don't know how to solve my problem. |
We are going to reach out to the SPFx team to better understand their intended design for using teamsjs in these scenarios and report back. |
hey @Ben-Oops, thanks for bringing this to our attention. I work in the SharePoint Framework team and I hope I can give you some directions here. in short, what you are experiencing is.. expected: as you are an SPFx app, you are supposed to use the auth provided by the SPFx client APIs. The APIs have logic inside to understand the best auth for the host. As you are in Teams, we will use OBO or NAA (whatever your version of Teams in your tenant supports). The rational behind this choise is because teams.JS library is not present in all the places where you can host an SPFx application. In fact, it is not available on a SharePoint page in a browser. Here are a couple of pointers to help you here: Now: how this does fit with 3rd party IdPs? We currently support only Azure AD as IdP. That means that federation between identity providers is the only way for you to integrate with other IdPs. |
Hi @lucabandMSFT, Thanks for your help. If i understand correctly your comments it's not possible to achieve what i tried to do with SPFx because it only supports Entra ID (Azure AD). So my only way is to use Azure B2C federation with NAA. Right ? Reminder of my goal: Connect in SSO if possible from a Teams App deployed in multiple tenants to an Azure B2C through user Entra ID identity of each tenants. I'm a bit lost on how to achieve this goal. What i've done so far: In Azure B2C i declared an Entra Id (Single Tenant for now to test). This way i'm able to connect with my personal tenant account to Azure B2C using MSAL library for example. But the problem comes when i tried to implement this authentication in Teams App. As Teams App don't authorize loginPopUp or loginRedirect, i decided to use TeamsJS for authentication. I don't succeed to make it work properly as you can see above. I someone can give me some leads on how to achieve this goal, it will be greatly appreciate as i'm a bit stuck with SPFx. Thanks. |
I just want to check to ensure we are answering the right question. Is it required for your solution to use SPFx? Or are you also open to building a Teams app using just teamsjs without the use of SPFx? I didn't know if being part of SharePoint was a requirement for your app or if it was just a choice you made because you thought it was the best/easiest way to achieve your goal. |
It's not mandatory to use SPFx. I use it because it's already integrated with native M365 environment. I can also use Fluent to create an experience equivalent to the native M365 experience. |
@Ben-Oops , let's try with simple steps (first.. then we can add more complexity later). Assuming you can federate (AzureAD federation with the other IdP). Does using AADHttpClient withing the SPFx application works for you? |
Context:
In the context of a POC, I need to make calls to APIs from an SPFX App Teams hosted in my tenant using an Azure AD B2C to authenticate. I create an IDP (Identity Provider) to add my tenant in Azure B2C. To authenticate we use OAuth 2.0 Open ID Connect with Authorization Code flow.
Repro Step
Solution 1: Use @azure/msal-browser SDK for authentication
It works in Teams Web but not in Teams Desktop because it does not allow to open pop-up. See below.
I think there is no way to authorize po-up in Teams Desktop so i tried Solution 2 below.
Solution 2: Use @microsoft/teams-js SDK for authentication
This time the pop-up is now displayed correctly in Teams Desktop but I can't complete authentication in both Teams Desktop and Web. I do receive the authorisation code but it is not intercepted by the Teams connection SDK and is therefore not sent to the /token endpoint to retrieve the authentication token. I use the same redirect URL as the one used with @azure/msal-browser SDK
Redirect URL: https://[tenantname].sharepoint.com/_layouts/15/teamslogon.aspx
As you can see in Step 2 I'm stuck on this screen with no way of recovering my access token. If anyone can help me with this it would be greatly appreciated. Thank you very much.
The text was updated successfully, but these errors were encountered: