Skip to content
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

Fix error when running on Azure Functions #2206

Merged
merged 3 commits into from
Aug 2, 2023

Conversation

BHoggs
Copy link
Contributor

@BHoggs BHoggs commented Aug 1, 2023

Fixes #2198

Changes proposed in this pull request

The fix for this turned out to be quite simple - just added a try block around the code that attempts to create the graph directory in the user's profile.

As far as I can see this has no flow-on effects. This folder is not used for anything else, other than checking if an existing config file exists. However this step does not fail with the change I have made.

Have tested in Azure Functions ~4, 7.2 runtime.

I also tested in Azure Automation, but this unfortunately does not fix the import error there.

@BHoggs BHoggs requested a review from a team as a code owner August 1, 2023 05:14
@peombwa
Copy link
Member

peombwa commented Aug 1, 2023

Thanks for your contribution!

Can you confirm if you are able to successfully login with the try catch block added - Connect-MgGraph ...? .mg directory is used by the auth library to sync "auth records" for token caching. I suspect the auth library will default to process context (in-memory cache) if the directory does not exist.

@BHoggs
Copy link
Contributor Author

BHoggs commented Aug 2, 2023

Welcome! I guess in 99% of scenarios this doesn't change anything. It's pretty rare where the home directory is read-only. As far as I could tell from my testing it appears to work fine on Azure functions in this scenario, and doesn't effect other scenarios.

I did only test the function app scenario using managed identity (Connect-MgGraph -Identity), do you think it also needs to be tested using client/secret auth?

Copy link
Member

@peombwa peombwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I've validated that everything works as expected in Azure Function using certificates, client secrets, and managed identities.

@peombwa peombwa merged commit 981a626 into microsoftgraph:dev Aug 2, 2023
2 checks passed
@BHoggs BHoggs deleted the az-functions-fix branch August 2, 2023 22:15
@peombwa peombwa mentioned this pull request Aug 10, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft.Graph.Authentication fails to load in Azure Functions with WEBSITE_RUN_AS_PACKAGE
2 participants