-
Notifications
You must be signed in to change notification settings - Fork 1k
Request Power Automate flow with OAuth from SPFx: AADSTS65002: Consent between first party application and first party resource must be configured via preauthorization #10286
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
Comments
Hello @vlad-nvs |
@vlad-nvs, |
Thanks for the article. I checked once again, and the approach described in the article is not working for the HTTP triggers where the option 'Who can trigger the flow' is set to 'Any user in my tenant' or 'Specific user in my tenant'. The article you mention is an old one. When you configure the flow, you can now choose Who can trigger the flow. The URL is changed when user select options and Save the flow (check my screenshot). If I use the next code: I'll get the next error: 'The OAuth authorization scheme is required. Please add authentication scheme and try again.' And this is predictable, because a POST call should contain Authorization header for this case, but it's not possible to get a Bearer token to pass it to the Authorization header. I tried aadTokenProviderFactory.getTokenProvider and even aadClientFactory.getClient. For example:
OR
But in all cases, I got the error: As well, I trusted API permissions: And it's not working either. I also found a similar question on Microsoft, but without an answer: For me, it looks like a bug, and it's not possible to call Power Automate flow from SPFx if it has configured options 'Who can trigger the flow' set to Any user in my tenant' or 'Specific user in my tenant'. P.S. Option 'Anyone' for 'Who can trigger the flow' will work without any issues but it's not my case. Hope it's clear. Any ideas? |
@vlad-nvs, We’ve seen that setting the flow’s “Who can trigger the flow” option to “Anyone” allows anonymous access and typically resolves the OAuth requirement. However, if it’s still not working even in that mode, we’d be happy to help further investigate the flow configuration or how the request is being made. That said, triggering flows with tenant-level authentication from SPFx directly (using aadTokenProviderFactory or aadHttpClientFactory) is currently not fully supported, due to AADSTS65002 errors caused by required preauthorization between first-party apps and the Power Automate service. We understand this feels like a limitation, and we agree it would be beneficial to support this scenario. If this functionality is important for your use case, we recommend submitting a feature request or upvoting an existing one via the Microsoft Feedback Portal: |
Yes, option 'Anyone' for 'Who can trigger the flow' allows anonymous access and request from SPFx to the flow URL is working as expected. However, this limitation for the two other options is confusing and I think this issue will raise again and again in future because of the security reasons. But anyway, thank you for the clarification. |
Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
💥 SharePoint Framework
Developer environment
None
What browser(s) / client(s) have you tested
Additional environment details
Describe the bug / error
We have Power Automate flow with HTTP trigger and configured option 'Who can trigger the flow' with value 'Any user in my tenant'.
If we try to call flow via URL we need to pass Authorization header with valid token.
We used aadTokenProviderFactory.getTokenProvider and provider.getToken("https://service.flow.microsoft.com/", true) but it throws next error:
AADSTS65002: Consent between first party application and first party resource must be configured via preauthorization
Steps to reproduce
context.aadTokenProviderFactory.getTokenProvider.then((provider)=>{.....})
context.aadTokenProviderFactory.getTokenProvider.then((provider)=>{provider.getToken("https://service.flow.microsoft.com/", true).then((token)=>{....})})
Expected behavior
We need a way to get token to call Power Automate from SPFx. I think using aadTokenProviderFactory is a correct way but it's not working.
How to get token to call Power Automate flow with OAuth from SPFx?
The text was updated successfully, but these errors were encountered: