/// <summary> /// Gets the new instance of non interactive handler. /// </summary> /// <param name="context">The context.</param> /// <param name="resource">The resource.</param> /// <param name="clientId">The client identifier.</param> /// <param name="userCredential">The user credential.</param> private static object GetNewInstanceOfNonInteractiveHandler(AuthenticationContext context, string resource, string clientId, UserCredential userCredential) { var uriString = EndpointTemplateUri.BindByName(new Uri(context.Authority), TokenEndpointBindings).OriginalString; var cache = context.TokenCache; var callAsync = false; // Retrieve and configure authenticator var authenticator = context.Authenticator(); authenticator.TokenUri(uriString); var typeOfObject = Type.GetType("Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenNonInteractiveHandler, Microsoft.IdentityModel.Clients.ActiveDirectory"); var ctorArguments = new object[] { authenticator, cache, resource, clientId, userCredential, callAsync }; var instanceOfHandler = Activator.CreateInstance(type: typeOfObject, args: ctorArguments); return(instanceOfHandler); }