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 Function: authManager.GetAzureADAppOnlyAuthenticatedContext erroring #1568

Closed
pmatthews05 opened this Issue Feb 6, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@pmatthews05

pmatthews05 commented Feb 6, 2018

Category

[X ] Bug
[ ] Enhancement

Environment

[ X] Office 365 / SharePoint Online
[ ] SharePoint 2016
[ ] SharePoint 2013

Expected or Desired Behavior

To be able to connect to SharePoint Online using an Office 365 App Only Authentication Token & certificate.

Observed Behavior

Deployed Azure Function that is using Office 365 App Only Authenticating into SharePoint. Was working OK since last Thursday 1st Feb. Since then when connecting to SharePoint, as it calls

OfficeDevPnP.Core.AuthenticationManager authManager = new 
OfficeDevPnP.Core.AuthenticationManager();
  using (var clientContext = authManager.GetAzureADAppOnlyAuthenticatedContext(tenantAdminUrl, clientId, tenant, certificatePath, certificatePassword))
            {
}

it throws error message "Object reference not set to an instance of an object"

If I run the code locally in Visual Studio, I do not encounter the error message. It only happens after deploying to Azure Functions.

The error message I get is the following
2018-02-06T10:38:58.672 Failed! Object reference not set to an instance of an object.
2018-02-06T10:38:58.703 StackTrace: at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.RunAsyncTask[T](Task`1 task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireToken(String resource, ClientAssertionCertificate clientCertificate)
at OfficeDevPnP.Core.AuthenticationManager.<>c__DisplayClass36_0.b__0(Object sender, WebRequestEventArgs args)
at Microsoft.SharePoint.Client.ClientRuntimeContext.OnExecutingWebRequest(WebRequestEventArgs args)
at Microsoft.SharePoint.Client.ClientContext.GetWebRequestExecutor()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at AppFunctionDemo.Function2.GetTenantSiteProperties(AuthenticationManager authManager, String tenantAdminUrl, String clientId, String tenant, String certificatePath, SecureString certificatePassword, TraceWriter log)
at AppFunctionDemo.Function2.Run(TimerInfo myTimer, ExecutionContext exCtx, TraceWriter log)

Steps to Reproduce

Create a Office 365 App only token. Give it Full permissions to SharePoint Online.
Create a App Function that connects to Sharepoint.
Deploy to Azure.

I have tried using different versions of PNP.

@pmatthews05

This comment has been minimized.

pmatthews05 commented Feb 6, 2018

Turns out there has been a change to the Azure Functions version. https://github.com/Azure/azure-functions-host/releases

By downgrading the Azure Function service to version 1.0.1138 it then appears to work again.

Go into your application settings, and where it says FUNCTIONS_EXTENSION_VERSION: ~1 change the version number to 1.0.11388

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment