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

Use DI Container to initialize Option classes #110

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

SvenLauterbach
Copy link

Issue

When using the Azure functions microsoft graph extension version 1.0.0-beta6 the Azure function application reports an AccessDenied Exception:

image

This error was already reported in #108 and fixed in #77. However, even when using the dev branch, the exception is still thrown.

Cause

While #77 has done some fixing in the GraphOptions class, the cause for this exception comes from the order in which MicrosoftGraphExtensionConfigProvider and WebhookSubscriptionStore are created by the DI Container.

The exception is thrown by the constructor of the WebhookSubscriptionStore, which tries to create the BYOB_TokenMap directory:

public WebhookSubscriptionStore(IOptions<GraphOptions> options)
{
    _options = options.Value;
    _fileLock = new FileLock();
    _fileLock.PerformWriteIO(_options.TokenMapLocation, () => CreateRootDirectory());
}

This directory is configured by the BYOB_TokenMap app setting and applied to the GraphOptions class by calling GraphOptions.SetAppSettings(). The call to this method is done inside the constructor of the MicrosoftGraphExtensionConfigProvider class:

public MicrosoftGraphExtensionConfigProvider(IOptions<GraphOptions> options, 
            ILoggerFactory loggerFactory, 
            IGraphServiceClientProvider graphClientProvider, 
            INameResolver appSettings,
            IAsyncConverter<TokenBaseAttribute, string> tokenConverter,
            IGraphSubscriptionStore subscriptionStore)
        {
            _options = options.Value;
            _options.SetAppSettings(appSettings);
            _graphServiceClientManager = new GraphServiceClientManager(_options, tokenConverter, graphClientProvider);
            _subscriptionStore = subscriptionStore;
            _loggerFactory = loggerFactory;
        }

Fix

Applying the values from the app settings to the Options classes should be done outside those infrastructure classes, because their initialization order depends on the DI Container.

This PR moves the initialization of those Options classes to the DI container.

"WebhookSubscriptionStore" throws a "AccessDenied" exception, because it was trying to create the "BYOB_TokenMap" directory which still points to the default directory "D:/home/data/byob_graphmap".  The directory is configured in the "SetAppSettings()" method of the GraphOption class. This method is called in the "MicrosoftGraphExtensionConfigProvider" class constructor, which gets not called.
Configuring the option class should not be the responsibility of the services, so this was moved to the DI container.
@dnfclas
Copy link

dnfclas commented Jan 11, 2020

CLA assistant check
All CLA requirements met.

@elksson
Copy link

elksson commented Feb 5, 2020

@connermcmahon When can we get this pull request reviewed and a fix implemented to this issue?

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.

3 participants