sp-dev-docs
sp-dev-docs copied to clipboard
SPFX 1.17 PopupFlow
Hi all,
Cannot make this popup flow work in anyway, here is the code I'm using: const tokenProvider = await this.context.aadTokenProviderFactory.getTokenProvider();
const spEventObserver:ISPEventObserver = { componentId: this.componentId, instanceId:this.instanceId, isDisposed:false, dispose:null};
tokenProvider.onBeforeRedirectEvent.add(spEventObserver, (eventArgs: IBeforeRedirectEventArgs) =>{
eventArgs.cancel();
})
tokenProvider.popupEvent.add(spEventObserver, (eventArgs: IPopupEventArgs) =>
{ eventArgs.requestPopup(); eventArgs.showPopup(); })
return await tokenProvider.getToken(reachResourceUrl);
What am I doing wrong?
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Bumping, I've followed instructions but its still redirecting.
Debugging AADHttpClient I can see popupEvent is registered correctly, but it's never called, onBeforeRedirect event is called instead.
Running Get-SPOTenant shows that IsEnableAppAuthPopupEnabled is set to true.
Also this line is confusing:
const configurableTokenProvider: AadTokenProvider = _AadTokenProviders.configurable as AadTokenProvider;
_AadTokenProviders variable is from @microsoft/sp-http module and I'm not sure how to access it, but using context.aadHttpClientFactory seems to be setting up _AadTokenProviders.configurable correctly.
e.g. https://sharepoint.stackexchange.com/questions/308478/spfx-login-popup-flow?newreg=d18b7cdd876b42f6a7db5985c51910a3
@andrewconnell maybe worth updating docs with different sample?
@danielcostalvt @SharePickle - we identified an issue and working on the fix. If no unpredicted things happen it should be rolled out WW in about 2-3 weeks.
Any update on this @AJIXuMuK ?
@glyn-clough-wm-reply - sorry for the silence. The fix should be rolled out globally.
Could you please check if you're still experiencing the issue?
Many thanks - we'll try and test this out over the next few days and provide an update.
Can I just check - is this the Microsoft recommended approach to access AD secured API's, when there is ITP blocking the usual authentication methods? (As that's the challenge we're trying to solve)
@glyn-clough-wm-reply - yes, we recommend this approach for SPFx solutions.
@AJIXuMuK : will try it out and provide some feedback. My question though, if we have multiple web parts consuming different APIs, we will have a never ending appearance of popups, correct?
Can we get some insight if there is any plan on removing the cookie dependency of authentication alltogether in the future?
@glyn-clough-wm-reply - sorry for the silence. The fix should be rolled out globally.
Could you please check if you're still experiencing the issue?
Hi @AJIXuMuK - we've had a look (with @SharePickle ) and we're unfortunately it still doesn't appear to be working, and is returning an internal error. Is the documentation still correct, or do you have a working sample we could follow?
The popup shows up, but nothing happens (error says cannot read measage of undefined in console). Also if you try get token again it says is Token request previously failed.
@SharePickle could you please share the console errors and also correlation id from requests (request-id header value) for failing requests?
Here's my setup:
// configure popup
onInit() {
return this.context.aadTokenProviderFactory.getTokenProvider()
.then(configurableTokenProvider => {
configurableTokenProvider.popupEvent.add(this, this.handlePopup);
this._tokenProvider = configurableTokenProvider;
})
.catch(e => console.error(e));
}
handlePopup = (eventArgs: PopupEventArgs) => {
eventArgs.cancel(); // REQUIRED: to cancel the default popup that is called to open
eventArgs.showPopup(); // initiate the popup flow
}
getToken = async () => {
const token = await this._tokenProvider.getToken('https://graph.microsoft.com')
}
The web part is just a simple button which calls getToken method.
When I click the first time - popup shows up, but nothing happens.
When I was debugging cannot read measage of undefined I found it caused by this method (argument e is undefined):
When I click the button second time nothing happens at all, but if I debug again the error message is caught internally and it says Token request previously failed..
Error: Token request previously failed
at new t (chunk.aadTokenProvider_en-us_fee8ad587b68c8265bea.js:1:1754)
at e._getTokenInternal (chunk.aadTokenProvider_en-us_fee8ad587b68c8265bea.js:1:3807)
at e.getToken (chunk.aadTokenProvider_en-us_fee8ad587b68c8265bea.js:1:2612)
at sp-pages-assembly_en-us_c362cb7e1934defdf3d1046262075d28.js:78:169616
If I refresh the page and click button again - token loads successfully.
This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within the next 7 days of this comment. Please see our wiki for more information: Issue List Labels: Needs Author Feedback & Issue List: No response from the original issue author
Hi @AJIXuMuK - any update on this? Do you need anything else from @SharePickle ?
hi @AJIXuMuK / @VesaJuvonen can we get an answer on: My question though, if we have multiple web parts consuming different APIs, we will have a never ending appearance of popups, correct?
Can we get some insight if there is any plan on removing the cookie dependency of authentication alltogether in the future?
@AJIXuMuK hey sorry to ping you so often, but is there anything you guys found out? Now I'm getting other error:
Uncaught (in promise) ClientAuthError: User cancelled the flow.
at t [as constructor] (chunk.vendors~msalImplicit~msalImplicitLegacy_none_98fce48cd7ca5bbe0433.js:1:8320)
at new t (chunk.vendors~msalImplicit~msalImplicitLegacy_none_98fce48cd7ca5bbe0433.js:1:8879)
at t.createUserCancelledError (chunk.vendors~msalImplicit~msalImplicitLegacy_none_98fce48cd7ca5bbe0433.js:1:10209)
at chunk.vendors~msalImplicit~msalImplicitLegacy_none_98fce48cd7ca5bbe0433.js:1:41370
Is there any update on this? I also need to be able to handle AAD authentication when silentsso gets blocked by the browser
Thank you for taking the time to file an issue. We periodically archive older or inactive issues as part of our issue management process, which automatically closes them once they are archived.
If you’d like to understand more about why and how we handle archived (closed) issues, please see Our approach to closed issues.
We appreciate your contribution and if this is still an active issue with the latest SPFx versions, please do resubmit the details. We needed to perform a cleanup, so that we can start with a clean table with a new process. We apologize for the inconvenience this might cause.