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

PlatformPlugin exception getting app-only token in ASP.NET Core #222

Closed
DianeD opened this issue Mar 14, 2017 · 1 comment
Closed

PlatformPlugin exception getting app-only token in ASP.NET Core #222

DianeD opened this issue Mar 14, 2017 · 1 comment

Comments

@DianeD
Copy link

DianeD commented Mar 14, 2017

I'm trying to create an ASP.NET Core app that uses MSAL for the client credentials flow.

I get the following exception when trying to get an access token:

NullReferenceException: Object reference not set to an instance of an object.
Microsoft.Identity.Client.Internal.PlatformPlugin.LoadPlatformSpecificAssembly()

Authentication is modeled on active-directory-dotnet-webapp-openidconnect-aspnetcore-v2
Authorization is modeled on active-directory-dotnet-daemon-v2

My app is registered with the Mail.Read Application permission. Here's the code that throws the exception:

string authority = $"https://login.microsoftonline.com/{ tenantId }/v2.0";
ConfidentialClientApplication client = new ConfidentialClientApplication(
    authority,
    appId,
    redirectUri,
    new ClientCredential(appSecret),
    null); //new TokenCache());

AuthenticationResult authResult = await client.AcquireTokenForClient(
    new string[] { "https://graph.microsoft.com/.default" }, null); //"Mail.Read"
return authResult.Token;

I've tried variations in the project.json file. Right now it's:

{
  "userSecretsId": ...,

  "dependencies": {
    "BundlerMinifier.Core": "2.2.306",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
    "Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.1.0",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.Session": "1.1.0",
    "Microsoft.AspNetCore.SignalR.Server": "0.2.0-*",
    "Microsoft.AspNetCore.WebSockets": "0.2.0-*",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Caching.Memory": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
    "Microsoft.Graph": "1.2.0",
    "NuGet.CommandLine": "3.4.3",
    "Microsoft.AspNetCore.Http.Abstractions": "1.1.0",
    "Microsoft.Identity.Client": "1.0.304142221-alpha",
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    }
  },

  "tools": {
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimes": {
    "win10-x64": {}
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
@kpanwar
Copy link

kpanwar commented Mar 15, 2017

this problem will not occur with the next release as we will move to a single binary.

@kpanwar kpanwar closed this as completed Mar 15, 2017
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

No branches or pull requests

2 participants